Skip to main content

Class: Client

The Client to interact with nodes.

Table of contents

Methods

Methods

getInfo

getInfo(): Promise<INodeInfoWrapper>

Returns the node information together with the url of the used node

Returns

Promise<INodeInfoWrapper>

.


getNetworkInfo

getNetworkInfo(): Promise<INetworkInfo>

Gets the network related information such as network_id and min_pow_score

Returns

Promise<INetworkInfo>


basicOutputIds

basicOutputIds(queryParameters): Promise<OutputIdsResponse>

Fetch basic output IDs based on query parameters

Parameters

NameType
queryParametersQueryParameter[]

Returns

Promise<OutputIdsResponse>


getOutput

getOutput(outputId): Promise<IOutputResponse>

Get output from a known outputID

Parameters

NameType
outputIdstring

Returns

Promise<IOutputResponse>


getOutputs

getOutputs(outputIds): Promise<IOutputResponse[]>

Fetch OutputResponse from provided OutputIds (requests are sent in parallel)

Parameters

NameType
outputIdsstring[]

Returns

Promise<IOutputResponse[]>


generateEd25519Addresses

generateEd25519Addresses(secretManager, generateAddressesOptions): Promise<string[]>

Generate addresses

Parameters

NameType
secretManagerSecretManagerType
generateAddressesOptionsIGenerateAddressesOptions

Returns

Promise<string[]>


buildAndPostBlock

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

Build and post a block

Parameters

NameType
secretManager?SecretManagerType
options?IBuildBlockOptions

Returns

Promise<[string, IBlock]>


getTips

getTips(): Promise<string[]>

Returns tips that are ideal for attaching a block. The tips can be considered as non-lazy and are therefore ideal for attaching a block.

Returns

Promise<string[]>


postBlock

postBlock(block): Promise<string>

Post block in JSON format, returns the block ID.

Parameters

NameType
blockIBlock

Returns

Promise<string>


getBlock

getBlock(blockId): Promise<IBlock>

Get block as JSON.

Parameters

NameType
blockIdstring

Returns

Promise<IBlock>


getBlockMetadata

getBlockMetadata(blockId): Promise<IBlockMetadata>

Get block metadata.

Parameters

NameType
blockIdstring

Returns

Promise<IBlockMetadata>


findInputs

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

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

Parameters

NameType
addressesstring[]
amountnumber

Returns

Promise<IUTXOInput[]>


findOutputs

findOutputs(outputIds, addresses): Promise<IOutputResponse[]>

Find all outputs based on the requests criteria. This method will try to query multiple nodes if the request amount exceeds individual node limit.

Parameters

NameType
outputIdsstring[]
addressesstring[]

Returns

Promise<IOutputResponse[]>


prepareTransaction

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

Prepare a transaction for signing

Parameters

NameType
secretManager?SecretManagerType
options?IBuildBlockOptions

Returns

Promise<IPreparedTransactionData>


signTransaction

signTransaction(secretManager, preparedTransactionData): Promise<PayloadTypes>

Sign a transaction

Parameters

NameType
secretManagerSecretManagerType
preparedTransactionDataIPreparedTransactionData

Returns

Promise<PayloadTypes>


signatureUnlock

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

Create a signature unlock using the provided secretManager.

Parameters

NameType
secretManagerSecretManagerType
transactionEssenceHashstring
chainIBip32Chain

Returns

Promise<UnlockTypes>


postBlockPayload

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

Submit a payload in a block

Parameters

NameType
payloadPayloadTypes

Returns

Promise<[string, IBlock]>


getNode

getNode(): Promise<INode>

Get a node candidate from the healthy node pool.

Returns

Promise<INode>


getNetworkId

getNetworkId(): Promise<number>

Get the network id of the node we're connecting to.

Returns

Promise<number>


getBech32Hrp

getBech32Hrp(): Promise<string>

Returns the bech32_hrp.

Returns

Promise<string>


getMinPowScore

getMinPowScore(): Promise<number>

Returns the min PoW score.

Returns

Promise<number>


getTipsInterval

getTipsInterval(): Promise<number>

Returns the tips interval.

Returns

Promise<number>


getTokenSupply

getTokenSupply(): Promise<string>

Returns the token supply.

Returns

Promise<string>


getProtocolParameters

getProtocolParameters(): Promise<INodeInfoProtocol>

Returns the protocol parameters.

Returns

