Skip to main content

Class: Client

The Client to interact with nodes.

Table of contents

Constructors

Methods

Constructors

constructor

new Client(options)

Parameters

NameTypeDescription
optionsClientMethodHandler | IClientOptionsclient options or a client method handler.

Methods

destroy

destroy(): Promise<any>

Returns

Promise<any>


getInfo

getInfo(): Promise<INodeInfoWrapper>

Get the node information together with the url of the used node.

Returns

Promise<INodeInfoWrapper>


getNetworkInfo

getNetworkInfo(): Promise<INetworkInfo>

Get network related information such as protocol parameters and minimum pow score.

Returns

Promise<INetworkInfo>


basicOutputIds

basicOutputIds(queryParameters): Promise<IOutputsResponse>

Fetch basic output IDs based on the given query parameters.

Parameters

NameType
queryParametersQueryParameter[]

Returns

Promise<IOutputsResponse>


getOutput

getOutput(outputId): Promise<OutputResponse>

Get output from a given output ID.

Parameters

NameType
outputIdstring

Returns

Promise<OutputResponse>


getOutputs

getOutputs(outputIds): Promise<OutputResponse[]>

Fetch OutputResponse from given output IDs. Requests are sent in parallel.

Parameters

NameType
outputIdsstring[]

Returns

Promise<OutputResponse[]>


buildAndPostBlock

buildAndPostBlock(secretManager?, options?): Promise<[string, Block]>

Build and post a block.

Parameters

NameTypeDescription
secretManager?SecretManagerTypeOne of the supported secret managers.
options?IBuildBlockOptionsOptions on how to build a block.

Returns

Promise<[string, Block]>

The block ID and the posted block itself.


getTips

getTips(): Promise<string[]>

Request tips from the node. The tips can be considered as non-lazy and are therefore ideal for attaching a block to the Tangle.

Returns

Promise<string[]>

An array of tips represented by their block IDs.


postBlock

postBlock(block): Promise<string>

Post a block in JSON format.

Parameters

NameTypeDescription
blockBlockThe block to post.

Returns

Promise<string>

The block ID once the block has been posted.


getBlock

getBlock(blockId): Promise<Block>

Get a block in JSON format.

Parameters

NameTypeDescription
blockIdstringThe corresponding block ID of the requested block.

Returns

Promise<Block>

The requested block.


getBlockMetadata

getBlockMetadata(blockId): Promise<IBlockMetadata>

Get the metadata of a block.

Parameters

NameTypeDescription
blockIdstringThe corresponding block ID of the requested block metadata.

Returns

Promise<IBlockMetadata>

The requested block metadata.


findInputs

findInputs(addresses, amount): Promise<UTXOInput[]>

Find inputs from addresses for a given amount (useful for offline signing).

Parameters

NameTypeDescription
addressesstring[]A list of included addresses.
amountbigintThe amount to find inputs for.

Returns

Promise<UTXOInput[]>

An array of UTXO inputs.


prepareTransaction

prepareTransaction(secretManager?, options?): Promise<PreparedTransactionData>

Prepare a transaction for signing.

Parameters

NameTypeDescription
secretManager?SecretManagerTypeOne of the supported secret managers.
options?IBuildBlockOptionsOptions to build a block.

Returns

Promise<PreparedTransactionData>

An instance of PreparedTransactionData.


signTransaction

signTransaction(secretManager, preparedTransactionData): Promise<TransactionPayload>

Sign a transaction.

Parameters

NameTypeDescription
secretManagerSecretManagerTypeOne of the supported secret managers.
preparedTransactionDataPreparedTransactionDataAn instance of PreparedTransactionData.

Returns

Promise<TransactionPayload>

The corresponding transaction payload.


signatureUnlock

signatureUnlock(secretManager, transactionEssenceHash, chain): Promise<UnlockCondition>

Create a signature unlock using the given secret manager.

Parameters

NameTypeDescription
secretManagerSecretManagerTypeOne of the supported secret managers.
transactionEssenceHashstringThe hash of the transaction essence.
chainBip44A BIP44 chain

Returns

Promise<UnlockCondition>

The corresponding unlock condition.


postBlockPayload

postBlockPayload(payload): Promise<[string, Block]>

Submit a payload in a block.

Parameters

NameTypeDescription
payloadPayloadThe payload to post.

Returns

Promise<[string, Block]>

The block ID followed by the block containing the payload.


getNode

getNode(): Promise<INode>

Get a node candidate from the healthy node pool.

Returns

Promise<INode>


getNetworkId

getNetworkId(): Promise<string>

