subspace-site/api.html

34 lines
19 KiB
HTML

<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>API | SUBSPACE</title>
<meta name="description" content="Reactive ÐApp Development">
<link rel="apple-touch-icon" sizes="180x180" href="/assets/img/logo-small.png">
<link rel="icon" type="image/png" sizes="32x32" href="/assets/img/logo-small.png">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/img/logo-small.png">
<link rel="shortcut icon" href="/assets/img/logo-small.png">
<meta name="theme-color" content="#ffffff">
<link rel="preload" href="/assets/css/0.styles.ff6dfed4.css" as="style"><link rel="preload" href="/assets/js/app.dee337e1.js" as="script"><link rel="preload" href="/assets/js/2.c401969f.js" as="script"><link rel="preload" href="/assets/js/7.a2409073.js" as="script"><link rel="prefetch" href="/assets/js/10.df07d2be.js"><link rel="prefetch" href="/assets/js/11.b5216252.js"><link rel="prefetch" href="/assets/js/12.85ce989d.js"><link rel="prefetch" href="/assets/js/13.73efb4d7.js"><link rel="prefetch" href="/assets/js/14.513e9262.js"><link rel="prefetch" href="/assets/js/15.d48a7184.js"><link rel="prefetch" href="/assets/js/16.1b9eabd3.js"><link rel="prefetch" href="/assets/js/17.910b0e9e.js"><link rel="prefetch" href="/assets/js/18.0936c664.js"><link rel="prefetch" href="/assets/js/19.1ae67b9a.js"><link rel="prefetch" href="/assets/js/3.fc5c8748.js"><link rel="prefetch" href="/assets/js/4.e5468477.js"><link rel="prefetch" href="/assets/js/5.26dd2b41.js"><link rel="prefetch" href="/assets/js/6.8a01ae42.js"><link rel="prefetch" href="/assets/js/8.901206cf.js"><link rel="prefetch" href="/assets/js/9.19ef9a17.js">
<link rel="stylesheet" href="/assets/css/0.styles.ff6dfed4.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/assets/img/logo-small.png" alt="SUBSPACE" class="logo"> <span class="site-name can-hide">SUBSPACE</span></a> <div class="links"><!----> <nav class="nav-links can-hide"><div class="nav-item"><a href="/getting-started/" class="nav-link">Getting Started</a></div><div class="nav-item"><a href="/integrations-overview.html" class="nav-link">Integrations</a></div><div class="nav-item"><a href="/api.html" class="nav-link router-link-exact-active router-link-active">API</a></div><div class="nav-item"><a href="https://github.com/embarklabs/subspace" target="_blank" rel="noopener noreferrer" class="nav-link external">
Github
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/getting-started/" class="nav-link">Getting Started</a></div><div class="nav-item"><a href="/integrations-overview.html" class="nav-link">Integrations</a></div><div class="nav-item"><a href="/api.html" class="nav-link router-link-exact-active router-link-active">API</a></div><div class="nav-item"><a href="https://github.com/embarklabs/subspace" target="_blank" rel="noopener noreferrer" class="nav-link external">
Github
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav> <ul class="sidebar-links"><li><a href="/" class="sidebar-link">Home</a></li><li><a href="/how-it-works.html" class="sidebar-link">How it works?</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/getting-started.html" class="sidebar-link">Getting Started</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/getting-started.html#installation" class="sidebar-link">Installation</a></li><li class="sidebar-sub-header"><a href="/getting-started.html#importing-the-library" class="sidebar-link">Importing the library</a></li><li class="sidebar-sub-header"><a href="/getting-started.html#connecting-to-a-web3-provider" class="sidebar-link">Connecting to a web3 provider</a></li><li class="sidebar-sub-header"><a href="/getting-started.html#reacting-to-data" class="sidebar-link">Reacting to data</a></li><li class="sidebar-sub-header"><a href="/getting-started.html#tracking-state" class="sidebar-link">Tracking state</a></li><li class="sidebar-sub-header"><a href="/getting-started.html#tracking-events" class="sidebar-link">Tracking events</a></li><li class="sidebar-sub-header"><a href="/getting-started.html#tracking-balances" class="sidebar-link">Tracking balances</a></li><li class="sidebar-sub-header"><a href="/getting-started.html#subscriptions" class="sidebar-link">Subscriptions</a></li><li class="sidebar-sub-header"><a href="/getting-started.html#cleanup" class="sidebar-link">Cleanup</a></li></ul></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>Integrations</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/integrations-overview.html" class="sidebar-link">Overview</a></li><li><a href="/react.html" class="sidebar-link">React</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue.html" class="sidebar-link">Vue</a><ul class="sidebar-sub-headers"></ul></li><li><section class="sidebar-group is-sub-group depth-1"><p class="sidebar-heading"><span>Redux</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/redux.html" class="sidebar-link">redux</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/redux-observable.html" class="sidebar-link">redux-observable</a></li></ul></section></li><li><a href="/reactive-graphql.html" class="sidebar-link">reactive-graphql</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/apollo-client.html" class="sidebar-link">apollo-client</a><ul class="sidebar-sub-headers"></ul></li></ul></section></li><li><a href="/tutorial.html" class="sidebar-link">Tutorial</a></li><li><a href="/api.html" class="active sidebar-link">API</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/api.html#general" class="sidebar-link">General</a></li><li class="sidebar-sub-header"><a href="/api.html#contract-methods" class="sidebar-link">Contract methods</a></li><li class="sidebar-sub-header"><a href="/api.html#low-level-api-for-data-tracking" class="sidebar-link">Low level API for data tracking</a></li></ul></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="api"><a href="#api" class="header-anchor">#</a> API</h1> <h2 id="general"><a href="#general" class="header-anchor">#</a> General</h2> <h3 id="new-subspace-web3provider-options"><a href="#new-subspace-web3provider-options" class="header-anchor">#</a> <code>new Subspace(web3Provider [, options])</code></h3> <p>Constructor.</p> <p><strong>Parameters</strong></p> <ol><li><code>web3Provider</code> - <code>Object</code>: a valid web3 websockets provider.</li> <li><code>options</code> - <code>Object</code> (optional): Options used to initialize Subspace
<ul><li><code>dbFilename</code> - <code>String</code> (optional): Name of the database where the information will be stored (default <code>'subspace.db'</code>)</li> <li><code>callInterval</code> - <code>Number</code> (optional): - Interval of time in milliseconds to query a contract/address to determine changes in state or balance (default: <code>undefined</code>. Obtains data every block).</li></ul></li></ol> <h3 id="init"><a href="#init" class="header-anchor">#</a> <code>init()</code></h3> <p>Initializes <strong>Subspace</strong></p> <p><strong>Returns</strong> <code>Promise</code> that once it's resolved, will mean that <strong>Subspace</strong> is available to use</p> <h3 id="close"><a href="#close" class="header-anchor">#</a> <code>close()</code></h3> <p>Dispose and perform the cleanup necessary to remove the internal subscriptions and interval timers created by <strong>Subspace</strong> during its normal execution.</p> <h3 id="contract-instance-abi-address"><a href="#contract-instance-abi-address" class="header-anchor">#</a> <code>contract(instance|{abi,address})</code></h3> <p>Adds a <code>track</code> method to the web3 contract objects. You can obtain this functionality by passing a <code>web3.eth.Contract</code> instance, or the <code>abi</code> and <code>address</code> of your contract</p> <p><strong>Returns</strong> <code>web3.eth.Contract</code> object enhanced with <code>.track()</code> functions for methods and events.</p> <h2 id="contract-methods"><a href="#contract-methods" class="header-anchor">#</a> Contract methods</h2> <h3 id="mycontract-events-myevent-track-options"><a href="#mycontract-events-myevent-track-options" class="header-anchor">#</a> <code>myContract.events.MyEvent.track([options])</code></h3> <p>Track a contract event.</p> <p><strong>Parameters</strong></p> <ol><li><code>options</code> - <code>Object</code> (optional): web3 filter options object to limit the number of events based on a block number range, or indexed filters
<ul><li><code>filter</code> - <code>Object</code> (optional): Lets you filter events by indexed parameters, e.g. <code>{filter: {myNumber: [12,13]}}</code> means all events where <code>&quot;myNumber&quot;</code> is <code>12</code> or <code>13</code>.</li> <li><code>fromBlock</code> - <code>Number</code> (optional): The block number from which to get events on.</li> <li><code>toBlock</code> - <code>Number</code> (optional): The block number to get events up to (Defaults to <code>&quot;latest&quot;</code>)</li> <li><code>topics</code> - <code>Array</code> (optional): This allows you to manually set the topics for the event filter. If given the filter property and event signature, (<code>topic[0]</code>) will not be set automatically.</li></ul></li></ol> <p><strong>Returns</strong> <code>RxJS Observable</code> which will stream the event <code>returnValues</code>.</p> <h3 id="mycontract-methods-mymethod-param1-track-calloptions"><a href="#mycontract-methods-mymethod-param1-track-calloptions" class="header-anchor">#</a> <code>myContract.methods.myMethod([param1[, ...]]).track([callOptions])</code></h3> <p>Track a constant function / contract state variable on each block mined, or depending on the <code>callInterval</code> option used during <strong>Subspace</strong> initialization.</p> <p><strong>Parameters</strong></p> <ol><li><code>callOptions</code> - <code>Object</code> (optional): The options used for calling.
<ul><li><code>from</code> - <code>String</code> (optional): The address the call “transaction” should be made from.</li> <li><code>gasPrice</code> - <code>String</code> (optional): The gas price in wei to use for this call “transaction”.</li> <li><code>gas</code> - <code>Number</code> (optional): The maximum gas provided for this call “transaction” (gas limit).</li></ul></li></ol> <p><strong>Returns</strong> <code>RxJS Observable</code> which will stream the function / variable values. Data type will depend on the contract function invoked.</p> <h3 id="mycontract-trackbalance-address-tokenaddress"><a href="#mycontract-trackbalance-address-tokenaddress" class="header-anchor">#</a> <code>myContract.trackBalance(address [, tokenAddress])</code></h3> <p>Track a contract's balance changes for an address on each block mined, or depending on the <code>callInterval</code> option used during <strong>Subspace</strong> initialization.</p> <p><strong>Parameters</strong></p> <ol><li><code>address</code> - <code>String</code>: The address to get the balance of.</li> <li><code>tokenAddress</code> - <code>String</code> (optional): If you want to track the balance for an ERC20 contract, here you can specify the token address. Otherwise, Only ETH balances will be returned.</li></ol> <p><strong>Returns</strong> <code>RxJS Observable</code> which will stream a string containing the address balance.</p> <h2 id="low-level-api-for-data-tracking"><a href="#low-level-api-for-data-tracking" class="header-anchor">#</a> Low level API for data tracking</h2> <p>These are used in case you don't want to decorate your web3 contract objects, or if you want to track the balance for an specific address.</p> <h3 id="trackevent-contractobject-eventname-options"><a href="#trackevent-contractobject-eventname-options" class="header-anchor">#</a> <code>trackEvent(contractObject, eventName [, options])</code></h3> <p>Track a contract event.</p> <p><strong>Parameters</strong></p> <ol><li><code>contractObject</code> - <code>web3.eth.Contract</code>: An already initialized contract object pointing to an address and containing a valid ABI.</li> <li><code>eventName</code> - <code>String</code>: The name of the event to subscribe.</li> <li><code>options</code> - <code>Object</code> (optional): web3 filter options object to limit the number of events based on a block number range, or indexed filters
<ul><li><code>filter</code> - <code>Object</code> (optional): Lets you filter events by indexed parameters, e.g. <code>{filter: {myNumber: [12,13]}}</code> means all events where <code>&quot;myNumber&quot;</code> is <code>12</code> or <code>13</code>.</li> <li><code>fromBlock</code> - <code>Number</code> (optional): The block number from which to get events on.</li> <li><code>toBlock</code> - <code>Number</code> (optional): The block number to get events up to (Defaults to <code>&quot;latest&quot;</code>)</li> <li><code>topics</code> - <code>Array</code> (optional): This allows you to manually set the topics for the event filter. If given the filter property and event signature, (<code>topic[0]</code>) will not be set automatically.</li></ul></li></ol> <p><strong>Returns</strong> <code>RxJS Observable</code> which will stream the event <code>returnValues</code>.</p> <h3 id="trackproperty-contractobject-functionname-functionargs-calloptions"><a href="#trackproperty-contractobject-functionname-functionargs-calloptions" class="header-anchor">#</a> <code>trackProperty(contractObject, functionName [, functionArgs] [, callOptions])</code></h3> <p>Track a constant function / contract state variable on each block mined, or depending on the <code>callInterval</code> option used during <strong>Subspace</strong> initialization.</p> <p><strong>Parameters</strong></p> <ol><li><code>contractObject</code> - <code>web3.eth.Contract</code>: An already initialized contract object pointing to an address and containing a valid ABI.</li> <li><code>functionName</code> - <code>String</code>: Name of the function or variable whose values will be tracked.</li> <li><code>functionArgs</code> - <code>Array</code> (optional): Array of arguments that the tracked function receives</li> <li><code>callOptions</code> - <code>Object</code> (optional): The options used for calling.
<ul><li><code>from</code> - <code>String</code> (optional): The address the call “transaction” should be made from.</li> <li><code>gasPrice</code> - <code>String</code> (optional): The gas price in wei to use for this call “transaction”.</li> <li><code>gas</code> - <code>Number</code> (optional): The maximum gas provided for this call “transaction” (gas limit).</li></ul></li></ol> <p><strong>Returns</strong> <code>RxJS Observable</code> which will stream the function / variable values. Data type will depend on the contract function invoked.</p> <h3 id="trackbalance-address-tokenaddress"><a href="#trackbalance-address-tokenaddress" class="header-anchor">#</a> <code>trackBalance(address [, tokenAddress])</code></h3> <p>Track balance changes for an address on each block mined, or depending on the <code>callInterval</code> option used during <strong>Subspace</strong> initialization.</p> <p><strong>Parameters</strong></p> <ol><li><code>address</code> - <code>String</code>: The address to get the balance of.</li> <li><code>tokenAddress</code> - <code>String</code> (optional): If you want to track the balance for an ERC20 contract, here you can specify the token address. Otherwise, Only ETH balances will be returned.</li></ol> <p><strong>Returns</strong> <code>RxJS Observable</code> which will stream a string containing the address balance.</p> <h3 id="tracklogs-options-abi"><a href="#tracklogs-options-abi" class="header-anchor">#</a> <code>trackLogs(options [, abi])</code></h3> <p>Tracks incoming logs, filtered by the given options.</p> <p><strong>Parameters</strong></p> <ol><li><code>options</code> - <code>Object</code> (optional): web3 filter options object to limit the number of logs
<ul><li><code>address</code> - <code>String|Array</code> (optional): An address or a list of addresses to only get logs from particular account(s).</li> <li><code>fromBlock</code> - <code>Number</code> (optional): The block number from which to get events on.</li> <li><code>topics</code> - <code>Array</code> (optional): An array of values which must each appear in the log entries. The order is important, if you want to leave topics out use null, e.g. [null, '0x00...']. You can also pass another array for each topic with options for that topic e.g. [null, ['option1', 'option2']].</li></ul></li> <li><code>abi</code> - <code>Array</code> (optional): Array containing the ABI for the inputs of the logs received. It will automatically decode the logs using this ABI instead of returning the hexadecimal data.</li></ol> <p><strong>Returns</strong> <code>RxJS Observable</code> which will stream the logs. If the inputs ABI is included in the call, the logs will be automatically decoded.</p></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
<a href="/tutorial.html" class="prev">Tutorial</a></span> <!----></p></div> </main></div><div class="global-ui"></div></div>
<script src="/assets/js/app.dee337e1.js" defer></script><script src="/assets/js/2.c401969f.js" defer></script><script src="/assets/js/7.a2409073.js" defer></script>
</body>
</html>