Promise<INodeInfoProtocol>


getLocalPow

getLocalPow(): Promise<boolean>

Returns if local pow should be used or not.

Returns

Promise<boolean>


getFallbackToLocalPow

getFallbackToLocalPow(): Promise<boolean>

Get fallback to local proof of work timeout.

Returns

Promise<boolean>


getHealth

getHealth(url): Promise<boolean>

Get health of node by input url.

Parameters

NameType
urlstring

Returns

Promise<boolean>


getNodeInfo

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

Get info of node with input url.

Parameters

NameType
urlstring
auth?IAuth

Returns

Promise<INodeInfo>


getPeers

getPeers(): Promise<IPeer[]>

Get peers.

Returns

Promise<IPeer[]>


postBlockRaw

postBlockRaw(block): Promise<string>

Post block as raw bytes, returns the block ID.

Parameters

NameType
blockIBlock

Returns

Promise<string>


getBlockRaw

getBlockRaw(blockId): Promise<Uint8Array>

Get block as raw bytes.

Parameters

NameType
blockIdstring

Returns

Promise<Uint8Array>


getMilestoneById

getMilestoneById(milestoneId): Promise<IMilestonePayload>

Look up a milestone by a given milestone index.

Parameters

NameType
milestoneIdstring

Returns

Promise<IMilestonePayload>


getUtxoChangesById

getUtxoChangesById(milestoneId): Promise<IMilestoneUtxoChangesResponse>

Returns all UTXO changes that happened at a specific milestone.

Parameters

NameType
milestoneIdstring

Returns

Promise<IMilestoneUtxoChangesResponse>


getMilestoneByIndex

getMilestoneByIndex(index): Promise<IMilestonePayload>

Look up a milestone by a given milestone index.

Parameters

NameType
indexnumber

Returns

Promise<IMilestonePayload>


getUtxoChangesByIndex

getUtxoChangesByIndex(index): Promise<IMilestoneUtxoChangesResponse>

Returns all UTXO changes that happened at a specific milestone.

Parameters

NameType
indexnumber

Returns

Promise<IMilestoneUtxoChangesResponse>


getReceipts

getReceipts(): Promise<IReceiptsResponse>

Get receipts.

Returns

Promise<IReceiptsResponse>


getReceiptsMigratedAt

getReceiptsMigratedAt(milestoneIndex): Promise<IReceiptsResponse[]>

Get the receipts by the given milestone index.

Parameters

NameType
milestoneIndexnumber

Returns

Promise<IReceiptsResponse[]>


getTreasury

getTreasury(): Promise<ITreasury>

Get the treasury output.

Returns

Promise<ITreasury>


getIncludedBlock

getIncludedBlock(transactionId): Promise<IBlock>

Returns the included block of the transaction.

Parameters

NameType
transactionIdstring

Returns

Promise<IBlock>


getIncludedBlockMetadata

getIncludedBlockMetadata(transactionId): Promise<IBlock>

Returns the metadata of the included block of the transaction.

Parameters

NameType
transactionIdstring

Returns

Promise<IBlock>


hexToBech32

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

Transforms a hex encoded address to a bech32 encoded address.

Parameters

NameType
hexstring
bech32Hrp?string

Returns

Promise<string>


aliasIdToBech32

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

Transforms an alias id to a bech32 encoded address.

Parameters

NameType
aliasIdstring
bech32Hrp?string

Returns

Promise<string>


nftIdToBech32

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

Transforms an nft id to a bech32 encoded address.

Parameters

NameType
nftIdstring
bech32Hrp?string

Returns

Promise<string>


hexPublicKeyToBech32Address

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

Transforms a hex encoded public key to a bech32 encoded address.

Parameters

NameType
hexstring
bech32Hrp?string

Returns

Promise<string>


aliasOutputIds

aliasOutputIds(queryParameters): Promise<OutputIdsResponse>

Fetch alias output IDs

Parameters

NameType
queryParametersAliasQueryParameter[]

Returns

Promise<OutputIdsResponse>


aliasOutputId

aliasOutputId(aliasId): Promise<string>

Fetch alias output ID

Parameters

NameType
aliasIdstring

Returns

Promise<string>


nftOutputIds

nftOutputIds(queryParameters): Promise<OutputIdsResponse>

Fetch NFT output IDs

Parameters

NameType
queryParametersNftQueryParameter[]

Returns

Promise<OutputIdsResponse>


nftOutputId

