Class: Client
The Client to interact with nodes.
Table of contents
Methods
- getInfo
- getNetworkInfo
- basicOutputIds
- getOutput
- getOutputs
- generateEd25519Addresses
- buildAndPostBlock
- getTips
- postBlock
- getBlock
- getBlockMetadata
- findInputs
- findOutputs
- prepareTransaction
- signTransaction
- signatureUnlock
- postBlockPayload
- getNode
- getNetworkId
- getBech32Hrp
- getMinPowScore
- getTipsInterval
- getTokenSupply
- getProtocolParameters
- getLocalPow
- getFallbackToLocalPow
- getHealth
- getNodeInfo
- getPeers
- postBlockRaw
- getBlockRaw
- getMilestoneById
- getUtxoChangesById
- getMilestoneByIndex
- getUtxoChangesByIndex
- getReceipts
- getReceiptsMigratedAt
- getTreasury
- getIncludedBlock
- getIncludedBlockMetadata
- hexToBech32
- aliasIdToBech32
- nftIdToBech32
- hexPublicKeyToBech32Address
- aliasOutputIds
- aliasOutputId
- nftOutputIds
- nftOutputId
- foundryOutputIds
- foundryOutputId
- getOutputsIgnoreErrors
- findBlocks
- retry
- retryUntilIncluded
- consolidateFunds
- reattach
- reattachUnchecked
- promote
- promoteUnchecked
- unhealthyNodes
- buildBasicOutput
- buildAliasOutput
- buildFoundryOutput
- buildNftOutput
- listen
- clearListeners
- requestFundsFromFaucet
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
Name | Type |
---|---|
queryParameters | QueryParameter [] |
Returns
Promise
<OutputIdsResponse
>
getOutput
▸ getOutput(outputId
): Promise
<IOutputResponse
>
Get output from a known outputID
Parameters
Name | Type |
---|---|
outputId | string |
Returns
Promise
<IOutputResponse
>
getOutputs
▸ getOutputs(outputIds
): Promise
<IOutputResponse
[]>
Fetch OutputResponse from provided OutputIds (requests are sent in parallel)
Parameters
Name | Type |
---|---|
outputIds | string [] |
Returns
Promise
<IOutputResponse
[]>
generateEd25519Addresses
▸ generateEd25519Addresses(secretManager
, generateAddressesOptions
): Promise
<string
[]>
Generate addresses
Parameters
Name | Type |
---|---|
secretManager | SecretManagerType |
generateAddressesOptions | IGenerateAddressesOptions |
Returns
Promise
<string
[]>
buildAndPostBlock
▸ buildAndPostBlock(secretManager?
, options?
): Promise
<[string
, IBlock
]>
Build and post a block
Parameters
Name | Type |
---|---|
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
Name | Type |
---|---|
block | IBlock |
Returns
Promise
<string
>
getBlock
▸ getBlock(blockId
): Promise
<IBlock
>
Get block as JSON.
Parameters
Name | Type |
---|---|
blockId | string |
Returns
Promise
<IBlock
>
getBlockMetadata
▸ getBlockMetadata(blockId
): Promise
<IBlockMetadata
>
Get block metadata.
Parameters
Name | Type |
---|---|
blockId | string |
Returns
Promise
<IBlockMetadata
>
findInputs
▸ findInputs(addresses
, amount
): Promise
<IUTXOInput
[]>
Find inputs from addresses for a provided amount (useful for offline signing)
Parameters
Name | Type |
---|---|
addresses | string [] |
amount | number |
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
Name | Type |
---|---|
outputIds | string [] |
addresses | string [] |
Returns
Promise
<IOutputResponse
[]>
prepareTransaction
▸ prepareTransaction(secretManager?
, options?
): Promise
<IPreparedTransactionData
>
Prepare a transaction for signing
Parameters
Name | Type |
---|---|
secretManager? | SecretManagerType |
options? | IBuildBlockOptions |
Returns
Promise
<IPreparedTransactionData
>
signTransaction
▸ signTransaction(secretManager
, preparedTransactionData
): Promise
<PayloadTypes
>
Sign a transaction
Parameters
Name | Type |
---|---|
secretManager | SecretManagerType |
preparedTransactionData | IPreparedTransactionData |
Returns
Promise
<PayloadTypes
>
signatureUnlock
▸ signatureUnlock(secretManager
, transactionEssenceHash
, chain
): Promise
<UnlockTypes
>
Create a signature unlock using the provided secretManager
.
Parameters
Name | Type |
---|---|
secretManager | SecretManagerType |
transactionEssenceHash | string |
chain | IBip32Chain |
Returns
Promise
<UnlockTypes
>
postBlockPayload
▸ postBlockPayload(payload
): Promise
<[string
, IBlock
]>
Submit a payload in a block
Parameters
Name | Type |
---|---|
payload | PayloadTypes |
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
Name | Type |
---|---|
url | string |
Returns
Promise
<boolean
>
getNodeInfo
▸ getNodeInfo(url
, auth?
): Promise
<INodeInfo
>
Get info of node with input url.
Parameters
Name | Type |
---|---|
url | string |
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
Name | Type |
---|---|
block | IBlock |
Returns
Promise
<string
>
getBlockRaw
▸ getBlockRaw(blockId
): Promise
<Uint8Array
>
Get block as raw bytes.
Parameters
Name | Type |
---|---|
blockId | string |
Returns
Promise
<Uint8Array
>
getMilestoneById
▸ getMilestoneById(milestoneId
): Promise
<IMilestonePayload
>
Look up a milestone by a given milestone index.
Parameters
Name | Type |
---|---|
milestoneId | string |
Returns
Promise
<IMilestonePayload
>
getUtxoChangesById
▸ getUtxoChangesById(milestoneId
): Promise
<IMilestoneUtxoChangesResponse
>
Returns all UTXO changes that happened at a specific milestone.
Parameters
Name | Type |
---|---|
milestoneId | string |
Returns
Promise
<IMilestoneUtxoChangesResponse
>
getMilestoneByIndex
▸ getMilestoneByIndex(index
): Promise
<IMilestonePayload
>
Look up a milestone by a given milestone index.
Parameters
Name | Type |
---|---|
index | number |
Returns
Promise
<IMilestonePayload
>
getUtxoChangesByIndex
▸ getUtxoChangesByIndex(index
): Promise
<IMilestoneUtxoChangesResponse
>
Returns all UTXO changes that happened at a specific milestone.
Parameters
Name | Type |
---|---|
index | number |
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
Name | Type |
---|---|
milestoneIndex | number |
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
Name | Type |
---|---|
transactionId | string |
Returns
Promise
<IBlock
>
getIncludedBlockMetadata
▸ getIncludedBlockMetadata(transactionId
): Promise
<IBlock
>
Returns the metadata of the included block of the transaction.
Parameters
Name | Type |
---|---|
transactionId | string |
Returns
Promise
<IBlock
>
hexToBech32
▸ hexToBech32(hex
, bech32Hrp?
): Promise
<string
>
Transforms a hex encoded address to a bech32 encoded address.
Parameters
Name | Type |
---|---|
hex | string |
bech32Hrp? | string |
Returns
Promise
<string
>
aliasIdToBech32
▸ aliasIdToBech32(aliasId
, bech32Hrp?
): Promise
<string
>
Transforms an alias id to a bech32 encoded address.
Parameters
Name | Type |
---|---|
aliasId | string |
bech32Hrp? | string |
Returns
Promise
<string
>
nftIdToBech32
▸ nftIdToBech32(nftId
, bech32Hrp?
): Promise
<string
>
Transforms an nft id to a bech32 encoded address.
Parameters
Name | Type |
---|---|
nftId | string |
bech32Hrp? | string |
Returns
Promise
<string
>
hexPublicKeyToBech32Address
▸ hexPublicKeyToBech32Address(hex
, bech32Hrp?
): Promise
<string
>
Transforms a hex encoded public key to a bech32 encoded address.
Parameters
Name | Type |
---|---|
hex | string |
bech32Hrp? | string |
Returns
Promise
<string
>
aliasOutputIds
▸ aliasOutputIds(queryParameters
): Promise
<OutputIdsResponse
>
Fetch alias output IDs
Parameters
Name | Type |
---|---|
queryParameters | AliasQueryParameter [] |
Returns
Promise
<OutputIdsResponse
>
aliasOutputId
▸ aliasOutputId(aliasId
): Promise
<string
>
Fetch alias output ID
Parameters
Name | Type |
---|---|
aliasId | string |
Returns
Promise
<string
>
nftOutputIds
▸ nftOutputIds(queryParameters
): Promise
<OutputIdsResponse
>
Fetch NFT output IDs
Parameters
Name | Type |
---|---|
queryParameters | NftQueryParameter [] |
Returns
Promise
<OutputIdsResponse
>
nftOutputId
▸ nftOutputId(nftId
): Promise
<string
>
Fetch NFT output ID
Parameters
Name | Type |
---|---|
nftId | string |
Returns
Promise
<string
>
foundryOutputIds
▸ foundryOutputIds(queryParameters
): Promise
<OutputIdsResponse
>
Fetch Foundry Output IDs
Parameters
Name | Type |
---|---|
queryParameters | FoundryQueryParameter [] |
Returns
Promise
<OutputIdsResponse
>
foundryOutputId
▸ foundryOutputId(foundryId
): Promise
<string
>
Fetch Foundry Output ID
Parameters
Name | Type |
---|---|
foundryId | string |
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
Name | Type |
---|---|
outputIds | string [] |
Returns
Promise
<IOutputResponse
[]>
findBlocks
▸ findBlocks(blockIds
): Promise
<IBlock
[]>
Find all blocks by provided block IDs.
Parameters
Name | Type |
---|---|
blockIds | string [] |
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
Name | Type |
---|---|
blockId | string |
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
Name | Type |
---|---|
blockId | string |
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
Name | Type |
---|---|
secretManager | SecretManagerType |
generateAddressesOptions | IGenerateAddressesOptions |
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
Name | Type |
---|---|
blockId | string |
Returns
Promise
<[string
, IBlock
]>
reattachUnchecked
▸ reattachUnchecked(blockId
): Promise
<[string
, IBlock
]>
Reattach a block without checking if it should be reattached
Parameters
Name | Type |
---|---|
blockId | string |
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
Name | Type |
---|---|
blockId | string |
Returns
Promise
<[string
, IBlock
]>
promoteUnchecked
▸ promoteUnchecked(blockId
): Promise
<[string
, IBlock
]>
Promote a block without checking if it should be promoted
Parameters
Name | Type |
---|---|
blockId | string |
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
Name | Type |
---|---|
params | BasicOutputBuilderParams |
Returns
Promise
<BasicOutput
>
buildAliasOutput
▸ buildAliasOutput(params
): Promise
<AliasOutput
>
Build an Alias Output.
Parameters
Name | Type |
---|---|
params | AliasOutputBuilderParams |
Returns
Promise
<AliasOutput
>
buildFoundryOutput
▸ buildFoundryOutput(params
): Promise
<FoundryOutput
>
Build a Foundry Output.
Parameters
Name | Type |
---|---|
params | FoundryOutputBuilderParams |
Returns
Promise
<FoundryOutput
>
buildNftOutput
▸ buildNftOutput(params
): Promise
<NftOutput
>
Build an Nft Output.
Parameters
Name | Type |
---|---|
params | NftOutputBuilderParams |
Returns
Promise
<NftOutput
>
listen
▸ listen(topics
, callback
): Promise
<void
>
Listen to MQTT topics.
Parameters
Name | Type |
---|---|
topics | string [] |
callback | (error : Error , result : string ) => void |
Returns
Promise
<void
>
clearListeners
▸ clearListeners(topics
): Promise
<void
>
Stop listening for provided MQTT topics.
Parameters
Name | Type |
---|---|
topics | string [] |
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
Name | Type |
---|---|
url | string |
address | string |
Returns
Promise
<string
>