Home Reference Source Test
public class | source

Client

Constructor Summary

Public Constructor
public

constructor(config: Client.Configuration | object, consensus: Promise<BaseConsensus>)

Member Summary

Public Members
public get

mempool: Client.Mempool

Access the mempool directly.

public get

network: Client.Network

Access and modify network information such as connected peers.

Method Summary

Public Methods
public

async addBlockListener(listener: BlockListener): Promise<Handle>

public
public
public

async addTransactionListener(listener: TransactionListener, addresses: Array<Address|string>): Promise<Handle>

public

async getAccount(address: Address | string): Promise<Account>

Fetches a single account and its associated data by its address.

public

async getAccounts(addresses: Array<Address|string>): Promise<Array<Account>>

Fetches multiple accounts and their associated data by their addresses.

public

async getBlock(hash: Hash | string, includeBody: boolean): Promise<Block>

Fetches the block with the specified hash.

public

async getBlockAt(height: number, includeBody: boolean): Promise<Block>

Fetches the block at the specified height or block number.

public

async getBlockTemplate(minerAddress: Address | string, extraData: Uint8Array | string): Promise<Block>

Creates a template for the next block to be generated.

public

async getHeadBlock(includeBody: boolean): Promise<Block>

Fetches the block that is the current tip of the chain.

public

async getHeadHash(): Promise<Hash>

Fetches the hash of the current tip of the chain.

public

async getHeadHeight(): Promise<number>

Fetches the height or block number of the current tip of the chain.

public

async getTransaction(hash: Hash | string, blockHash: Hash | string, blockHeight: number): Promise<TransactionDetails>

Fetches a single transaction by its transaction hash.

public

async getTransactionReceipt(hash: Hash | string): PromiseTransactionReceipt>

Fetches a single transaction receipt by its transaction hash.

public

async getTransactionReceiptsByAddress(address: Address | string): Promise<Array<TransactionReceipt>>

Fetches transaction history as receipts for a single address.

public

async getTransactionReceiptsByHashes(hashes: Array<Hash|string>): Promise<Array<TransactionReceipt>>

Fetches multiple transaction receipts by their transaction hash.

public

async getTransactionsByAddress(address: Address | string, sinceBlockHeight: number, knownTransactionDetails: Array<Client.TransactionDetails>): Promise<Array<Client.TransactionDetails>>

This method can be used to fetch the transaction history for a specific address as well as any pending transactions related to it.

public

async removeListener(handle: Handle): Promise

public

async sendTransaction(tx: Transaction | object | string): Promise<TransactionDetails>

public

async submitBlock(block: Block | string): Promise<boolean>

Submits a block to the blockchain.

public

Public Constructors

public constructor(config: Client.Configuration | object, consensus: Promise<BaseConsensus>) source

Params:

NameTypeAttributeDescription
config Client.Configuration | object
consensus Promise<BaseConsensus>
  • optional

Public Members

public get mempool: Client.Mempool source

Access the mempool directly. Allows for unfiltered processing of all transactions in the mempool.

public get network: Client.Network source

Access and modify network information such as connected peers.

Public Methods

public async addBlockListener(listener: BlockListener): Promise<Handle> source

Params:

NameTypeAttributeDescription
listener BlockListener

Return:

Promise<Handle>

public async addConsensusChangedListener(listener: ConsensusChangedListener): Promise<Handle> source

Params:

NameTypeAttributeDescription
listener ConsensusChangedListener

Return:

Promise<Handle>

public async addHeadChangedListener(listener: HeadChangedListener): Promise<Handle> source

Params:

NameTypeAttributeDescription
listener HeadChangedListener

Return:

Promise<Handle>

public async addTransactionListener(listener: TransactionListener, addresses: Array<Address|string>): Promise<Handle> source

Params:

NameTypeAttributeDescription
listener TransactionListener
addresses Array<Address|string>

Return:

Promise<Handle>

public async getAccount(address: Address | string): Promise<Account> source

Fetches a single account and its associated data by its address.

