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[]>


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

NameType
mnemonicstring

Returns

Promise<string>


computeAliasId

computeAliasId(outputId): Promise<string>

Computes the alias id for the given alias output id.

Parameters

NameType
outputIdstring

Returns

Promise<string>


computeNftId

computeNftId(outputId): Promise<string>

Computes the NFT id for the given NFT output id.

Parameters

NameType
outputIdstring

Returns

Promise<string>


computeFoundryId

computeFoundryId(aliasAddress, serialNumber, tokenSchemeKind): Promise<string>

Computes the foundry id.

Parameters

NameType
aliasAddressstring
serialNumbernumber
tokenSchemeKindnumber

Returns

Promise<string>


generateAddresses

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

Generate addresses

Parameters

NameType
secretManagerSecretManager
generateAddressesOptionsIGenerateAddressesOptions

Returns

Promise<string[]>


buildAndPostBlock

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

Build and post a block

Parameters

NameType
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

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[]>


getLedgerNanoStatus

getLedgerNanoStatus(isSimulator): Promise<LedgerNanoStatus>

Get the status of a Ledger Nano

Parameters

NameType
isSimulatorboolean

Returns

Promise<LedgerNanoStatus>


prepareTransaction

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

Prepare a transaction for signing

Parameters

NameType
secretManager?SecretManager
options?IBuildBlockOptions

Returns

Promise<IPreparedTransactionData>


storeMnemonic

storeMnemonic(secretManager, mnemonic): Promise<void>

Store a mnemonic in the Stronghold vault

Parameters

NameType
secretManagerSecretManager
mnemonicstring

Returns

Promise<void>


signTransaction

signTransaction(secretManager, preparedTransactionData): Promise<PayloadTypes>

Sign a transaction

Parameters

NameType
secretManagerSecretManager
preparedTransactionDataIPreparedTransactionData

Returns

Promise<PayloadTypes>


signatureUnlock

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

Create a signature unlock using the provided secretManager.

Parameters

NameType
secretManagerSecretManager
inputSigningDataIInputSigningData
transactionEssenceHashnumber[]

Returns

Promise<UnlockTypes>


postBlockPayload

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

Submit a payload in a block

Parameters

NameType
payloadPayloadTypes

Returns

Promise<[string, IBlock]>


parseBech32Address

parseBech32Address(address): Promise<AddressTypes>

Returns a valid Address parsed from a String.

Parameters

NameType
addressstring

Returns

Promise<AddressTypes>


blockId

blockId(block): Promise<string>

Returns a block ID (Blake2b256 hash of the block bytes)

Parameters

NameType
blockIBlock

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

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>


bech32ToHex

bech32ToHex(bech32): Promise<string>

Transforms bech32 to hex.

Parameters

NameType
bech32string

Returns

Promise<string>


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>


isAddressValid

isAddressValid(address): Promise<boolean>

Checks if a String is a valid bech32 encoded address.

Parameters

NameType
addressstring

Returns

Promise<boolean>


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>


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

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
secretManagerSecretManager
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(options): Promise<IBasicOutput>

Build a Basic Output.

Parameters

NameType
optionsIBasicOutputBuilderOptions

Returns

Promise<IBasicOutput>


buildAliasOutput

buildAliasOutput(options): Promise<IAliasOutput>

Build an Alias Output.

Parameters

NameType
optionsIAliasOutputBuilderOptions

Returns

Promise<IAliasOutput>


buildFoundryOutput

buildFoundryOutput(options): Promise<IFoundryOutput>

Build a Foundry Output.

Parameters

NameType
optionsIFoundryOutputBuilderOptions

Returns

Promise<IFoundryOutput>


buildNftOutput

buildNftOutput(options): Promise<INftOutput>

Build an Nft Output.

Parameters

NameType
optionsINftOutputBuilderOptions

Returns

Promise<INftOutput>


hashTransactionEssence

hashTransactionEssence(essence): Promise<string>

Compute the hash of a transaction essence.

Parameters

NameType
essenceITransactionEssence

Returns

Promise<string>


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>