Optional
options: Partial<GrpcOptions>Start dumping packages into the specified file.
Only enabled if the node was built with the network_dump
feature.
Rejects if the network dump failed to start.
await client.dumpStart(cli.flags.filepath, cli.flags.dumpRaw);
console.log('Dump successfully started');
Which file to dump the packages into. Requires a valid path.
Whether the node should dump raw packages.
Find a block with lowest possible height where the predicate holds. Note that this function uses binary search and is only intended to work for monotone predicates.
The value returned from predicate
at the lowest block (in terms of height) where the predicate holds.
A predicate function resolving with value of type R if the predicate holds, and undefined if not.
The precondition for this method is that the function is monotone, i.e., if block at height h
satisfies the test then also a block at height h+1
does.
If this precondition does not hold then the return value from this method is unspecified.
Optional
from: bigint = ...An optional lower bound of the range of blocks to search. Defaults to 0n.
Optional
to: bigintAn optional upper bound of the range of blocks to search. Defaults to latest finalized block.
Find the first block finalized after a given time.
Information about the block found, or undefined if no block was found.
The time to find first block after
Optional
from: bigintAn optional lower bound of the range of blocks to search. Defaults to 0n.
Optional
to: bigintAn optional upper bound of the range of blocks to search. Defaults to latest finalized block.
Find the block where a smart contract instance was created. This is a specialized form of findEarliestFinalized.
Information about the block and the contract instance, or undefined if not found.
The contract address to search for.
Optional
from: bigintAn optional lower bound of the range of blocks to search. Defaults to 0n.
Optional
to: bigintAn optional upper bound of the range of blocks to search. Defaults to latest finalized block.
Retrieves the account info for the given account. If the provided block hash is in a block prior to the finalization of the account, then the account information will not be available. A credential registration id can also be provided, instead of an address. In this case the node will return the account info of the account, which the corresponding credential is (or was) deployed to. An account index can also be provided.
const accountAddress = AccountAddress.fromBase58(cli.flags.account);
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const accountInfo: AccountInfo = await client.getAccountInfo(accountAddress, blockHash);
console.log('Account balance:', accountInfo.accountAmount);
console.log('Account address:', accountInfo.accountAddress);
// If the account is a delegator print delegator information
if (accountInfo.type === AccountInfoType.Delegator) {
console.log('Delegated stake amount:', accountInfo.accountDelegation.stakedAmount);
}
the account info for the provided account address.
An error of type RpcError
if not found in the block.
base58 account address, or a credential registration id or account index to get the account info for
Optional
blockHash: BlockHashoptional block hash to get the account info at, otherwise retrieves from last finalized block
Retrieve a stream of accounts that exist at the end of the given block.
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const accounts: AsyncIterable<AccountAddress.Type> = client.getAccountList(blockHash);
an async iterable of account addresses.
Optional
blockHash: BlockHashan optional block hash to get the accounts at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Get a list of non-finalized transaction hashes for a given account. This endpoint is not expected to return a large amount of data in most cases, but in bad network conditions it might. The stream will end when all the non-finalized transaction hashes have been returned.
From ./../examples/nodejs/client/getAccountNonFinalizedTransactions.ts#52~55
const accountAddress = AccountAddress.fromBase58(cli.flags.account);
const transactions: AsyncIterable<TransactionHash.Type> = client.getAccountNonFinalizedTransactions(accountAddress);
a stream of transaction hashes.
The address of the account that you wish to query.
Optional
abortSignal: AbortSignalGet a stream of ancestors for the provided block. Starting with the provided block itself, moving backwards until no more ancestors or the requested number of ancestors has been returned.
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const ancestors: AsyncIterable<BlockHash.Type> = client.getAncestors(BigInt(cli.flags.maxAncestors), blockHash);
an async iterable of ancestors' block hashes.
the maximum amount of ancestors as a bigint.
Optional
blockHash: BlockHasha optional block hash to get the ancestors at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Get the anonymity revokers registered as of the end of a given block. The stream will end when all the anonymity revokers have been returned, or an abort signal is called.
From ./../examples/nodejs/client/getAnonymityRevokers.ts#47~56
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const ars: AsyncIterable<ArInfo> = client.getAnonymityRevokers(blockHash);
for await (const ar of ars) {
console.log('Anonymity Revoker ID:', ar.arIdentity);
console.log('Anonymity Revoker name:', ar.arDescription.name);
console.log('Anonymity Revoker description:', ar.arDescription.description, '\n');
}
an async iterable of identity provider info objects.
Optional
blockHash: BlockHashan optional block hash to get the anonymity revokers at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Get the projected earliest time at which a particular baker will be required to bake a block.
If the baker is not a baker for the current reward period, this returns a timestamp at the start of the next reward period. If the baker is a baker for the current reward period, the earliest win time is projected from the current round forward, assuming that each round after the last finalized round will take the minimum block time. (If blocks take longer, or timeouts occur, the actual time may be later, and the reported time in subsequent queries may reflect this.) At the end of an epoch (or if the baker is not projected to bake before the end of the epoch) the earliest win time for a (current) baker will be projected as the start of the next epoch. This is because the seed for the leader election is updated at the epoch boundary, and so the winners cannot be predicted beyond that. Note that in some circumstances the returned timestamp can be in the past, especially at the end of an epoch.
an UNAVAILABLE
RPC error if the current consensus version is 0 (prior to protocol version 6), as the endpoint is only supported from consensus version 1 (from protocol version 6).
The projected earliest time at which a particular baker will be required to bake a block, as a unix timestamp in milliseconds.
The baker that should be queried for.
Get all the bakers at the end of the given block.
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const bakerIds: AsyncIterable<BakerId> = client.getBakerList(blockHash);
an async iterable of BakerIds.
Optional
blockHash: BlockHashan optional block hash to get the baker list at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Get all bakers in the reward period of a block. This endpoint is only supported for protocol version 6 and onwards.
an IllegalArgument
RPC error if the protocol does not support the endpoint.
All bakers in the reward period of a block
Optional
blockHash: BlockHashoptional block hash to get the cryptographic parameters at, otherwise retrieves from last finalized block.
For a non-genesis block, this returns the quorum certificate, a timeout certificate (if present) and epoch finalization entry (if present).
an UNIMPLEMENTED
RPC error if the endpoint is not enabled by the node.
an INVALID_ARGUMENT
if the block being pointed to is not a product of ConcordiumBFT
the requested block certificates.
Optional
blockHash: BlockHashoptional block hash to get the cryptographic parameters at, otherwise retrieves from last finalized block.
Retrieves the status of the block chain parameters at the given blockHash.
From ./../examples/nodejs/client/getBlockChainParameters.ts#43~59
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const cp: ChainParameters = await client.getBlockChainParameters(blockHash);
const euroPerEnergy = cp.euroPerEnergy.numerator + '/' + cp.euroPerEnergy.denominator;
console.log('Account creation limit:', cp.accountCreationLimit);
console.log('Euro per Energy:', euroPerEnergy);
// Check version of chain parameters
if (cp.version === 2) {
console.log('Minimum block time', cp.minBlockTime);
} else if (cp.version === 1) {
console.log('Minimum equity capital:', cp.minimumEquityCapital);
} else {
console.log('Chain parameters is V0 and does not contain information on minimum equity capital');
}
Info on all of the block chain parameters.
Optional
blockHash: BlockHashthe block hash of the block to get the information from.
Get the summary of the finalization data in a given block.
From ./../examples/nodejs/client/getBlockFinalizationSummary.ts#47~60
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const summary: BlockFinalizationSummary = await client.getBlockFinalizationSummary(blockHash);
if (summary.tag === 'record') {
// Response contains finalization summary for the given block:
console.log('block:', summary.record.block);
console.log('index:', summary.record.index);
console.log('delay:', summary.record.delay);
console.log('Amount of finalizers:', summary.record.finalizers.length);
} else {
console.log('Given block has not been finalized, and no information can be gotten');
}
a finalization summary
Optional
blockHash: BlockHashan optional block hash to get the finalization summaries at, otherwise retrieves from last finalized block.
Get information, such as height, timings, and transaction counts for the given block.
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const blockInfo: BlockInfo = await client.getBlockInfo(blockHash);
information on a block.
Optional
blockHash: BlockHashan optional block hash to get the info from, otherwise retrieves from last finalized block.
Retrieves a status for the given transaction/block item.
From ./../examples/nodejs/client/getBlockItemStatus.ts#51~108
const blockItemStatus: BlockItemStatus = await client.getBlockItemStatus(
TransactionHash.fromHexString(cli.flags.transaction)
);
console.log('Status of the transaction:', cli.flags.transaction, '\n');
// Note that there will be no outcomes for a transaction that has only been received:
if (blockItemStatus.status === 'received') {
console.log('blockItemStatus is "received" and therefore has no "status" field');
}
// If the transaction has only been committed, then there is a list of outcomes:
if (blockItemStatus.status === 'committed') {
console.log('blockItemStatus is "committed" and therefore there are potentially multiple outcomes');
}
// If the transaction has been finalized, then there is exactly one outcome:
if (blockItemStatus.status === 'finalized') {
console.log('blockItemStatus is "finalized" and therefore there is exactly one outcome \n');
const { summary } = blockItemStatus.outcome;
if (summary.type === 'accountTransaction') {
console.log('The block item is an account transaction');
switch (summary.transactionType) {
case 'transfer':
// The transaction is a simple transfer
const { amount, to } = summary.transfer;
const ccdAmount = CcdAmount.toCcd(amount);
console.log(ccdAmount, 'CCD sent to', to);
break;
case 'failed':
// The transaction was rejected, in which case the transaction
// type is still available under the failedTransactionType field
const { failedTransactionType, rejectReason } = summary;
console.log(
'Transaction of type "' + failedTransactionType + '" failed because:',
rejectReason.tag
);
break;
default:
// Another transaction kind encountered
const otherType = summary.transactionType;
console.log('The transaction is of type:', otherType);
}
} else if (summary.type === 'updateTransaction') {
console.log('The block item is a chain update');
const { effectiveTime, payload } = summary;
console.log('EffectiveTime:', effectiveTime);
console.log('Payload:', payload);
console;
} else if (summary.type === 'accountCreation') {
console.log('The block item is an account creation');
console.log('Account created with address:', summary.address);
}
}
the status for the given transaction/block item, or undefined if it does not exist.
the transaction/block item to get a status for.
Get the pending updates to chain parameters at the end of a given block. The stream will end when all the pending updates for a given block have been returned.
From ./../examples/nodejs/client/getBlockPendingUpdates.ts#50~53
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const pendingUpdates: AsyncIterable<PendingUpdate> = client.getBlockPendingUpdates(blockHash);
a stream of pending updates
Optional
blockHash: BlockHashan optional block hash to get the pending updates at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Get a list of special events in a given block. These are events generated by the protocol, such as minting and reward payouts. They are not directly generated by any transaction. The stream will end when all the special events for a given block have been returned.
From ./../examples/nodejs/client/getBlockSpecialEvents.ts#51~54
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const events: AsyncIterable<BlockSpecialEvent> = client.getBlockSpecialEvents(blockHash);
a stream of block item summaries
Optional
blockHash: BlockHashan optional block hash to get the special events at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Get a list of transaction events in a given block. The stream will end when all the transaction events for a given block have been returned.
From ./../examples/nodejs/client/getBlockTransactionEvents.ts#49~52
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const events: AsyncIterable<BlockItemSummary> = client.getBlockTransactionEvents(blockHash);
a stream of block item summaries
Optional
blockHash: BlockHashan optional block hash to get the transaction events at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Gets a stream of blocks. To get a stream of only finalized blocks
use getFinalizedBlocks()
instead.
// Get block stream
const blocks: AsyncIterable<ArrivedBlockInfo> = client.getBlocks();
// Prints blocks infinitely
for await (const block of blocks) {
console.log('Arrived block height:', block.height);
console.log('Arrived block hash:', block.hash, '\n');
}
An AsyncIterator stream of blocks.
Optional
abortSignal: AbortSignalan AbortSignal to close the stream. Note that the stream does not close itself as it is infinite, so usually you'd want to provide this parameter.
Get a list of live blocks at a given height.
From ./../examples/nodejs/client/getBlocksAtHeightAbsolute.ts#46~48
const blocks: BlockHash.Type[] = await client.getBlocksAtHeight(BigInt(cli.flags.height));
A list of block hashes as hex strings
Either an absolute block height request or a relative block height request
Get the current branches of blocks starting from and including the last finalized block.
const branch: Branch = await client.getBranches();
console.log('Root hash:', branch.blockHash);
console.log("Root's children:");
console.dir(branch.children, { depth: null, colors: true });
a branch with a block hash and a list of branch-children
Retrieves the consensus status information from the node. Note that the optional fields will only be unavailable for a newly started node that has not processed enough data yet.
From ./../examples/nodejs/client/getConsensusStatus.ts#38~40
const consensusStatus: ConsensusStatus = await client.getConsensusStatus();
Retrieves the consensus status information from the node. Note that the optional fields will only be unavailable for a newly started node that has not processed enough data yet.
From ./../examples/nodejs/client/getCryptographicParameters.ts#44~47
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const parameters: CryptographicParameters = await client.getCryptographicParameters(blockHash);
the global cryptographic parameters at the given block, or undefined it the block does not exist.
Optional
blockHash: BlockHashoptional block hash to get the cryptographic parameters at, otherwise retrieves from last finalized block.
Get information related to the baker election for a particular block.
election info for the given block
Optional
blockHash: BlockHashan optional block hash to get the election info at, otherwise retrieves from last finalized block.
Retrieves the embedded schema of the given module at the provided block.
const moduleRef = ModuleReference.fromHexString(cli.flags.module);
const schema = await client.getEmbeddedSchema(moduleRef);
the module schema as a RawModuleSchema or null
if not found in the block.
An error of type RpcError
if the module was not found in the block.
If the module source cannot be parsed or contains duplicate schema sections.
the module's reference, represented by the ModuleReference class.
Optional
blockHash: BlockHashoptional block hash to get the module embedded schema at, otherwise retrieves from last finalized block
Gets a stream of finalized blocks.
From ./../examples/nodejs/client/getFinalizedBlocks.ts#39~48
// Get block stream
const blockStream: AsyncIterable<FinalizedBlockInfo> = client.getFinalizedBlocks();
// Prints blocks infinitely
for await (const block of blockStream) {
console.log('Arrived block height:', block.height);
console.log('Arrived block hash:', block.hash, '\n');
}
An AsyncIterator stream of finalized blocks.
Optional
abortSignal: AbortSignalan AbortSignal to close the stream. Note that the stream does not close itself as it is infinite, so usually you'd want to provide this parameter.
Gets a stream of finalized blocks from specified startHeight
.
A stream of v1.FinalizedBlockInfo.
Optional
startHeight: bigintAn optional height to start streaming blocks from. Defaults to 0n.
Optional
abortSignal: AbortSignalAn optional abort signal, which will end the stream. If this is not specified, the stream continues indefinitely.
Gets a stream of finalized blocks from specified startHeight
.
A stream of v1.FinalizedBlockInfo.
Optional
startHeight: bigintAn optional height to start streaming blocks from. Defaults to 0n.
Optional
endHeight: bigintAn optional height to stop streaming at. If this is not specified, the stream continues indefinitely.
Get the block hash of the first finalized block in a specified epoch.
The following error cases are possible:
NOT_FOUND
RPC error if the query specifies an unknown block.UNAVAILABLE
RPC error if the query is for an epoch that is not finalized in the current genesis index, or is for a future genesis index.INVALID_ARGUMENT
RPC error if the query is for an epoch with no finalized blocks for a past genesis index.INVALID_ARGUMENT
RPC error if the input EpochRequest
is malformed.UNAVAILABLE
RPC error if the endpoint is disabled on the node.The block hash as a hex encoded string.
Optional
epochRequest: BlockHash | RelativeEpochRequestConsists of either a block hash or a relative epoch request consisting of a genesis index and an epoch. If none is passed, it queries the last finalized block.
Get the identity providers registered as of the end of a given block. The stream will end when all the identity providers have been returned, or an abort signal is called.
From ./../examples/nodejs/client/getIdentityProviders.ts#47~55
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const ips: AsyncIterable<IpInfo> = client.getIdentityProviders(blockHash);
for await (const ip of ips) {
console.log('Identity Provider ID:', ip.ipIdentity);
console.log('Identity Provider Description:', ip.ipDescription, '\n');
}
an async iterable of identity provider info objects.
Optional
blockHash: BlockHashan optional block hash to get the providers at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Retrieve information about a given smart contract instance.
const contractAddress = ContractAddress.create(cli.flags.contract);
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const instanceInfo: InstanceInfo = await client.getInstanceInfo(contractAddress, blockHash);
console.log('Name:', instanceInfo.name);
console.log('Amount in CCD:', Number(instanceInfo.amount.microCcdAmount / 1000000n));
console.log('Version:', instanceInfo.version);
console.log('Owner:', instanceInfo.owner.address);
console.log('Module Reference:', instanceInfo.sourceModule.moduleRef);
console.log('Methods:');
for (const method of instanceInfo.methods) {
console.log(' ' + method);
}
An object with information about the contract instance.
An error of type RpcError
if not found in the block.
the address of the smart contract.
Optional
blockHash: BlockHashoptional block hash to get the smart contact instances at, otherwise retrieves from last finalized block
Get the exact state of a specific contract instance, streamed as a list of key-value pairs. The list is streamed in lexicographic order of keys.
const contractAddress = ContractAddress.create(cli.flags.contract);
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const states: AsyncIterable<InstanceStateKVPair> = client.getInstanceState(contractAddress, blockHash);
an async iterable of instance states as key-value pairs of hex strings.
the contract to get the state of.
Optional
blockHash: BlockHasha optional block hash to get the instance states at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Get a stream of all smart contract modules' references. The stream will end when all modules that exist in the state at the end of the given block have been returned.
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const moduleRefs: AsyncIterable<ModuleReference.Type> = client.getModuleList(blockHash);
an async iterable of contract module references.
Optional
blockHash: BlockHashan optional block hash to get the contract modules at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Retrieves the source of the given module at the provided block.
const ref = ModuleReference.fromHexString(cli.flags.module);
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const versionedSource = await client.getModuleSource(ref, blockHash);
the source of the module as raw bytes.
An error of type RpcError
if not found in the block.
the module's reference, represented by the ModuleReference class.
Optional
blockHash: BlockHashoptional block hash to get the module source at, otherwise retrieves from last finalized block
Retrieves the next account nonce for the given account. The account nonce is used in all account transactions as part of their header.
From ./../examples/nodejs/client/getNextAccountSequenceNumber.ts#50~56
const account = AccountAddress.fromBase58(cli.flags.account);
const nextNonce: NextAccountNonce = await client.getNextAccountNonce(account);
console.log('Next Nonce:', nextNonce.nonce);
console.log('Nonce is reliable:', nextNonce.allFinal);
the next account nonce, and a boolean indicating if the nonce is reliable.
base58 account address to get the next account nonce for.
Get next available sequence numbers for updating chain parameters after a given block.
From ./../examples/nodejs/client/getNextUpdateSequenceNumbers.ts#44~47
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const updateSeqNums: NextUpdateSequenceNumbers = await client.getNextUpdateSequenceNumbers(blockHash);
a NextUpdateSequenceNumbers object
Optional
blockHash: BlockHashan optional block hash to get the sequence numbers at, otherwise retrieves from last finalized block.
Get information about the node.
The NodeInfo
includes information of
ConsensusInfo
returned depends on if the node supports
the protocol on chain and whether the node is configured as a baker or not. const nodeInfo: NodeInfo = await client.getNodeInfo();
Info about the node
Retrieves information on the passive delegators.
From ./../examples/nodejs/client/getPassiveDelegationInfo.ts#45~52
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const passiveDelegationInfo: PassiveDelegationStatus = await client.getPassiveDelegationInfo(blockHash);
console.log('CCD provided by the delegators to the pool:', CcdAmount.toCcd(passiveDelegationInfo.delegatedCapital));
console.log('Total capital in CCD of ALL pools:', CcdAmount.toCcd(passiveDelegationInfo.allPoolTotalCapital));
console.log('Pool commision rates:', passiveDelegationInfo.commissionRates);
The status of the passive delegators.
Optional
blockHash: BlockHashthe block hash of the block to get the information from.
Get the registered passive delegators at the end of a given block.
In contrast to the GetPassiveDelegatorsRewardPeriod
which returns delegators
that are fixed for the reward period of the block, this endpoint returns the
list of delegators that are registered in the block. Any changes to delegators
are immediately visible in this list.
The stream will end when all the delegators has been returned.
From ./../examples/nodejs/client/getPassiveDelegators.ts#53~61
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const delegators: AsyncIterable<DelegatorInfo> = client.getPassiveDelegators(blockHash);
console.log('Each staking account and the amount of stake they have:\n');
for await (const delegatorInfo of delegators) {
console.log(delegatorInfo.account, delegatorInfo.stake);
}
a stream of DelegatorInfo
Optional
blockHash: BlockHashan optional block hash to get the delegators at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Get the fixed passive delegators for the reward period of the given block.
In contracts to the GetPassiveDelegators
which returns delegators registered
for the given block, this endpoint returns the fixed delegators contributing
stake in the reward period containing the given block.
The stream will end when all the delegators has been returned.
From ./../examples/nodejs/client/getPassiveDelegatorsRewardPeriod.ts#52~60
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const delegators: AsyncIterable<DelegatorRewardPeriodInfo> = client.getPassiveDelegatorsRewardPeriod(blockHash);
console.log('Each staking account and the amount of stake they have:\n');
for await (const delegatorInfo of delegators) {
console.log(delegatorInfo.account, delegatorInfo.stake);
}
a stream of DelegatorRewardPeriodInfo
Optional
blockHash: BlockHashan optional block hash to get the delegators at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Get the registered delegators of a given pool at the end of a given block.
In contrast to the GetPoolDelegatorsRewardPeriod
which returns delegators
that are fixed for the reward period of the block, this endpoint returns the
list of delegators that are registered in the block. Any changes to delegators
are immediately visible in this list.
The stream will end when all the delegators has been returned.
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const delegators: AsyncIterable<DelegatorInfo> = client.getPoolDelegators(BigInt(cli.flags.poolOwner), blockHash);
console.log('Each staking account and the amount of stake they have:\n');
for await (const delegatorInfo of delegators) {
console.log(delegatorInfo.account, delegatorInfo.stake);
}
a stream of DelegatorInfo
The BakerId of the pool owner
Optional
blockHash: BlockHashan optional block hash to get the delegators at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Get the fixed delegators of a given pool for the reward period of the given block.
In contracts to the GetPoolDelegators
which returns delegators registered
for the given block, this endpoint returns the fixed delegators contributing
stake in the reward period containing the given block.
The stream will end when all the delegators has been returned.
From ./../examples/nodejs/client/getPoolDelegatorsRewardPeriod.ts#60~71
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const delegators: AsyncIterable<DelegatorRewardPeriodInfo> = client.getPoolDelegatorsRewardPeriod(
BigInt(cli.flags.poolOwner),
blockHash
);
console.log('Each staking account and the amount of stake they have:\n');
for await (const delegatorInfo of delegators) {
console.log(delegatorInfo.account, delegatorInfo.stake);
}
a stream of DelegatorRewardPeriodInfo
The BakerId of the pool owner
Optional
blockHash: BlockHashan optional block hash to get the delegators at, otherwise retrieves from last finalized block.
Optional
abortSignal: AbortSignalan optional AbortSignal to close the stream.
Retrieves information on the baker pool of the given bakerId.
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const bakerPool: BakerPoolStatus = await client.getPoolInfo(BigInt(cli.flags.poolOwner), blockHash);
console.log('Open status:', bakerPool.poolInfo?.openStatus);
console.log('Baker address:', bakerPool.bakerAddress);
console.log(
'CCD provided by the baker to the pool:',
bakerPool.bakerEquityCapital !== undefined ? CcdAmount.toCcd(bakerPool.bakerEquityCapital) : undefined
);
console.log(
'CCD provided by the delegators to the pool:',
bakerPool.delegatedCapital !== undefined ? CcdAmount.toCcd(bakerPool.delegatedCapital) : undefined
);
console.log('Total capital in CCD of ALL pools:', CcdAmount.toCcd(bakerPool.allPoolTotalCapital));
console.log('Pool commision rates:', bakerPool.poolInfo?.commissionRates);
The status of the corresponding baker pool.
the ID of the baker to get the status for.
Optional
blockHash: BlockHashthe block hash of the block to get the information from.
Retrieves the reward status at the given blockHash
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const tokenomics = await client.getTokenomicsInfo(blockHash);
// Protocol version 4 expanded the amount of information in the response, so one should check the type to access that.
// This information includes information about the payday and total amount of funds staked.
if (tokenomics.version === 1) {
console.log('Next payday time:', tokenomics.nextPaydayTime);
console.log('Total staked amount by bakers and delegators', tokenomics.totalStakedCapital);
}
// While other information is in both V1 and V0
console.log('The amount in the baking reward account:', tokenomics.bakingRewardAccount);
console.log('Total amount in existence:', tokenomics.totalAmount);
the reward status at the given block, or undefined it the block does not exist.
Optional
blockHash: BlockHashoptional block hash to get the reward status at, otherwise retrieves from last finalized block
Get the list of bakers that won the lottery in a particular historical epoch (i.e. the last finalized block is in a later epoch). This lists the winners for each round in the epoch, starting from the round after the last block in the previous epoch, running to the round before the first block in the next epoch. It also indicates if a block in each round was included in the finalized chain.
The following error cases are possible:
a NOT_FOUND
RPC error if the query specifies an unknown block.
an UNAVAILABLE
RPC error if the query is for an epoch that is not finalized in the current genesis index, or is for a future genesis index.
an INVALID_ARGUMENT
RPC error if the query is for an epoch that is not finalized for a past genesis index.
an INVALID_ARGUMENT
RPC error if the query is for a genesis index at consensus version 0.
an INVALID_ARGUMENT
RPC error if the input EpochRequest
is malformed.
an UNAVAILABLE
RPC error if the endpoint is disabled on the node.
A stream of winning bakers for a given epoch.
Optional
epochRequest: BlockHash | RelativeEpochRequestConsists of either a block hash or a relative epoch request consisting of a genesis index and an epoch. If none is passed, it queries the last finalized block.
Queries the node to check its health
const check = await client.healthCheck();
if (check.isHealthy) {
console.log('The node is healthy!');
} else {
console.log('The node is not healthy');
console.log('Message: ' + check.message);
}
a HealthCheck indicating whether the node is healthy or not and provides the message from the client, if not healthy.
Get the value at a specific key of a contract state. In contrast to
GetInstanceState
this is more efficient, but requires the user to know
the specific key to look for.
From ./../examples/nodejs/client/instanceStateLookup.ts#60~65
const contract = ContractAddress.create(cli.flags.contract);
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const state: HexString = await client.instanceStateLookup(contract, cli.flags.key, blockHash);
the state of the contract at the given key as a hex string.
the contract to get the state of.
the key of the desired contract state.
Optional
blockHash: BlockHasha optional block hash to get the instance states at, otherwise retrieves from last finalized block.
Invokes a smart contract.
// Handle the optional arguments
const invoker = cli.flags.invoker ? AccountAddress.fromBase58(cli.flags.invoker) : undefined;
const amount = cli.flags.amount ? CcdAmount.fromMicroCcd(cli.flags.amount) : undefined;
const parameter = cli.flags.parameter ? Parameter.fromHexString(cli.flags.parameter) : undefined;
const energy = cli.flags.energy ? Energy.create(cli.flags.energy) : undefined;
const contract = ContractAddress.create(cli.flags.contract);
const context: ContractContext = {
// Required
method: ReceiveName.fromString(cli.flags.receive),
contract,
// Optional
invoker,
amount,
parameter,
energy,
};
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const result = await client.invokeContract(context, blockHash);
// We can inspect the result
if (result.tag === 'failure') {
console.log('Invoke was unsuccesful');
console.log('The reason the update failed:', result.reason);
} else if (result.tag === 'success') {
console.log('Invoke was succesful');
const returnValue = result.returnValue; // If the invoked method has return value
if (returnValue) {
console.log('The return value of the invoked method:', ReturnValue.toHexString(returnValue));
}
const events: ContractTraceEvent[] = result.events;
console.log('A list of effects that the update would have:');
console.dir(events, { depth: null, colors: true });
}
If the node was able to invoke, then a object describing the outcome is returned.
The outcome is determined by the tag
field, which is either success
or failure
.
The usedEnergy
field will always be present, and is the amount of NRG was used during the execution.
If the tag is success
, then an events
field is present, and it contains the events that would have been generated.
If invoking a V1 contract and it produces a return value, it will be present in the returnValue
field.
If the tag is failure
, then a reason
field is present, and it contains the reason the update would have been rejected.
If either the block does not exist, or then node fails to parse of any of the inputs, then undefined is returned.
Optional
blockHash: BlockHashthe block hash at which the contract should be invoked at. The contract is invoked in the state at the end of this block.
Suggest to a peer to connect to the submitted peer details. This, if successful, adds the peer to the list of given addresses. Otherwise return a GRPC error. Note. The peer might not be connected to instantly, in that case the node will try to establish the connection in near future. This function returns a GRPC status 'Ok' in this case.
await client.peerConnect(cli.flags.ip, cli.flags.port);
console.log('Successfully connected to peer');
The ip address to connect to. Must be a valid ip address.
The port to connect to. Must be between 0 and 65535.
Disconnect from the peer and remove them from the given addresses list if they are on it. Return if the request was processed successfully. Otherwise return a GRPC error.
await client.peerDisconnect(cli.flags.ip, cli.flags.port);
console.log('Successfully disconnected from peer');
The ip address to connect to. Must be a valid ip address.
The port to connect to. Must be between 0 and 65535.
Serializes and sends an account transaction to the node to be put in a block on the chain.
Note that a transaction can still fail even if it was accepted by the node. To keep track of the transaction use getTransactionStatus.
const walletFile = readFileSync(cli.flags.walletFile, 'utf8');
const walletExport = parseWallet(walletFile);
const sender = AccountAddress.fromBase58(walletExport.value.address);
const toAddress = AccountAddress.fromBase58(cli.flags.receiver);
const nextNonce: NextAccountNonce = await client.getNextAccountNonce(sender);
const header: AccountTransactionHeader = {
expiry: TransactionExpiry.futureMinutes(60),
nonce: nextNonce.nonce,
sender,
};
// Include memo if it is given otherwise don't
let simpleTransfer = undefined;
if (cli.flags.memo) {
simpleTransfer = {
amount: CcdAmount.fromMicroCcd(cli.flags.amount),
toAddress,
memo: new DataBlob(Buffer.from(cli.flags.memo, 'hex')),
};
} else {
simpleTransfer = {
amount: CcdAmount.fromMicroCcd(cli.flags.amount),
toAddress,
};
}
const accountTransaction: AccountTransaction = {
header: header,
payload: simpleTransfer,
type: AccountTransactionType.Transfer,
};
// Sign transaction
const signer = buildAccountSigner(walletExport);
const signature: AccountTransactionSignature = await signTransaction(accountTransaction, signer);
const transactionHash = await client.sendAccountTransaction(accountTransaction, signature);
const status = await client.waitForTransactionFinalization(transactionHash);
console.dir(status, { depth: null, colors: true });
The transaction hash as a hex-encoded string
the transaction to send to the node
the signatures on the signing digest of the transaction
Sends a credential deployment transaction, for creating a new account, to the node to be put in a block on the chain.
Note that a transaction can still fail even if it was accepted by the node. To keep track of the transaction use getTransactionStatus.
See this document for how this function can be used.
The transaction hash
the serialized payload, consisting of the v1.CredentialDeploymentTransaction
along with corresponding signatures. This can be serialized by utilizing the serializeCredentialDeploymentPayload
function.
the expiry of the transaction
Sends an account transaction, with an already serialized payload, to the node to be put in a block on the chain.
Note that a transaction can still fail even if it was accepted by the node. To keep track of the transaction use getTransactionStatus.
In general, ConcordiumGRPCClient.sendAccountTransaction is the recommended method to send account transactions, as this does not require the caller to serialize the payload themselves.
The transaction hash as a byte array
the transactionheader to send to the node
the amount of energy allotted for the transaction
the payload serialized to a buffer
the signatures on the signing digest of the transaction
Sends an update instruction transaction for updating a chain parameter to the node to be put in a block on the chain.
The transaction hash
the update instruction transaction to send to the node
map of the signatures on the hash of the serialized unsigned update instruction, with the key index as map key
Waits until given transaction is finalized.
const walletFile = readFileSync(cli.flags.walletFile, 'utf8');
const walletExport = parseWallet(walletFile);
const sender = AccountAddress.fromBase58(walletExport.value.address);
const toAddress = AccountAddress.fromBase58(cli.flags.receiver);
const nextNonce: NextAccountNonce = await client.getNextAccountNonce(sender);
const header: AccountTransactionHeader = {
expiry: TransactionExpiry.futureMinutes(60),
nonce: nextNonce.nonce,
sender,
};
// Include memo if it is given otherwise don't
let simpleTransfer = undefined;
if (cli.flags.memo) {
simpleTransfer = {
amount: CcdAmount.fromMicroCcd(cli.flags.amount),
toAddress,
memo: new DataBlob(Buffer.from(cli.flags.memo, 'hex')),
};
} else {
simpleTransfer = {
amount: CcdAmount.fromMicroCcd(cli.flags.amount),
toAddress,
};
}
const accountTransaction: AccountTransaction = {
header: header,
payload: simpleTransfer,
type: AccountTransactionType.Transfer,
};
// Sign transaction
const signer = buildAccountSigner(walletExport);
const signature: AccountTransactionSignature = await signTransaction(accountTransaction, signer);
const transactionHash = await client.sendAccountTransaction(accountTransaction, signature);
const status = await client.waitForTransactionFinalization(transactionHash);
console.dir(status, { depth: null, colors: true });
BlockItemSummary of the transaction.
a transaction hash as a bytearray.
Optional
timeoutTime: numberthe number of milliseconds until the function throws error.
Generated using TypeDoc
A concordium-node specific gRPC client wrapper. This will not work in a browser environment, in which case ConcordiumGRPCWebClient should be used instead.
Example