Files
stacks-blockchain-api/client/index.html

173 lines
9.1 KiB
HTML

<!doctype html>
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>@stacks/blockchain-api-client</title>
<meta name="description" content="Documentation for @stacks/blockchain-api-client">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
<script async src="assets/js/search.js" id="search-script"></script>
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="assets/js/search.json" data-base=".">
<div class="field">
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
<input id="tsd-search-field" type="text" />
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">@stacks/blockchain-api-client</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
<div class="tsd-filter-group">
<div class="tsd-select" id="tsd-filter-visibility">
<span class="tsd-select-label">All</span>
<ul class="tsd-select-list">
<li data-value="public">Public</li>
<li data-value="protected">Public/Protected</li>
<li data-value="private" class="selected">All</li>
</ul>
</div>
<input type="checkbox" id="tsd-filter-inherited" checked />
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
<input type="checkbox" id="tsd-filter-externals" checked />
<label class="tsd-widget" for="tsd-filter-externals">Externals</label>
</div>
</div>
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
</div>
</div>
</div>
</div>
<div class="tsd-page-title">
<div class="container">
<h1>@stacks/blockchain-api-client</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<div class="tsd-panel tsd-typography">
<a href="#stacksblockchain-api-client" id="stacksblockchain-api-client" style="color: inherit; text-decoration: none;">
<h1>@stacks/blockchain-api-client</h1>
</a>
<p><a href="https://www.npmjs.org/package/@stacks/blockchain-api-client"><img src="https://img.shields.io/npm/v/@stacks/blockchain-api-client.svg?style=flat-square" alt="NPM Package"></a>
<a href="https://github.com/blockstack/stacks-blockchain-api/actions"><img src="https://github.com/blockstack/stacks-blockchain-api/workflows/stacks-blockchain-api/badge.svg" alt="Build Status"></a></p>
<p>A JS Client for the Stacks Blockchain API</p>
<a href="#features" id="features" style="color: inherit; text-decoration: none;">
<h2>Features</h2>
</a>
<p>This package provides the ability to:</p>
<ul>
<li>Execute REST API requests against the Stacks Blockchain API</li>
<li>Subscribe to WebSockets for real-time Stacks updates (for addresses or transactions)</li>
<li>Full type safety for WebSocket and API requests and responses</li>
</ul>
<a href="#installation" id="installation" style="color: inherit; text-decoration: none;">
<h2>Installation</h2>
</a>
<p>You can install this package using NPM:</p>
<pre><code class="language-shell"><span style="color: #000000">npm install --save-dev @stacks/blockchain-api-client</span>
</code></pre>
<a href="#usage" id="usage" style="color: inherit; text-decoration: none;">
<h2>Usage</h2>
</a>
<p>Here is an example code that connects with the WebSocket server and subscribes to updates for a specific Stacks address:</p>
<pre><code class="language-js"><span style="color: #AF00DB">import</span><span style="color: #000000"> { </span><span style="color: #001080">connectWebSocketClient</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;@stacks/blockchain-api-client&#039;</span><span style="color: #000000">;</span>
<span style="color: #008000">// for mainnet, replace with ws://stacks-node-api.testnet.stacks.co/</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">client</span><span style="color: #000000"> = </span><span style="color: #AF00DB">await</span><span style="color: #000000"> </span><span style="color: #795E26">connectWebSocketClient</span><span style="color: #000000">(</span><span style="color: #A31515">&#039;wss://stacks-node-api.mainnet.stacks.co/&#039;</span><span style="color: #000000">);</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">sub</span><span style="color: #000000"> = </span><span style="color: #AF00DB">await</span><span style="color: #000000"> </span><span style="color: #001080">client</span><span style="color: #000000">.</span><span style="color: #795E26">subscribeAddressTransactions</span><span style="color: #000000">(</span><span style="color: #A31515">&#039;ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA&#039;</span><span style="color: #000000">, </span><span style="color: #001080">event</span><span style="color: #000000"> </span><span style="color: #0000FF">=&gt;</span>
<span style="color: #000000"> </span><span style="color: #001080">console</span><span style="color: #000000">.</span><span style="color: #795E26">log</span><span style="color: #000000">(</span><span style="color: #001080">event</span><span style="color: #000000">);</span>
<span style="color: #000000"> </span><span style="color: #008000">/*</span>
<span style="color: #008000"> {</span>
<span style="color: #008000"> address: &#039;ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA&#039;,</span>
<span style="color: #008000"> tx_id: &#039;0x8912000000000000000000000000000000000000000000000000000000000000&#039;,</span>
<span style="color: #008000"> tx_status: &#039;success&#039;,</span>
<span style="color: #008000"> tx_type: &#039;token_transfer&#039;,</span>
<span style="color: #008000"> }</span>
<span style="color: #008000"> */</span>
<span style="color: #000000">);</span>
<span style="color: #AF00DB">await</span><span style="color: #000000"> </span><span style="color: #001080">sub</span><span style="color: #000000">.</span><span style="color: #795E26">unsubscribe</span><span style="color: #000000">();</span>
</code></pre>
<a href="#documentation" id="documentation" style="color: inherit; text-decoration: none;">
<h2>Documentation</h2>
</a>
<p>You can find full references <a href="https://blockstack.github.io/stacks-blockchain-api/client/index.html">here</a>.</p>
<a href="#known-issues" id="known-issues" style="color: inherit; text-decoration: none;">
<h2>Known Issues</h2>
</a>
<ul>
<li>The TypeScript definitions for several objects involving type unions, including transactions, are incorrectly specified as only <code>object</code>.</li>
</ul>
</div>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<nav class="tsd-navigation primary">
<ul>
<li class=" ">
<a href="modules.html">Modules</a>
</li>
<li class=" tsd-kind-module">
<a href="modules/generated.html">generated</a>
</li>
<li class=" tsd-kind-module">
<a href="modules/generated_runtime.html">generated/runtime</a>
</li>
<li class=" tsd-kind-module">
<a href="modules/socket_io.html">socket-<wbr>io</a>
</li>
<li class=" tsd-kind-module">
<a href="modules/ws.html">ws</a>
</li>
</ul>
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
</ul>
</nav>
</div>
</div>
</div>
<footer class="with-border-bottom">
<div class="container">
<h2>Legend</h2>
<div class="tsd-legend-group">
<ul class="tsd-legend">
<li class="tsd-kind-variable"><span class="tsd-kind-icon">Variable</span></li>
<li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li>
<li class="tsd-kind-type-alias"><span class="tsd-kind-icon">Type alias</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-interface"><span class="tsd-kind-icon">Interface</span></li>
<li class="tsd-kind-interface tsd-has-type-parameter"><span class="tsd-kind-icon">Interface with type parameter</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li>
<li class="tsd-kind-class tsd-has-type-parameter"><span class="tsd-kind-icon">Class with type parameter</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-enum"><span class="tsd-kind-icon">Enumeration</span></li>
</ul>
</div>
</div>
</footer>
<div class="container tsd-generator">
<p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p>
</div>
<div class="overlay"></div>
<script src="assets/js/main.js"></script>
</body>
</html>