nftOutputId(nftId): Promise<string>

Fetch NFT output ID

Parameters

NameType
nftIdstring

Returns

Promise<string>


foundryOutputIds

foundryOutputIds(queryParameters): Promise<OutputIdsResponse>

Fetch Foundry Output IDs

Parameters

NameType
queryParametersFoundryQueryParameter[]

Returns

Promise<OutputIdsResponse>


foundryOutputId

foundryOutputId(foundryId): Promise<string>

Fetch Foundry Output ID

Parameters

NameType
foundryIdstring

Returns

Promise<string>


getOutputsIgnoreErrors

getOutputsIgnoreErrors(outputIds): Promise<IOutputResponse[]>

Try to get OutputResponse from provided OutputIds (requests are sent in parallel and errors are ignored, can be useful for spent outputs)

Parameters

NameType
outputIdsstring[]

Returns

Promise<IOutputResponse[]>


findBlocks

findBlocks(blockIds): Promise<IBlock[]>

Find all blocks by provided block IDs.

Parameters

NameType
blockIdsstring[]

Returns

Promise<IBlock[]>


retry

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

Retries (promotes or reattaches) a block for provided block id. Block should be retried only if they are valid and haven't been confirmed for a while.

Parameters

NameType
blockIdstring

Returns

Promise<[string, IBlock]>


retryUntilIncluded

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

Retries (promotes or reattaches) a block for provided block id until it's included (referenced by a milestone). Default interval is 5 seconds and max attempts is 40. Returns the included block at first position and additional reattached blocks

Parameters

NameType
blockIdstring
interval?number
maxAttempts?number

Returns

Promise<[string, IBlock][]>


consolidateFunds

consolidateFunds(secretManager, generateAddressesOptions): Promise<string>

Function to consolidate all funds from a range of addresses to the address with the lowest index in that range Returns the address to which the funds got consolidated, if any were available

Parameters

NameType
secretManagerSecretManagerType
generateAddressesOptionsIGenerateAddressesOptions

Returns

Promise<string>


reattach

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

Reattaches blocks for provided block id. Blocks can be reattached only if they are valid and haven't been confirmed for a while.

Parameters

NameType
blockIdstring

Returns

Promise<[string, IBlock]>


reattachUnchecked

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

Reattach a block without checking if it should be reattached

Parameters

NameType
blockIdstring

Returns

Promise<[string, IBlock]>


promote

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

Promotes a block. The method should validate if a promotion is necessary through get_block. If not, the method should error out and should not allow unnecessary promotions.

Parameters

NameType
blockIdstring

Returns

Promise<[string, IBlock]>


promoteUnchecked

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

Promote a block without checking if it should be promoted

Parameters

NameType
blockIdstring

Returns

Promise<[string, IBlock]>


unhealthyNodes

unhealthyNodes(): Promise<Set<INode>>

Returns the unhealthy nodes.

Returns

Promise<Set<INode>>


buildBasicOutput

buildBasicOutput(params): Promise<BasicOutput>

Build a Basic Output.

Parameters

NameType
paramsBasicOutputBuilderParams

Returns

Promise<BasicOutput>


buildAliasOutput

buildAliasOutput(params): Promise<AliasOutput>

Build an Alias Output.

Parameters

NameType
paramsAliasOutputBuilderParams

Returns

Promise<AliasOutput>


buildFoundryOutput

buildFoundryOutput(params): Promise<FoundryOutput>

Build a Foundry Output.

Parameters

NameType
paramsFoundryOutputBuilderParams

Returns

Promise<FoundryOutput>


buildNftOutput

buildNftOutput(params): Promise<NftOutput>

Build an Nft Output.

Parameters

NameType
paramsNftOutputBuilderParams

Returns

Promise<NftOutput>


listen

listen(topics, callback): Promise<void>

Listen to MQTT topics.

Parameters

NameType
topicsstring[]
callback(error: Error, result: string) => void

Returns

Promise<void>


clearListeners

clearListeners(topics): Promise<void>

Stop listening for provided MQTT topics.

Parameters

NameType
topicsstring[]

Returns

Promise<void>


requestFundsFromFaucet

requestFundsFromFaucet(url, address): Promise<string>

Request funds from a faucet, for example https://faucet.testnet.shimmer.network/api/enqueue or http://localhost:8091/api/enqueue.

Parameters

NameType
urlstring
addressstring

Returns

Promise<string>