Class ConcordiumGRPCClient

A concordium-node specific gRPC client wrapper. Only use this if you intend to supply a custom transport layer. Otherwise more user-friendly options ConcordiumGRPCWebClient and ConcordiumGRPCNodeClient exist for web/nodejs use respectively.

Hierarchy

Constructors

Properties

client: QueriesClient
healthClient: HealthClient

Methods

  • 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.

    From ./../examples/nodejs/client/dumpStart.ts#60~63

        await client.dumpStart(cli.flags.filepath, cli.flags.dumpRaw);
    console.log('Dump successfully started');

    Parameters

    • filePath: string

      Which file to dump the packages into. Requires a valid path.

    • raw: boolean

      Whether the node should dump raw packages.

    Returns Promise<void>

  • 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.

    Returns

    The value returned from predicate at the lowest block (in terms of height) where the predicate holds.

    Type Parameters

    • R

    Parameters

    • predicate: ((bi: CommonBlockInfo) => Promise<undefined | R>)

      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: bigint

      An optional upper bound of the range of blocks to search. Defaults to latest finalized block.

    Returns Promise<undefined | R>

  • Find the first block finalized after a given time.

    Returns

    Information about the block found, or undefined if no block was found.

    Parameters

    • time: Date

      The time to find first block after

    • Optional from: bigint

      An optional lower bound of the range of blocks to search. Defaults to 0n.

    • Optional to: bigint

      An optional upper bound of the range of blocks to search. Defaults to latest finalized block.

    Returns Promise<undefined | BlockInfo>

  • Find the block where a smart contract instance was created. This is a specialized form of findEarliestFinalized.

    Returns

    Information about the block and the contract instance, or undefined if not found.

    Parameters

    • address: ContractAddress

      The contract address to search for.

    • Optional from: bigint

      An optional lower bound of the range of blocks to search. Defaults to 0n.

    • Optional to: bigint

      An optional upper bound of the range of blocks to search. Defaults to latest finalized block.

    Returns Promise<undefined | FindInstanceCreationReponse>

  • 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.

    From ./../examples/nodejs/client/getAccountInfo.ts#64~85

        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
    );
    }

    Returns

    the account info for the provided account address.

    Throws

    An error of type RpcError if not found in the block.

    Parameters

    • accountIdentifier: AccountIdentifierInput

      base58 account address, or a credential registration id or account index to get the account info for

    • Optional blockHash: BlockHash

      optional block hash to get the account info at, otherwise retrieves from last finalized block

    Returns Promise<AccountInfo>

  • Retrieve a stream of accounts that exist at the end of the given block.

    From ./../examples/nodejs/client/getAccountList.ts#51~58

        const blockHash =
    cli.flags.block === undefined
    ? undefined
    : BlockHash.fromHexString(cli.flags.block);
    const accounts: AsyncIterable<AccountAddress.Type> =
    client.getAccountList(blockHash);

    Returns

    an async iterable of account addresses.

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the accounts at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<AccountAddress>

  • 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#56~60

        const accountAddress = AccountAddress.fromBase58(cli.flags.account);
    const transactions: AsyncIterable<TransactionHash.Type> =
    client.getAccountNonFinalizedTransactions(accountAddress);

    Returns

    a stream of transaction hashes.

    Parameters

    • accountAddress: AccountAddress

      The address of the account that you wish to query.

    • Optional abortSignal: AbortSignal

    Returns AsyncIterable<TransactionHash>

  • Get 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.

    From ./../examples/nodejs/client/getAncestors.ts#61~70

        const blockHash =
    cli.flags.block === undefined
    ? undefined
    : BlockHash.fromHexString(cli.flags.block);
    const ancestors: AsyncIterable<BlockHash.Type> = client.getAncestors(
    BigInt(cli.flags.maxAncestors),
    blockHash
    );

    Returns

    an async iterable of ancestors' block hashes.

    Parameters

    • maxAmountOfAncestors: bigint

      the maximum amount of ancestors as a bigint.

    • Optional blockHash: BlockHash

      a optional block hash to get the ancestors at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<BlockHash>

  • 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#51~67

        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'
    );
    }

    Returns

    an async iterable of identity provider info objects.

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the anonymity revokers at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<ArInfo>

  • 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.

    Throws

    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).

    Returns

    The projected earliest time at which a particular baker will be required to bake a block, as a unix timestamp in milliseconds.

    Parameters

    • baker: bigint

      The baker that should be queried for.

    Returns Promise<Timestamp>

  • Get all the bakers at the end of the given block.

    From ./../examples/nodejs/client/getBakerList.ts#51~57

        const blockHash =
    cli.flags.block === undefined
    ? undefined
    : BlockHash.fromHexString(cli.flags.block);
    const bakerIds: AsyncIterable<BakerId> = client.getBakerList(blockHash);

    Returns

    an async iterable of BakerIds.

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the baker list at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<bigint>

  • Get all bakers in the reward period of a block. This endpoint is only supported for protocol version 6 and onwards.

    Throws

    an IllegalArgument RPC error if the protocol does not support the endpoint.

    Returns

    All bakers in the reward period of a block

    Parameters

    • Optional blockHash: BlockHash

      optional block hash to get the cryptographic parameters at, otherwise retrieves from last finalized block.

    Returns AsyncIterable<BakerRewardPeriodInfo>

  • For a non-genesis block, this returns the quorum certificate, a timeout certificate (if present) and epoch finalization entry (if present).

    Throws

    an UNIMPLEMENTED RPC error if the endpoint is not enabled by the node.

    Throws

    an INVALID_ARGUMENT if the block being pointed to is not a product of ConcordiumBFT

    Returns

    the requested block certificates.

    Parameters

    • Optional blockHash: BlockHash

      optional block hash to get the cryptographic parameters at, otherwise retrieves from last finalized block.

    Returns Promise<BlockCertificates>

  • Retrieves the status of the block chain parameters at the given blockHash.

    From ./../examples/nodejs/client/getBlockChainParameters.ts#47~69

        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'
    );
    }

    Returns

    Info on all of the block chain parameters.

    Parameters

    • Optional blockHash: BlockHash

      the block hash of the block to get the information from.

    Returns Promise<ChainParameters>

  • Get the summary of the finalization data in a given block.

    From ./../examples/nodejs/client/getBlockFinalizationSummary.ts#51~70

        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'
    );
    }

    Returns

    a finalization summary

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the finalization summaries at, otherwise retrieves from last finalized block.

    Returns Promise<BlockFinalizationSummary>

  • Get information, such as height, timings, and transaction counts for the given block.

    From ./../examples/nodejs/client/getBlockInfo.ts#48~54

        const blockHash =
    cli.flags.block === undefined
    ? undefined
    : BlockHash.fromHexString(cli.flags.block);
    const blockInfo: BlockInfo = await client.getBlockInfo(blockHash);

    Returns

    information on a block.

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the info from, otherwise retrieves from last finalized block.

    Returns Promise<BlockInfo>

  • Retrieves a status for the given transaction/block item.

    From ./../examples/nodejs/client/getBlockItemStatus.ts#59~124


    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);
    }
    }

    Returns

    the status for the given transaction/block item, or undefined if it does not exist.

    Parameters

    • transactionHash: TransactionHash

      the transaction/block item to get a status for.

    Returns Promise<BlockItemStatus>

  • 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#54~61

        const blockHash =
    cli.flags.block === undefined
    ? undefined
    : BlockHash.fromHexString(cli.flags.block);
    const pendingUpdates: AsyncIterable<PendingUpdate> =
    client.getBlockPendingUpdates(blockHash);

    Returns

    a stream of pending updates

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the pending updates at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<PendingUpdate>

  • 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#55~62

        const blockHash =
    cli.flags.block === undefined
    ? undefined
    : BlockHash.fromHexString(cli.flags.block);
    const events: AsyncIterable<BlockSpecialEvent> =
    client.getBlockSpecialEvents(blockHash);

    Returns

    a stream of block item summaries

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the special events at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<BlockSpecialEvent>

  • 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#53~60

        const blockHash =
    cli.flags.block === undefined
    ? undefined
    : BlockHash.fromHexString(cli.flags.block);
    const events: AsyncIterable<BlockItemSummary> =
    client.getBlockTransactionEvents(blockHash);

    Returns

    a stream of block item summaries

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the transaction events at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<BlockItemSummary>

  • Gets a stream of blocks. To get a stream of only finalized blocks use getFinalizedBlocks() instead.

    From ./../examples/nodejs/client/getBlocks.ts#43~52

        // 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');
    }

    Returns

    An AsyncIterator stream of blocks.

    Parameters

    • Optional abortSignal: AbortSignal

      an 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.

    Returns AsyncIterable<CommonBlockInfo>

  • Get the current branches of blocks starting from and including the last finalized block.

    From ./../examples/nodejs/client/getBranches.ts#43~49

        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 });

    Returns

    a branch with a block hash and a list of branch-children

    Returns Promise<Branch>

  • 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#48~55

        const blockHash =
    cli.flags.block === undefined
    ? undefined
    : BlockHash.fromHexString(cli.flags.block);
    const parameters: CryptographicParameters =
    await client.getCryptographicParameters(blockHash);

    Returns

    the global cryptographic parameters at the given block, or undefined it the block does not exist.

    Parameters

    • Optional blockHash: BlockHash

      optional block hash to get the cryptographic parameters at, otherwise retrieves from last finalized block.

    Returns Promise<CryptographicParameters>

  • Get information related to the baker election for a particular block.

    Returns

    election info for the given block

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the election info at, otherwise retrieves from last finalized block.

    Returns Promise<ElectionInfo>

  • Retrieves the embedded schema of the given module at the provided block.

    From ./../examples/nodejs/client/getEmbeddedSchema.ts#55~58

        const moduleRef = ModuleReference.fromHexString(cli.flags.module);
    const schema = await client.getEmbeddedSchema(moduleRef);

    Returns

    the module schema as a buffer.

    Throws

    An error of type RpcError if not found in the block.

    Throws

    If the module or schema cannot be parsed

    Parameters

    • moduleRef: ModuleReference

      the module's reference, represented by the ModuleReference class.

    • Optional blockHash: BlockHash

      optional block hash to get the module embedded schema at, otherwise retrieves from last finalized block

    Returns Promise<Uint8Array>

  • Gets a stream of finalized blocks.

    From ./../examples/nodejs/client/getFinalizedBlocks.ts#43~53

        // 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');
    }

    Returns

    An AsyncIterator stream of finalized blocks.

    Parameters

    • Optional abortSignal: AbortSignal

      an 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.

    Returns AsyncIterable<CommonBlockInfo>

  • Gets a stream of finalized blocks from specified startHeight.

    Returns

    A stream of v1.FinalizedBlockInfo.

    Parameters

    • Optional startHeight: bigint

      An optional height to start streaming blocks from. Defaults to 0n.

    • Optional abortSignal: AbortSignal

      An optional abort signal, which will end the stream. If this is not specified, the stream continues indefinitely.

    Returns AsyncIterable<CommonBlockInfo>

  • Gets a stream of finalized blocks from specified startHeight.

    Returns

    A stream of v1.FinalizedBlockInfo.

    Parameters

    • Optional startHeight: bigint

      An optional height to start streaming blocks from. Defaults to 0n.

    • Optional endHeight: bigint

      An optional height to stop streaming at. If this is not specified, the stream continues indefinitely.

    Returns AsyncIterable<CommonBlockInfo>

  • Get the block hash of the first finalized block in a specified epoch.

    The following error cases are possible:

    Throws

    • a NOT_FOUND RPC error if the query specifies an unknown block.

    Throws

    • 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.

    Throws

    • an INVALID_ARGUMENT RPC error if the query is for an epoch with no finalized blocks for a past genesis index.

    Throws

    • an INVALID_ARGUMENT RPC error if the input EpochRequest is malformed.

    Throws

    • an UNAVAILABLE RPC error if the endpoint is disabled on the node.

    Returns

    The block hash as a hex encoded string.

    Parameters

    • Optional epochRequest: BlockHash | RelativeEpochRequest

      Consists 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.

    Returns Promise<BlockHash>

  • 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#51~62

        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');
    }

    Returns

    an async iterable of identity provider info objects.

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the providers at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<IpInfo>

  • Retrieve information about a given smart contract instance.

    From ./../examples/nodejs/client/getInstanceInfo.ts#56~80

        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);
    }

    Returns

    An object with information about the contract instance.

    Throws

    An error of type RpcError if not found in the block.

    Parameters

    • contractAddress: ContractAddress

      the address of the smart contract.

    • Optional blockHash: BlockHash

      optional block hash to get the smart contact instances at, otherwise retrieves from last finalized block

    Returns Promise<InstanceInfo>

  • 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.

    From ./../examples/nodejs/client/getInstanceState.ts#64~74

        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
    );

    Returns

    an async iterable of instance states as key-value pairs of hex strings.

    Parameters

    • contractAddress: ContractAddress

      the contract to get the state of.

    • Optional blockHash: BlockHash

      a optional block hash to get the instance states at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<InstanceStateKVPair>

  • 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.

    From ./../examples/nodejs/client/getModuleList.ts#52~59

        const blockHash =
    cli.flags.block === undefined
    ? undefined
    : BlockHash.fromHexString(cli.flags.block);
    const moduleRefs: AsyncIterable<ModuleReference.Type> =
    client.getModuleList(blockHash);

    Returns

    an async iterable of contract module references.

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the contract modules at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<ModuleReference>

  • Retrieves the source of the given module at the provided block.

    From ./../examples/nodejs/client/getModuleSource.ts#63~70

        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);

    Returns

    the source of the module as raw bytes.

    Throws

    An error of type RpcError if not found in the block.

    Parameters

    • moduleRef: ModuleReference

      the module's reference, represented by the ModuleReference class.

    • Optional blockHash: BlockHash

      optional block hash to get the module source at, otherwise retrieves from last finalized block

    Returns Promise<VersionedModuleSource>

  • 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#54~62

        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);

    Returns

    the next account nonce, and a boolean indicating if the nonce is reliable.

    Parameters

    • accountAddress: AccountAddress

      base58 account address to get the next account nonce for.

    Returns Promise<NextAccountNonce>

  • Get information about the node. The NodeInfo includes information of

    • Meta information such as the, version of the node, type of the node, uptime and the local time of the node.
    • NetworkInfo which yields data such as the node id, packets sent/received, average bytes per second sent/received.
    • ConsensusInfo. The ConsensusInfo returned depends on if the node supports the protocol on chain and whether the node is configured as a baker or not.

    From ./../examples/nodejs/client/getNodeInfo.ts#55~57

        const nodeInfo: NodeInfo = await client.getNodeInfo();
    

    Returns

    Info about the node

    Returns Promise<NodeInfo>

  • Retrieves information on the passive delegators.

    From ./../examples/nodejs/client/getPassiveDelegationInfo.ts#53~70

        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);

    Returns

    The status of the passive delegators.

    Parameters

    • Optional blockHash: BlockHash

      the block hash of the block to get the information from.

    Returns Promise<PassiveDelegationStatus>

  • 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#57~69

        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);
    }

    Returns

    a stream of DelegatorInfo

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the delegators at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<DelegatorInfo>

  • 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#56~68

        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);
    }

    Returns

    a stream of DelegatorRewardPeriodInfo

    Parameters

    • Optional blockHash: BlockHash

      an optional block hash to get the delegators at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<DelegatorInfoCommon>

  • 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.

    From ./../examples/nodejs/client/getPoolDelegators.ts#65~79

        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);
    }

    Returns

    a stream of DelegatorInfo

    Parameters

    • baker: bigint

      The BakerId of the pool owner

    • Optional blockHash: BlockHash

      an optional block hash to get the delegators at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<DelegatorInfo>

  • 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#64~79

        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);
    }

    Returns

    a stream of DelegatorRewardPeriodInfo

    Parameters

    • baker: bigint

      The BakerId of the pool owner

    • Optional blockHash: BlockHash

      an optional block hash to get the delegators at, otherwise retrieves from last finalized block.

    • Optional abortSignal: AbortSignal

      an optional AbortSignal to close the stream.

    Returns AsyncIterable<DelegatorInfoCommon>

  • Retrieves information on the baker pool of the given bakerId.

    From ./../examples/nodejs/client/getPoolInfo.ts#56~81

        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:',
    CcdAmount.toCcd(bakerPool.bakerEquityCapital)
    );
    console.log(
    'CCD provided by the delegators to the pool:',
    CcdAmount.toCcd(bakerPool.delegatedCapital)
    );
    console.log(
    'Total capital in CCD of ALL pools:',
    CcdAmount.toCcd(bakerPool.allPoolTotalCapital)
    );
    console.log('Pool commision rates:', bakerPool.poolInfo.commissionRates);

    Returns

    The status of the corresponding baker pool.

    Parameters

    • bakerId: bigint

      the ID of the baker to get the status for.

    • Optional blockHash: BlockHash

      the block hash of the block to get the information from.

    Returns Promise<BakerPoolStatus>

  • Retrieves the reward status at the given blockHash

    From ./../examples/nodejs/client/getTokenomicsInfo.ts#56~79

        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);

    Returns

    the reward status at the given block, or undefined it the block does not exist.

    Parameters

    • Optional blockHash: BlockHash

      optional block hash to get the reward status at, otherwise retrieves from last finalized block

    Returns Promise<RewardStatus>

  • 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:

    Throws

    a NOT_FOUND RPC error if the query specifies an unknown block.

    Throws

    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.

    Throws

    an INVALID_ARGUMENT RPC error if the query is for an epoch that is not finalized for a past genesis index.

    Throws

    an INVALID_ARGUMENT RPC error if the query is for a genesis index at consensus version 0.

    Throws

    an INVALID_ARGUMENT RPC error if the input EpochRequest is malformed.

    Throws

    an UNAVAILABLE RPC error if the endpoint is disabled on the node.

    Returns

    A stream of winning bakers for a given epoch.

    Parameters

    • Optional epochRequest: BlockHash | RelativeEpochRequest

      Consists 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.

    Returns AsyncIterable<WinningBaker>

  • 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#64~76

        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
    );

    Returns

    the state of the contract at the given key as a hex string.

    Parameters

    • contractAddress: ContractAddress

      the contract to get the state of.

    • key: string

      the key of the desired contract state.

    • Optional blockHash: BlockHash

      a optional block hash to get the instance states at, otherwise retrieves from last finalized block.

    Returns Promise<string>

  • Invokes a smart contract.

    From ./../examples/nodejs/client/invokeContract.ts#97~149

        // 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 });
    }

    Returns

    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.

    Parameters

    • context: ContractContext
    • Optional blockHash: BlockHash

      the block hash at which the contract should be invoked at. The contract is invoked in the state at the end of this block.

    Returns Promise<InvokeContractResult>

  • 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.

    From ./../examples/nodejs/client/peerConnect.ts#58~61

        await client.peerConnect(cli.flags.ip, cli.flags.port);
    console.log('Successfully connected to peer');

    Parameters

    • ip: string

      The ip address to connect to. Must be a valid ip address.

    • port: number

      The port to connect to. Must be between 0 and 65535.

    Returns Promise<void>

  • 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.

    From ./../examples/nodejs/client/peerDisconnect.ts#57~60

        await client.peerDisconnect(cli.flags.ip, cli.flags.port);
    console.log('Successfully disconnected from peer');

    Parameters

    • ip: string

      The ip address to connect to. Must be a valid ip address.

    • port: number

      The port to connect to. Must be between 0 and 65535.

    Returns Promise<void>

  • 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.

    From ./../examples/nodejs/common/simpleTransfer.ts#81~134

        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 });

    Returns

    The transaction hash as a hex-encoded string

    Parameters

    Returns Promise<TransactionHash>

  • 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.

    Returns

    The transaction hash

    Parameters

    • rawPayload: Uint8Array

      the serialized payload, consisting of the v1.CredentialDeploymentTransaction along with corresponding signatures. This can be serialized by utilizing the serializeCredentialDeploymentPayload function.

    • expiry: TransactionExpiry

      the expiry of the transaction

    Returns Promise<TransactionHash>

  • 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, sendAccountTransaction is the recommended method to send account transactions, as this does not require the caller to serialize the payload themselves.

    Returns

    The transaction hash as a byte array

    Parameters

    • header: AccountTransactionHeader

      the transactionheader to send to the node

    • energyAmount: Energy

      the amount of energy allotted for the transaction

    • payload: Uint8Array

      the payload serialized to a buffer

    • signature: AccountTransactionSignature

      the signatures on the signing digest of the transaction

    Returns Promise<TransactionHash>

  • Sends an update instruction transaction for updating a chain parameter to the node to be put in a block on the chain.

    Returns

    The transaction hash

    Parameters

    • updateInstructionTransaction: UpdateInstruction

      the update instruction transaction to send to the node

    • signatures: Record<number, string>

      map of the signatures on the hash of the serialized unsigned update instruction, with the key index as map key

    Returns Promise<TransactionHash>

  • Waits until given transaction is finalized.

    From ./../examples/nodejs/common/simpleTransfer.ts#81~134

        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 });

    Returns

    BlockItemSummary of the transaction.

    Parameters

    • transactionHash: TransactionHash

      a transaction hash as a bytearray.

    • Optional timeoutTime: number

      the number of milliseconds until the function throws error.

    Returns Promise<BlockItemSummaryInBlock>

Generated using TypeDoc