Data returned by this method authenticated according to the current tip of the blockchain. Any further changes to as well as forks of the blockchain might invalidate the data. To ensure up-to-date information, subscribe to head changes (via #addHeadChangedListener) and refetch the account details.

Params:

NameTypeAttributeDescription
address Address | string

Address of an account

Return:

Promise<Account>

Single account and its associated data

public async getAccounts(addresses: Array<Address|string>): Promise<Array<Account>> source

Fetches multiple accounts and their associated data by their addresses.

Data returned by this method authenticated according to the current tip of the blockchain. Any further changes to as well as forks of the blockchain might invalidate the data. To ensure up-to-date information, subscribe to head changes (via #addHeadChangedListener) and refetch the account details.

Params:

NameTypeAttributeDescription
addresses Array<Address|string>

List of addresses of accounts

Return:

Promise<Array<Account>>

List of accounts and their associated data

public async getBlock(hash: Hash | string, includeBody: boolean): Promise<Block> source

Fetches the block with the specified hash. Depending on your client configuration, this might include blocks that do not exist on the current chain but are present on forks.

Params:

NameTypeAttributeDescription
hash Hash | string

The hash of a block

includeBody boolean
  • optional
  • default: true

Whether to include the transactions and other details of the block. If the client is not able to do so, it will return a block without such data.

Return:

Promise<Block>

The block with the specified hash. Throws an error if the block cannot be retrieved or no block with the specified hash exists.

public async getBlockAt(height: number, includeBody: boolean): Promise<Block> source

Fetches the block at the specified height or block number.

Data returned by this method authenticated according to the current tip of the blockchain. Any further forks of the blockchain might invalidate the data.

Params:

NameTypeAttributeDescription
height number

The height or block number of the block to fetch

includeBody boolean
  • optional
  • default: true

Whether to include the transactions and other details of the block. If the client is not able to do so, it will return a block without such data.

Return:

Promise<Block>

The block at the specified height or block number. Throws an error if the block cannot be retrieved or no block at the specified height exists.

public async getBlockTemplate(minerAddress: Address | string, extraData: Uint8Array | string): Promise<Block> source

Creates a template for the next block to be generated. This can be used to mine further blocks on top of the current chain.

Note that this functionality might not be available depending on your client configuration.

Params:

NameTypeAttributeDescription
minerAddress Address | string

Address that will be rewarded for mining the block.

extraData Uint8Array | string
  • optional

Optional extra data to be embedded in the block.

Return:

Promise<Block>

Template for the next block to be generated

public async getHeadBlock(includeBody: boolean): Promise<Block> source

Fetches the block that is the current tip of the chain.

Data returned by this method authenticated according to the current tip of the blockchain. Any further changes to as well as forks of the blockchain might invalidate the data.

Params:

NameTypeAttributeDescription
includeBody boolean
  • optional
  • default: true

Whether to include the transactions and other details of the block. If the client is not able to do so, it will return a block without such data.

Return:

Promise<Block>

The block that is the current tip of the chain

public async getHeadHash(): Promise<Hash> source

Fetches the hash of the current tip of the chain.

Data returned by this method authenticated according to the current tip of the blockchain. Any further changes to as well as forks of the blockchain might invalidate the data.

Return:

Promise<Hash>

Hash of the current tip of the chain

public async getHeadHeight(): Promise<number> source

Fetches the height or block number of the current tip of the chain.

Data returned by this method authenticated according to the current tip of the blockchain. Any further changes to as well as forks of the blockchain might invalidate the data.

Return:

Promise<number>

The height or block number of the current tip of the chain.

public async getTransaction(hash: Hash | string, blockHash: Hash | string, blockHeight: number): Promise<TransactionDetails> source

Fetches a single transaction by its transaction hash. This method can be used to fetch transactions that have been mined as well as pending transactions.

If you happen to know the hash and height of the block that contained the transaction, for example from a transaction receipt fetched earlier, you can provide such details to speed up the process of verification.

Data returned by this method is authenticated. Note that transactions with the state Client.TransactionState.MINED may be reverted as the chain is forked. Transactions with state Client.TransactionState.CONFIRMED are considered confirmed according to the configuration provided during client initialization.

Params:

NameTypeAttributeDescription
hash Hash | string

Hash of a transaction

blockHash Hash | string
  • optional

The hash of the block containing that transaction

blockHeight number
  • optional

The height of the block containing that transaction

Return:

Promise<TransactionDetails>

Details about the requested transaction. Throws an error if the no such transaction exists.

public async getTransactionReceipt(hash: Hash | string): PromiseTransactionReceipt> source

Fetches a single transaction receipt by its transaction hash.

Note that transaction receipts might be unauthenticated data depending on your client configuration and should not necessarily be considered a confirmation that a transaction was actually mined in a block.

Params:

NameTypeAttributeDescription
hash Hash | string

Hash of a transaction

Return:

PromiseTransactionReceipt>

public async getTransactionReceiptsByAddress(address: Address | string): Promise<Array<TransactionReceipt>> source

Fetches transaction history as receipts for a single address.

Note that transaction receipts might be unauthenticated data depending on your client configuration and should not necessarily be considered a confirmation that a transaction was actually mined in a block.

Params:

NameTypeAttributeDescription
address Address | string

Address of an account

Return:

Promise<Array<TransactionReceipt>>

public async getTransactionReceiptsByHashes(hashes: Array<Hash|string>): Promise<Array<TransactionReceipt>> source

Fetches multiple transaction receipts by their transaction hash.

Note that transaction receipts might be unauthenticated data depending on your client configuration and should not necessarily be considered a confirmation that a transaction was actually mined in a block.

Params:

NameTypeAttributeDescription
hashes Array<Hash|string>

List of hashes of transactions

Return:

Promise<Array<TransactionReceipt>>

public async getTransactionsByAddress(address: Address | string, sinceBlockHeight: number, knownTransactionDetails: Array<Client.TransactionDetails>): Promise<Array<Client.TransactionDetails>> source

This method can be used to fetch the transaction history for a specific address as well as any pending transactions related to it.

If you already fetched the transaction history before, you can provide some of this information.

  • If you provide {@param sinceBlockHeight}, the logic assumes that you already know all transactions up to that state and are completely certain about its status. This should not be the last known block height, but a lower value that could not have been forked from (i.e. this should be lower than last known block height - required block confirmations, as else you would not be informed about transactions being confirmed)
  • If you are aware of transactions that happened since {@param sinceBlockHeight} or were pending before you can provide them as well. This ensures you receive an update on them even with misbehaving peers. Pending transactions that appear to not have been mined will be stored in the local mempool and send to peers to ensure they are aware as well.

Data returned by this method is authenticated. Note that transactions with the state Client.TransactionState.MINED may be reverted as the chain is forked. Transactions with state Client.TransactionState.CONFIRMED are considered confirmed according to the configuration provided during client initialization.

Params:

NameTypeAttributeDescription
address Address | string

Address of an account

sinceBlockHeight number
  • optional
  • default: 0

Minimum block height to consider for updates

knownTransactionDetails Array<Client.TransactionDetails>
  • optional

List of transaction details on already known transactions since {@param sinceBlockHeight}

Return:

Promise<Array<Client.TransactionDetails>>

public async removeListener(handle: Handle): Promise source

Params:

NameTypeAttributeDescription
handle Handle

Return:

Promise

public async sendTransaction(tx: Transaction | object | string): Promise<TransactionDetails> source

Params:

NameTypeAttributeDescription
tx Transaction | object | string

Return:

Promise<TransactionDetails>

public async submitBlock(block: Block | string): Promise<boolean> source

Submits a block to the blockchain.

Note that this functionality might not be available depending on your client configuration.

Params:

NameTypeAttributeDescription
block Block | string

The block to append to the blockchain.

Return:

Promise<boolean>

public waitForConsensusEstablished(): Promise source

Return:

Promise