Client
Nimiq Albatross client that runs in browsers via WASM and is exposed to Javascript.
Usage:
Methods
addConsensusChangedListener()
Adds an event listener for consensus-change events, such as when consensus is established or lost.
Parameter | Type |
---|---|
First | ( state) => any`` |
<number > |
addHeadChangedListener()
Adds an event listener for new blocks added to the blockchain.
Parameter | Type |
---|---|
First | ( hash, reason, reverted_blocks, adopted_blocks) => any`` |
<number > |
addPeerChangedListener()
Adds an event listener for peer-change events, such as when a new peer joins, or a peer leaves.
Parameter | Type |
---|---|
First | ( peer_id, reason, peer_count, peer_info?) => any`` |
<number > |
addTransactionListener()
Adds an event listener for transactions to and from the provided addresses.
The listener is called for transactions when they are included in the blockchain.
Parameter | Type |
---|---|
First | ( string| [Address](Address) | Uint8Array)[] |
<number > |
connectNetwork()
This function is used to tell the network to (re)start connecting to peers. This is could be used to tell the network to restart connection operations after disconnect network is called.
<void
>
disconnectNetwork()
This function is used to tell the network to disconnect from every connected peer and stop trying to connect to other peers.
Important: this function returns when the signal to disconnect was sent, before all peers actually disconnect. This means that in order to ensure the network is disconnected, wait for all peers to disappear after calling.
<void
>
free()
getAccount()
Fetches the account for the provided address from the network.
Throws if the address cannot be parsed and on network errors.
Parameter | Type |
---|---|
First | string | Address | Uint8Array |
<PlainAccount> |
getAccounts()
Fetches the accounts for the provided addresses from the network.
Throws if an address cannot be parsed and on network errors.
Parameter | Type |
---|---|
First | ( string| [Address](Address) | Uint8Array)[] |
<PlainAccount[]> |
getAddressBook()
Returns the current address books peers. Each peer will have one address and currently no guarantee for the usefulness of that address can be given.
The resulting Array may be empty if there is no peers in the address book.
<PlainPeerInfo[]>
getBlock()
Fetches a block by its hash.
Throws if the client does not have the block.
Fetching blocks from the network is not yet available.
Parameter | Type |
---|---|
First | string |
<PlainBlock> |
getBlockAt()
Fetches a block by its height (block number).
Throws if the client does not have the block.
Fetching blocks from the network is not yet available.
Parameter | Type |
---|---|
First | number |
<PlainBlock> |
getHeadBlock()
Returns the current blockchain head block. Note that the web client is a light client and does not have block bodies, i.e. no transactions.
getHeadHash()
Returns the block hash of the current blockchain head.
<string
>
getHeadHeight()
Returns the block number of the current blockchain head.
<number
>
getNetworkId()
Returns the network ID that the client is connecting to.
<number
>
getStaker()
Fetches the staker for the provided address from the network.
Throws if the address cannot be parsed and on network errors.
Parameter | Type |
---|---|
First | string | Address | Uint8Array |
<PlainStaker> |
getStakers()
Fetches the stakers for the provided addresses from the network.
Throws if an address cannot be parsed and on network errors.
Parameter | Type |
---|---|
First | ( string| [Address](Address) | Uint8Array)[] |
<PlainStaker[]> |
getTransaction()
Fetches the transaction details for the given transaction hash.
Parameter | Type |
---|---|
First | string |
<PlainTransactionDetails> |
getTransactionReceiptsByAddress()
This function is used to query the network for transaction receipts from and to a specific address, that have been included in the chain.
The obtained receipts are not verified before being returned.
Up to a limit
number of transaction receipts are returned from newest to oldest.
It starts at the start_at
transaction and goes backwards. If this hash does not exist
or does not belong to the address, an empty list is returned.
If the network does not have at least min_peers
to query, then an error is returned.
Parameter | Type |
---|---|
First | number |
<PlainTransactionReceipt[]> |
getTransactionsByAddress()
This function is used to query the network for transactions from and to a specific address, that have been included in the chain.
The obtained transactions are verified before being returned.
If you already have transactions belonging to this address, you can provide some of that information to reduce the amount of network requests made:
- Provide the
since_block_height
parameter to exclude any history from before that block height. You should be completely certain about its state. This should not be the last known block height, but an earlier block height that could not have been forked from (e.g. the last known election or checkpoint block). - Provide a list of
known_transaction_details
to have them verified and/or broadcasted again. - Provide a
start_at
parameter to start the query at a specific transaction hash (which will not be included). This hash must exist and the corresponding transaction must involve this address for the query to work correctly.
Up to a limit
number of transactions are returned from newest to oldest.
If the network does not have at least min_peers
to query, an error is returned.
Parameter | Type |
---|---|
First | number |
<PlainTransactionDetails[]> |
getValidator()
Fetches the validator for the provided address from the network.
Throws if the address cannot be parsed and on network errors.
Parameter | Type |
---|---|
First | string | Address | Uint8Array |
<PlainValidator> |
getValidators()
Fetches the validators for the provided addresses from the network.
Throws if an address cannot be parsed and on network errors.
Parameter | Type |
---|---|
First | ( string| [Address](Address) | Uint8Array)[] |
<PlainValidator[]> |
isConsensusEstablished()
Returns if the client currently has consensus with the network.
<boolean
>
removeListener()
Removes an event listener by its handle.
Parameter | Type |
---|---|
First | number |
<void > |
sendTransaction()
Sends a transaction to the network and returns PlainTransactionDetails.
Throws in case of network errors.
Parameter | Type |
---|---|
First | string | PlainTransaction | Uint8Array | Transaction |
<PlainTransactionDetails> |
waitForConsensusEstablished()
Returns a promise that resolves when the client has established consensus with the network.
<void
>
create()
Creates a new Client that automatically starts connecting to the network.
Parameter | Type |
---|---|
First | PlainClientConfiguration |
<Client> |