Get the ID of the network the node is connected to.

Returns

Promise<string>


getBech32Hrp

getBech32Hrp(): Promise<string>

Get the Bech32 HRP (human readable part) of the network the node is connected to.

Returns

Promise<string>


getMinPowScore

getMinPowScore(): Promise<number>

Get the minimum PoW score.

Returns

Promise<number>


getTipsInterval

getTipsInterval(): Promise<number>

Get the tips interval.

Returns

Promise<number>


getTokenSupply

getTokenSupply(): Promise<string>

Get the token supply.

Returns

Promise<string>


getProtocolParameters

getProtocolParameters(): Promise<INodeInfoProtocol>

Get the protocol parameters.

Returns

Promise<INodeInfoProtocol>


getLocalPow

getLocalPow(): Promise<boolean>

Check whether local pow should be used or not.

Returns

Promise<boolean>


getFallbackToLocalPow

getFallbackToLocalPow(): Promise<boolean>

Check whether to fallback to local proof of work in case the node doesn't support remote PoW.

Returns

Promise<boolean>


getHealth

getHealth(url): Promise<boolean>

Get the health of a node.

Parameters

NameTypeDescription
urlstringThe URL of the node.

Returns

Promise<boolean>


getNodeInfo

getNodeInfo(url, auth?): Promise<INodeInfo>

Get the info about the node.

Parameters

NameTypeDescription
urlstringThe URL of the node.
auth?IAuthAn authentication object (e.g. JWT).

Returns

Promise<INodeInfo>


getPeers

getPeers(): Promise<IPeer[]>

Get the peers of the node.

Returns

Promise<IPeer[]>


postBlockRaw

postBlockRaw(block): Promise<string>

Post block as raw bytes, returns the block ID.

Parameters

NameTypeDescription
blockBlockThe block.

Returns

Promise<string>

The ID of the posted block.


getBlockRaw

getBlockRaw(blockId): Promise<Uint8Array>

Get block as raw bytes.

Parameters

NameTypeDescription
blockIdstringThe block ID of the requested block.

Returns

Promise<Uint8Array>

The raw bytes of the requested block.


getMilestoneById

getMilestoneById(milestoneId): Promise<MilestonePayload>

Get a milestone payload by its ID.

Parameters

NameTypeDescription
milestoneIdstringThe ID of the requested milestone.

Returns

Promise<MilestonePayload>

The corresponding milestone payload.


getUtxoChangesById

getUtxoChangesById(milestoneId): Promise<IMilestoneUtxoChangesResponse>

Get all UTXO changes of a milestone by its ID.

Parameters

NameTypeDescription
milestoneIdstringThe ID of the milestone that applied the UTXO changes.

Returns

Promise<IMilestoneUtxoChangesResponse>

A milestone UTXO changes response.


getMilestoneByIndex

getMilestoneByIndex(index): Promise<MilestonePayload>

Get a milestone payload by its index.

Parameters

NameTypeDescription
indexnumberThe index of the requested milestone.

Returns

Promise<MilestonePayload>

The corresponding milestone payload.


getUtxoChangesByIndex

getUtxoChangesByIndex(index): Promise<IMilestoneUtxoChangesResponse>

Get all UTXO changes of a milestone by its index.

Parameters

NameTypeDescription
indexnumberThe index of the milestone that applied the UTXO changes.

Returns

Promise<IMilestoneUtxoChangesResponse>

A milestone UTXO changes response.


getReceipts

getReceipts(): Promise<ReceiptsResponse>

Get all receipts.

Returns

Promise<ReceiptsResponse>


getReceiptsMigratedAt

getReceiptsMigratedAt(milestoneIndex): Promise<ReceiptsResponse[]>

Get the receipts at a given milestone index.

Parameters

NameTypeDescription
milestoneIndexnumberThe index of the milestone that migrated funds to the new network.

Returns

Promise<ReceiptsResponse[]>


getTreasury

getTreasury(): Promise<TreasuryOutput>

Get the treasury output.

Returns

Promise<TreasuryOutput>


getIncludedBlock

getIncludedBlock(transactionId): Promise<Block>

Get the included block of a given transaction.

Parameters

NameTypeDescription
transactionIdstringThe ID of the transaction.

Returns

Promise<Block>

The included block that contained the transaction.


getIncludedBlockMetadata

getIncludedBlockMetadata(transactionId): Promise<Block>

Get the metadata of the included block of a given transaction.

Parameters

NameTypeDescription
transactionIdstringThe ID of the transaction.

Returns

Promise<Block>

The included block that contained the transaction.


hexToBech32

