Module: chainweb

chainweb.js Exports functions to support interacting with a chainweb block chain Author: Lar Kuhtz
Source:

Namespaces

block
cut
event
header
transaction

Methods

(async, static) branch(chainId, upperopt, loweropt, minHeightopt, maxHeightopt, nopt, networkopt, hostopt, retryOptionsopt) → {Array.<Object>}

Return block headers from chain in decending order
Parameters:
Name Type Attributes Default Description
chainId number | string a chain id that is valid for the network
upper Array.<string> <optional>
only antecessors of these block hashes are returned. Note that if this is null, the result is empty.
lower Array.<string> <optional>
no antecessors of these block hashes are returned.
minHeight number <optional>
if given, minimum height of returned headers
maxHeight number <optional>
if given, maximum height of returned headers
n number <optional>
if given, limits the number of results. This is an upper limit. The actual number of returned items can be lower.
network string <optional>
"mainnet01" chainweb network
host string <optional>
"https://api.chainweb.com" chainweb api host
retryOptions Object <optional>
retry options object as accepted by the retry package
Properties
Name Type Attributes Default Description
retry404 boolean <optional>
false whether to retry on 404 results
Source:
Returns:
Array of block header objects TODO: support paging
Type
Array.<Object>

(async, static) payloads(chainId, hashes, networkopt, hostopt, retryOptionsopt) → {Array.<Object>}

Payloads with outputs
Parameters:
Name Type Attributes Default Description
chainId number | string a chain id that is valid for the network
hashes Array.<string> array of block payload hashes
network string <optional>
"mainnet01" chainweb network
host string <optional>
"https://api.chainweb.com" chainweb api host
retryOptions Object <optional>
retry options object as accepted by the retry package
Properties
Name Type Attributes Default Description
retry404 boolean <optional>
false whether to retry on 404 results
Source:
Returns:
Array of block header objects TODO: support paging
Type
Array.<Object>

(inner) base64json(txt)

Decode base64url encoded JSON text
Parameters:
Name Type Description
txt string base64url encoded json text
Source:

(inner) baseUrl(networkopt, hostopt, pathSuffix) → {Object}

Create URL for the Chainweb API
Parameters:
Name Type Attributes Default Description
network string <optional>
"mainnet01" chainweb network
host string <optional>
"https://api.chainweb.com" chainweb api host
pathSuffix string suffix of the path that is appended to the path of the base URL
Source:
Returns:
URL
Type
Object

(inner) chainUpdates(depth, chainIds, callback, networkopt, hostopt)

Apply callback to new updates. Same as headerUpdates, but filters for chains and only processes header updates that have reached the given confirmation depth in the chain.
Parameters:
Name Type Attributes Default Description
depth number confirmation depth at which blocks are yielded
chainIds Array.<number> array of chainIds from which blocks are included
callback blockCallback function that is called for each update
network string <optional>
"mainnet01" chainweb network
host string <optional>
"https://api.chainweb.com" chainweb api host
Source:
Returns:
the event source object the backs the stream

(inner) chainUrl(chainId, networkopt, hostopt, pathSuffix) → {Object}

Create URL for a chain endpoint of the Chainweb API
Parameters:
Name Type Attributes Default Description
chainId number | string a chain id that is valid for the network
network string <optional>
"mainnet01" chainweb network
host string <optional>
"https://api.chainweb.com" chainweb api host
pathSuffix string suffix of the path that is appended to the path of the chain URL
Source:
Returns:
URL
Type
Object

(inner) filterEvents()

Utility function to filter the events from an array of blocks
Source:

(inner) filterTxs()

Utility function to filter the transactions from an array of blocks
Source:

(async, inner) headers2blocks()

Utility function for collecting the payloads with outputs for a set of headers from the same chain. TODO: Currently all blocks must be from the same chain. We should support blocks from different chains.
Source:

(inner) headerUpdates(callback, networkopt, hostopt)

Parameters:
Name Type Attributes Default Description
callback headerCallback function that is called for each update
network string <optional>
"mainnet01" chainweb network
host string <optional>
"https://api.chainweb.com" chainweb api host
Source:

(async, inner) retryFetch(retryOptionsopt) → {Promise}

Retry a fetch callback
Parameters:
Name Type Attributes Description
retryOptions Object <optional>
retry options object as accepted by the retry package
Properties
Name Type Attributes Default Description
retry404 boolean <optional>
false whether to retry on 404 results
Source:
Returns:
Promise object that represents the response of the fetch action.
Type
Promise

Type Definitions

blockCallback(block)

Callback for processing individual items of a block stream
Parameters:
Name Type Description
block Object block object
Source:

eventCallback(event)

Callback for processing individual items of an event stream
Parameters:
Name Type Description
event Object event object
Source:

headerCallback(header)

Callback for processing individual items of a header stream
Parameters:
Name Type Description
header Object header object
Source:

transactionCallback(transaction)

Callback for processing individual items of a transaction stream
Parameters:
Name Type Description
transaction Object transaction object
Source:

updatesCallback(update)

Callback for processing individual items of an updates stream
Parameters:
Name Type Description
update Object update object
Source: