Create a new instance of the Client class from the given set of representatives. This is used to create a new instance of the Client class with a custom set of representatives.
New instances should be cleaned up with the destroy() method when they are no longer needed.
In general this is not needed and the Client.fromNetwork() method should be used instead.
The representatives to use for this instance of the Client class
Optional
weight?: bigintThe weight of the representative, in terms of voting power
A new instance of the Client class
The logger to use for this instance of the Client class. This
is defined by the Client.DefaultLogger
property, but can be overridden
by the application.
Readonly
statsStats for this instance of the client
Breakdown of the API calls made
The total number of times the API was called
The number of times the API failed
Static
Readonly
BuilderA reference to the UserClientBuilder class, which is the high-level interface to building blocks.
Static
Readonly
ConfigA reference to the Config class, which provides access to the KeetaNet configuration utilities.
Static
DefaultThe default logger to use for new instances of the Client class.
This is set to the console
object by default, but can be changed
by the application.
Static
isCheck if the given object is an instance of the Client class.
This is preferred to using the instanceof
operator because it will
work across different contexts.
Get the list of representatives that the CLIENT is aware of
The list of representatives that the client is aware of
Compute the blocks for a given builder. This will take the pending operations and compute the blocks for them.
This will additionally mutate the state of the builder to "seal" the blocks meaning new operations will be added to new blocks.
The network to use for the builder
The builder to use for the computation
The blocks that were computed
Destroy this instance of the Client class. This will clean up any resources used by the instance and stop any background tasks.
Fetch the account information for a given account. This will return the account information including the current head block, representative, balances, and metadata.
The account to fetch the information for
The account information
Fetch the account information for multiple accounts. This will return the account information including the current head block, representative, balances, and metadata for each account.
The accounts to fetch the information for
The account information for each account, as an object with the account as the key and the account information as the value
Get the balance of a given account for all tokens.
The account to get the balance for
An array of objects which specify the token and the balance for each token the user holds a balance for
Get a list of all representatives that the node is aware of and their weights. This will fetch the information from all representatives
The list of all representatives and their weights
Get the balance of a given account for a given token.
The account to get the balance for
The token to get the balance of for the given account
The balance of the account for the given token
Get a block from the specified representative by its block hash.
The default mode of operation will request the block from the main ledger of the "best" representative.
The "side" ledger is a special ledger that is used to hold unpublished blocks that the given representative has learned about but which have not been published to the network. This is used as part of the voting process.
The block hash to get the block for
The block for the given block hash or null if the block does not exist on the given ledger
The block hash to get the block for
Optional
side: LedgerSelectorThe side of the ledger to get the block from -- this is generally "main", but it is possible to request "side" ledger blocks
Optional
rep: ClientRepresentative | "ANY"The representative to get the block from -- this is generally "ANY" in which case the best representative will be used, but it is possible to request a specific representative
The block for the given block hash or null if the block does not exist on the given ledger
Get the chain for a given account. This is the set of blocks that the account has created. This will return the blocks in reverse order, with the most recent block first.
This is a paginated request and may return only a partial set of
blocks for a given request if there are more blocks to be fetched
from the representative. The startBlock
parameter can be used to
fetch the next set of blocks. Once all blocks have been fetched
an empty array will be returned.
The depth
parameter can be used to limit the number of blocks
returned. The default is to leave it up to the representative to
determine the number of blocks to return. The representative
may return fewer than the requested number of blocks even if there
are more blocks available, except that it will always return at
least 1 block if there are any blocks available.
The account to get the chain for
The options to use for the request
Optional
depth?: numberThe maximum number of blocks to return -- this is used to limit the number of blocks returned
Optional
startBlock?: string | BlockHashThe block hash to start from -- this is used to paginate the request
The chain of blocks for the given account, in reverse order starting with the most recent block
Get the current head block for a given account. This will return the entire block, or null if the account has not created any blocks.
An account with no blocks may still have a balance because other users may have sent tokens to it.
The account to get the head block for
The head block for the account or null if the account has not created any blocks
Get the history for a given account. This is the set of vote staples that have interacted with the account. This is different from the chain in that it includes vote staples that have affected this account but are not directly created by this account.
This is a paginated request and may return only a partial set of
vote staples for a given request if there are more vote staples
to be fetched from the representative. The startBlocksHash
parameter can be used to fetch the next set of vote staples.
It can be computed from the last entry in the previous
response's blocksHash
field. Once all vote staples have been
fetched an empty array will be returned.
The depth
parameter can be used to limit the number of vote
staples returned. The default is to leave it up to the
representative to determine the number of vote staples to return.
The representative may return fewer than the requested number of
vote staples even if there are more vote staples available, except
that it will always return at least 1 vote staple if there are any
vote staples available.
The account to get the history for
The options to use for the request
Optional
depth?: numberThe maximum number of vote staples to return -- this is used to limit the number of vote staples returned
Optional
startBlocksHash?: string | VoteBlockHashThe block hash to start from -- this is used to paginate the request
The history of vote staples for the given account, in reverse order starting with the most recent vote staple
Work in progress
Get the network status of all representatives
Maximum time to wait for a response from a representative in milliseconds
Get statistics about the preferred representative
Get a list of peers that the node is connected to.
The list of peers that the node is connected to
Get the pending block for a given account. This will return the block on the representative's side ledger that is pending vote completion. This is used to recover the pending block for an account that has not been published yet.
The account to get the pending block for
The pending block for the account or null if there is no pending block
Get the representative information for a given representative account
Optional
rep: string | Account<ECDSA_SECP256K1 | ED25519 | ECDSA_SECP256R1>The representative account to get the information for
The representative information
Get the supply of a token. This will return the total supply of the specified token.
The token to get the supply for
The total supply of the token
Get the version of the node for a given representative, if no representative is specified then the version of the "best" representative will be returned.
Get the vote staple for a given block hash. This will return the entire vote staple including the blocks whose hash has not been requested.
The default mode of operation will request the block from the main ledger of the "best" representative.
The "side" ledger is a special ledger that is used to hold unpublished votes and blocks that the given representative has learned about but which have not been published to the network. This is used as part of the voting process.
The block hash to get the vote staple for
The vote staple for the given block hash or null if the vote staple does not exist on the given ledger
The block hash to get the vote staple for
Optional
side: LedgerStorageThe side of the ledger to get the vote staple from -- this is generally "main", but it is possible to request "side" ledger blocks
The vote staple for the given block hash or null if the vote staple does not exist on the given ledger
Get a list of vote staples that have been added to the representative's ledger since a given moment in time.
This method is used to bootstrap a new node with the vote staples that have been added to the ledger since the last time the node was updated.
It is a paginated request and may return only a partial set of
vote staples for a given request if there are more vote staples
to be fetched from the representative. The moment
parameter
can be used to fetch the next set of vote staples, and the
bloomFilter
parameter can be used to tell the server not to
include any duplicate vote staples that have already been sent
as part of the last page in the case of a moment
overlap.
Once all vote staples have been fetched an empty array will be
returned.
The bloom filter is constructed from the bytes of the vote staples to exclude.
The moment in time to get the vote staples after
Optional
limit: numberThe maximum number of vote staples to return
Optional
bloomFilter: stringThe bloom filter to use to filter the vote staples which have already been sent
The list of vote staples that have been added to the representative's ledger since the given moment in time
List the ACLs that have been set on a given account by any other account. This will return the ACLs including the principal.
The account to list the ACLs for
The ACLs for the account where the entity is the specified account
List the ACLs that have been set for a given account that are targeting a particular set of accounts. This will return the ACLs including the principal, entity, and permissions for each ACL entry.
The account to list the ACLs for
The accounts to filter the ACLs by
The ACLs for the account where the target is one of the specified accounts
List the ACLs that have been set for a given account that are targeting a particular set of accounts. This will return the ACLs including the principal, entity, and permissions for each ACL entry.
The account to list the ACLs for
The accounts to filter the ACLs by
The ACLs for the account where the target is one of the specified accounts with additional information
Create a new instance of the UserClientBuilder class. This is a convenience method to create a new instance of the builder class.
The builder class is used to create blocks in a high-level way.
The options to use for the builder
Optional
userClient?: UserClientOrClientAndNetworkUser Client or object with a client and network
Recover any unpublished or half-publish account artifacts
Account to recover
Publish the recovered staple to the network (default is true)
Transmit a set of blocks to the network. This will request short votes and permanent votes for the blocks and then publish them to the network.
The blocks or UserClientBuilder to transmit
The result of the publish operation
Transmit a set of blocks to the network. This will request short votes and permanent votes for the blocks and then publish them to the network.
The blocks
builder will be computed using computeBuilderBlocks and then transmitted.
The UserClientBuilder to compute and transmit transmit
The network to use for the builder (if using a builder)
The result of the publish operation
Publish a Vote Staple to the network. This will publish the votes and blocks to the network.
If reps
is not defined then the highest weight representative
will be used. If reps
is defined then the votes and blocks
will be published to all representatives in the list.
The votes and blocks to publish
Optional
reps: ClientRepresentative[]The representatives to publish to
Optional
weight?: bigintThe weight of the representative, in terms of voting power
The result of the publish operation as well as the vote staple
Update this client's view of the network representatives. This will fetch the list of representatives from the network and update the list of representatives that this client will use.
If true, add any new representatives to the list of representatives
Static
fromConstruct a new instance of the Client class from the given network name. This will use the default representatives for the network based on the configuration.
New instances should be cleaned up with the destroy() method when they are no longer needed.
This is the recommended way to create a new instance of the Client class.
The network to use for this instance of the Client class
A new instance of the Client class
The Client class provides a low-level interface to the KeetaNet network. It handles sending messages to the KeetaNet representatives and parsing the responses.
It does not handle any of the higher-level logic of the KeetaNet network, for that there is the UserClient class.
Example