hexToBech32(hex, bech32Hrp?): Promise<string>

Convert a hex encoded address to a Bech32 encoded address.

Parameters

NameTypeDescription
hexstringThe hexadecimal string representation of an address.
bech32Hrp?stringThe Bech32 HRP (human readable part) to be used.

Returns

Promise<string>

The corresponding Bech32 address.


aliasIdToBech32

aliasIdToBech32(aliasId, bech32Hrp?): Promise<string>

Convert an Alias ID to a Bech32 encoded address.

Parameters

NameTypeDescription
aliasIdstringAn Alias ID.
bech32Hrp?stringThe Bech32 HRP (human readable part) to be used.

Returns

Promise<string>

The corresponding Bech32 address.


nftIdToBech32

nftIdToBech32(nftId, bech32Hrp?): Promise<string>

Convert an NFT ID to a Bech32 encoded address.

Parameters

NameTypeDescription
nftIdstringAn NFT ID.
bech32Hrp?stringThe Bech32 HRP (human readable part) to be used.

Returns

Promise<string>

The corresponding Bech32 address.


hexPublicKeyToBech32Address

hexPublicKeyToBech32Address(hex, bech32Hrp?): Promise<string>

Convert a hex encoded public key to a Bech32 encoded address.

Parameters

NameTypeDescription
hexstringThe hexadecimal string representation of a public key.
bech32Hrp?stringThe Bech32 HRP (human readable part) to be used.

Returns

Promise<string>

The corresponding Bech32 address.


aliasOutputIds

aliasOutputIds(queryParameters): Promise<IOutputsResponse>

Get the corresponding output IDs given a list of Alias query parameters.

Parameters

NameTypeDescription
queryParametersAliasQueryParameter[]An array of AliasQueryParameters.

Returns

Promise<IOutputsResponse>

A paginated query response of corresponding output IDs.


aliasOutputId

aliasOutputId(aliasId): Promise<string>

Get the corresponding output ID from an Alias ID.

Parameters

NameTypeDescription
aliasIdstringAn Alias ID.

Returns

Promise<string>

The corresponding output ID.


nftOutputIds

nftOutputIds(queryParameters): Promise<IOutputsResponse>

Get the corresponding output IDs given a list of NFT query parameters.

Parameters

NameTypeDescription
queryParametersNftQueryParameter[]An array of NftQueryParameters.

Returns

Promise<IOutputsResponse>

A paginated query response of corresponding output IDs.


nftOutputId

nftOutputId(nftId): Promise<string>

Get the corresponding output ID from an NFT ID.

Parameters

NameTypeDescription
nftIdstringAn NFT ID.

Returns

Promise<string>

The corresponding output ID.


foundryOutputIds

foundryOutputIds(queryParameters): Promise<IOutputsResponse>

Get the corresponding output IDs given a list of Foundry query parameters.

Parameters

NameTypeDescription
queryParametersFoundryQueryParameter[]An array of FoundryQueryParameters.

Returns

Promise<IOutputsResponse>

A paginated query response of corresponding output IDs.


foundryOutputId

foundryOutputId(foundryId): Promise<string>

Get the corresponding output ID from a Foundry ID.

Parameters

NameTypeDescription
foundryIdstringA Foundry ID.

Returns

Promise<string>

The corresponding output ID.


getOutputsIgnoreErrors

getOutputsIgnoreErrors(outputIds): Promise<OutputResponse[]>

Get outputs from provided output IDs (requests are sent in parallel and errors are ignored, can be useful for spent outputs)

Parameters

NameTypeDescription
outputIdsstring[]An array of output IDs.

Returns

Promise<OutputResponse[]>

An array of corresponding output responses.


findBlocks

findBlocks(blockIds): Promise<Block[]>

Find blocks by their IDs.

Parameters

NameTypeDescription
blockIdsstring[]An array of BlockIds.

Returns

Promise<Block[]>

An array of corresponding blocks.


retry

retry(blockId): Promise<[string, Block]>

Retry (promote or reattach) a block given its block ID.

Note: Blocks should be retried only if they are valid and haven't been confirmed for some time.

Parameters

NameTypeDescription
blockIdstringThe ID of the block to retry.

Returns

Promise<[string, Block]>

The included block.


retryUntilIncluded

retryUntilIncluded(blockId, interval?, maxAttempts?): Promise<[string, Block][]>

Retry (promote or reattach) a block given its block ID until it's included (i.e. referenced by a milestone).

Parameters

NameTypeDescription
blockIdstringThe ID of the block to retry.
interval?numberA retry interval in seconds. Defaults to 5.
maxAttempts?numberA maximum number of retries. Defaults to 40.

