Class: Client
The Client to interact with nodes.
Table of contents
Methods
- getInfo
- getNetworkInfo
- basicOutputIds
- getOutput
- getOutputs
- generateMnemonic
- mnemonicToHexSeed
- computeAliasId
- computeNftId
- computeFoundryId
- generateAddresses
- buildAndPostBlock
- getTips
- postBlock
- getBlock
- getBlockMetadata
- findInputs
- findOutputs
- getLedgerNanoStatus
- prepareTransaction
- storeMnemonic
- signTransaction
- signatureUnlock
- postBlockPayload
- parseBech32Address
- blockId
- getNode
- getNetworkId
- getBech32Hrp
- getMinPowScore
- getTipsInterval
- getTokenSupply
- getProtocolParameters
- getLocalPow
- getFallbackToLocalPow
- getHealth
- getNodeInfo
- getPeers
- postBlockRaw
- getBlockRaw
- getMilestoneById
- getUtxoChangesById
- getMilestoneByIndex
- getUtxoChangesByIndex
- getReceipts
- getReceiptsMigratedAt
- getTreasury
- getIncludedBlock
- getIncludedBlockMetadata
- bech32ToHex
- hexToBech32
- aliasIdToBech32
- nftIdToBech32
- hexPublicKeyToBech32Address
- isAddressValid
- aliasOutputIds
- aliasOutputId
- nftOutputIds
- nftOutputId
- foundryOutputIds
- foundryOutputId
- tryGetOutputs
- findBlocks
- retry
- retryUntilIncluded
- consolidateFunds
- reattach
- reattachUnchecked
- promote
- promoteUnchecked
- unhealthyNodes
- buildBasicOutput
- buildAliasOutput
- buildFoundryOutput
- buildNftOutput
- hashTransactionEssence
- listen
- clearListeners
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
[]>
generateMnemonic
▸ generateMnemonic(): Promise
<string
>
Generates a new mnemonic.
Returns
Promise
<string
>
mnemonicToHexSeed
▸ mnemonicToHexSeed(mnemonic
): Promise
<string
>
Returns a hex encoded seed for a mnemonic.
Parameters
Name | Type |
---|---|
mnemonic | string |
Returns
Promise
<string
>
computeAliasId
▸ computeAliasId(outputId
): Promise
<string
>
Computes the alias id for the given alias output id.
Parameters
Name | Type |
---|---|
outputId | string |
Returns
Promise
<string
>
computeNftId
▸ computeNftId(outputId
): Promise
<string
>
Computes the NFT id for the given NFT output id.
Parameters
Name | Type |
---|---|
outputId | string |
Returns
Promise
<string
>
computeFoundryId
▸ computeFoundryId(aliasAddress
, serialNumber
, tokenSchemeKind
): Promise
<string
>
Computes the foundry id.
Parameters
Name | Type |
---|---|
aliasAddress | string |
serialNumber | number |
tokenSchemeKind | number |
Returns
Promise
<string
>
generateAddresses
▸ generateAddresses(secretManager
, generateAddressesOptions
): Promise
<string
[]>
Generate addresses
Parameters
Name | Type |
---|---|
secretManager | SecretManager |
generateAddressesOptions | IGenerateAddressesOptions |
Returns
Promise
<string
[]>
buildAndPostBlock
▸ buildAndPostBlock(secretManager?
, options?
): Promise
<[string
, IBlock
]>
Build and post a block
Parameters
Name | Type |
---|---|
secretManager? | SecretManager |
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
[]>
getLedgerNanoStatus
▸ getLedgerNanoStatus(isSimulator
): Promise
<LedgerNanoStatus
>
Get the status of a Ledger Nano
Parameters
Name | Type |
---|---|
isSimulator | boolean |
Returns
Promise
<LedgerNanoStatus
>
prepareTransaction
▸ prepareTransaction(secretManager?
, options?
): Promise
<IPreparedTransactionData
>
Prepare a transaction for signing
Parameters
Name | Type |
---|---|
secretManager? | SecretManager |
options? | IBuildBlockOptions |
Returns
Promise
<IPreparedTransactionData
>
storeMnemonic
▸ storeMnemonic(secretManager
, mnemonic
): Promise
<void
>
Store a mnemonic in the Stronghold vault
Parameters
Name | Type |
---|---|
secretManager | SecretManager |
mnemonic | string |
Returns
Promise
<void
>
signTransaction
▸ signTransaction(secretManager
, preparedTransactionData
): Promise
<PayloadTypes
>
Sign a transaction
Parameters
Name | Type |
---|---|
secretManager | SecretManager |
preparedTransactionData | IPreparedTransactionData |
Returns
Promise
<PayloadTypes
>
signatureUnlock
▸ signatureUnlock(secretManager
, inputSigningData
, transactionEssenceHash
): Promise
<UnlockTypes
>
Create a signature unlock using the provided secretManager
.
Parameters
Name | Type |
---|---|
secretManager | SecretManager |
inputSigningData | IInputSigningData |
transactionEssenceHash | number [] |
Returns
Promise
<UnlockTypes
>
postBlockPayload
▸ postBlockPayload(payload
): Promise
<[string
, IBlock
]>
Submit a payload in a block
Parameters
Name | Type |
---|---|
payload | PayloadTypes |
Returns
Promise
<[string
, IBlock
]>
parseBech32Address
▸ parseBech32Address(address
): Promise
<AddressTypes
>
Returns a valid Address parsed from a String.
Parameters
Name | Type |
---|---|
address | string |
Returns
Promise
<AddressTypes
>
blockId
▸ blockId(block
): Promise
<string
>
Returns a block ID (Blake2b256 hash of the block bytes)
Parameters
Name | Type |
---|---|
block | IBlock |
Returns
Promise
<string
>
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
>
bech32ToHex
▸ bech32ToHex(bech32
): Promise
<string
>
Transforms bech32 to hex.
Parameters
Name | Type |
---|---|
bech32 | string |
Returns
Promise
<string
>
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
>
isAddressValid
▸ isAddressValid(address
): Promise
<boolean
>
Checks if a String is a valid bech32 encoded address.
Parameters
Name | Type |
---|---|
address | string |
Returns
Promise
<boolean
>
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
>
tryGetOutputs
▸ tryGetOutputs(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 | SecretManager |
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(options
): Promise
<IBasicOutput
>
Build a Basic Output.
Parameters
Name | Type |
---|---|
options | IBasicOutputBuilderOptions |
Returns
Promise
<IBasicOutput
>
buildAliasOutput
▸ buildAliasOutput(options
): Promise
<IAliasOutput
>
Build an Alias Output.
Parameters
Name | Type |
---|---|
options | IAliasOutputBuilderOptions |
Returns
Promise
<IAliasOutput
>
buildFoundryOutput
▸ buildFoundryOutput(options
): Promise
<IFoundryOutput
>
Build a Foundry Output.
Parameters
Name | Type |
---|---|
options | IFoundryOutputBuilderOptions |
Returns
Promise
<IFoundryOutput
>
buildNftOutput
▸ buildNftOutput(options
): Promise
<INftOutput
>
Build an Nft Output.
Parameters
Name | Type |
---|---|
options | INftOutputBuilderOptions |
Returns
Promise
<INftOutput
>
hashTransactionEssence
▸ hashTransactionEssence(essence
): Promise
<string
>
Compute the hash of a transaction essence.
Parameters
Name | Type |
---|---|
essence | ITransactionEssence |
Returns
Promise
<string
>
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
>