Returns

Promise<[string, Block][]>

The included block at first position and additional reattached blocks.


consolidateFunds

consolidateFunds(secretManager, generateAddressesOptions): Promise<string>

Consolidate all funds from a range of addresses to the address with the lowest index in that range.

Parameters

NameTypeDescription
secretManagerSecretManagerTypeOne of supported secret managers.
generateAddressesOptionsIGenerateAddressesOptionsOptions for generating addresses.

Returns

Promise<string>

The address to which the funds got consolidated, if any were available.


reattach

reattach(blockId): Promise<[string, Block]>

Reattach a block.

Note: Blocks can be reattached only if they are valid and haven't been confirmed for some time.

Parameters

NameTypeDescription
blockIdstringThe ID of the block to reattach.

Returns

Promise<[string, Block]>

The included block.


reattachUnchecked

reattachUnchecked(blockId): Promise<[string, Block]>

Reattach a block without checking whether it should be reattached.

Parameters

NameTypeDescription
blockIdstringThe ID of the block to reattach.

Returns

Promise<[string, Block]>

The included block.


promote

promote(blockId): Promise<[string, Block]>

Promote a block.

NOTE: The method validates whether a promotion is necessary through get_block. If not, the method will error out and will not do unnecessary promotions.

Parameters

NameTypeDescription
blockIdstringThe ID of the block to promote.

Returns

Promise<[string, Block]>

The included block.


promoteUnchecked

promoteUnchecked(blockId): Promise<[string, Block]>

Promote a block without checking if it should be promoted.

Parameters

NameTypeDescription
blockIdstringThe ID of the block to promote.

Returns

Promise<[string, Block]>

The included block.


unhealthyNodes

unhealthyNodes(): Promise<Set<INode>>

Return the unhealthy nodes.

Returns

Promise<Set<INode>>


buildBasicOutput

buildBasicOutput(params): Promise<BasicOutput>

Build a basic output.

Parameters

NameTypeDescription
paramsBasicOutputBuilderParamsAn instance of BasicOutputBuilderParams.

Returns

Promise<BasicOutput>


buildAliasOutput

buildAliasOutput(params): Promise<AliasOutput>

Build an alias output.

Parameters

NameTypeDescription
paramsAliasOutputBuilderParamsAn instance of AliasOutputBuilderParams.

Returns

Promise<AliasOutput>


buildFoundryOutput

buildFoundryOutput(params): Promise<FoundryOutput>

Build a foundry output.

Parameters

NameTypeDescription
paramsFoundryOutputBuilderParamsAn instance of FoundryOutputBuilderParams.

Returns

Promise<FoundryOutput>


buildNftOutput

buildNftOutput(params): Promise<NftOutput>

Build an NFT output.

Parameters

NameTypeDescription
paramsNftOutputBuilderParamsAn instance of NftOutputBuilderParams.

Returns

Promise<NftOutput>


listenMqtt

listenMqtt(topics, callback): Promise<void>

Listen to MQTT events.

Parameters

NameTypeDescription
topicsstring[]An array of MQTT topics to listen to.
callback(error: Error, result: string) => void-

Returns

Promise<void>


clearMqttListeners

clearMqttListeners(topics): Promise<void>

Stop listening to certain MQTT events.

Parameters

NameTypeDescription
topicsstring[]An array of MQTT topics to stop listening to.

Returns

Promise<void>


minimumRequiredStorageDeposit

minimumRequiredStorageDeposit(output): Promise<number>

Calculate the minimum required storage deposit for an output.

Parameters

NameTypeDescription
outputOutputThe output to calculate the minimum deposit amount for.

Returns

Promise<number>

The minimum required amount.


requestFundsFromFaucet

requestFundsFromFaucet(url, address): Promise<string>

Request funds from a faucet.

Example URLs: https://faucet.testnet.shimmer.network/api/enqueue or http://localhost:8091/api/enqueue.

Parameters

NameTypeDescription
urlstringThe URL of the faucet.
addressstringThe address to send the funds to.

Returns

Promise<string>

The faucet response.


callPluginRoute

callPluginRoute(basePluginPath, method, endpoint, queryParams?, request?): Promise<string>

Extension method which provides request methods for plugins.

Parameters

NameTypeDescription
basePluginPathstringThe base path for the plugin eg indexer/v1/ .
method"GET" | "POST"The http method.
endpointstringThe path for the plugin request.
queryParams?string[]Additional query params for the request.
request?stringThe request object.

Returns

Promise<string>

The response json.