Node.js binding to the IOTA client library.
- Using NPM:
$ npm i @iota/client
- Using yarn:
$ yarn add @iota/client
One of the following Node.js version: '10.x', '12.x', '14.x', '15.x', '16.x'
After you linked the library, you can create a Client
instance and interface with it.
const { ClientBuilder } = require('@iota/client')
const client = new ClientBuilder()
.node('https://api.lb-0.testnet.chrysalis2.com')
.build()
client.getInfo().then(console.log).catch(console.error)
Connecting to a MQTT broker using raw ip doesn't work. This is a limitation of rustls.
Adds an IOTA node to the client pool.
Param | Type | Description |
---|---|---|
url | string |
A node URL |
Returns the client builder instance for chained calls.
Adds an IOTA node with authentication to the client pool.
Param | Type | Description |
---|---|---|
url | string |
A node URL |
authOptions | NodeAuthOptions |
Options for node authentication |
Returns the client builder instance for chained calls.
Add a node to always connect first to with optional authentication.
Param | Type | Description |
---|---|---|
url | string |
A node URL |
authOptions | NodeAuthOptions |
Options for node authentication |
Returns the client builder instance for chained calls.
Add a node to always connect first to when using remote PoW with optional authentication. Will overwrite the primary node for this case.
Param | Type | Description |
---|---|---|
url | string |
A node URL |
authOptions | NodeAuthOptions |
Options for node authentication |
Returns the client builder instance for chained calls.
Adds a list of IOTA nodes to the client pool.
Param | Type | Description |
---|---|---|
url | string[] |
An array of node URLs |
Returns the client builder instance for chained calls.
Adds a list of IOTA nodes from node pool URLs to the client pool.
Param | Type | Description |
---|---|---|
url | string[] |
An array of node pool URLs |
Returns the client builder instance for chained calls.
Set a network to get default nodes for it. Can be "testnet" or "mainnet". Nodes that don't belong to this network are ignored.
Param | Type | Description |
---|---|---|
networkName | string |
The network |
Returns the client builder instance for chained calls.
Defines how many of nodes will be queried at the same time to check for quorum.
Param | Type | Description |
---|---|---|
enabled | boolean |
Define if quourm should be used or not |
Returns the client builder instance for chained calls.
Defines how many of nodes will be queried at the same time to check for quorum.
Param | Type | Description |
---|---|---|
size | number |
The number of nodes that will be queried |
Returns the client builder instance for chained calls.
Defines the minimum amount of nodes from the quorum pool that need to agree if we want to consider the result true.
Param | Type | Description |
---|---|---|
threshold | number |
Minimum amount of nodes |
Returns the client builder instance for chained calls.
Sets the options for the MQTT connection with the node.
Param | Type | Description |
---|---|---|
options | BrokerOptions |
The MQTT broker options |
Returns the client builder instance for chained calls.
Sets the node syncing interval.
Param | Type | Description |
---|---|---|
interval | number |
The interval for the node syncing process |
Returns the client builder instance for chained calls.
Disables the node syncing process. Every node will be considered healthy and ready to use.
Returns the client builder instance for chained calls.
Sets the default HTTP request timeout.
Param | Type | Description |
---|---|---|
timeout | number |
The timeout in milliseconds |
Returns the client builder instance for chained calls.
Sets the HTTP request timeout for the specified API.
Param | Type | Description |
---|---|---|
api | 'GetHealth' | 'GetInfo' | 'GetTips' | 'PostMessage' | 'GetOutput' | 'GetMilestone' |
The API to set the request timeout |
timeout | number |
The timeout in milliseconds |
Returns the client builder instance for chained calls.
Sets the PoW type.
Param | Type | Description |
---|---|---|
local | boolean |
Flag determining if PoW should be done locally or remotely |
Returns the client builder instance for chained calls.
Builds the client instance.
Returns a Client instance.
Gets the cached network info.
Returns a NetworkInfo instance.
Gets a handle to the MQTT topic subscriber.
Returns a TopicSubscriber instance.
Initiates the builder to send messages.
Returns a MessageSender instance.
Get a valid unspent address.
Param | Type | Description |
---|---|---|
seed | string |
The hex-encoded seed to search |
Returns a UnspentAddressGetter instance.
Find addresses from the seed regardless of their validity.
Param | Type | Description |
---|---|---|
seed | string |
The hex-encoded seed to search |
Returns a AddressGetter instance.
Finds all messages associated with the given indexation keys and message ids.
Param | Type | Description |
---|---|---|
indexationKeys | string[] |
The list of indexations keys too search |
messageIds | string[] |
The list of message ids to search |
Returns a promise resolving to the list of the found messages.
Get balance on a given seed and its wallet account index.
Param | Type | Description |
---|---|---|
seed | string |
The hex-encoded seed to search |
Returns a BalanceGetter instance.
Get the balance in iotas for the given addresses.
Param | Type | Description |
---|---|---|
addresses | string[] |
The list of addresses to search |
Returns A promise resolving to the list of { address, balance }
pairs.
Returns a random generated Bip39 mnemonic with the English word list.
Returns A String
Returns the seed hex encoded.
Param | Type | Description |
---|---|---|
mnemonic | string |
Bip39 mnemonic with words from the English word list. |
Returns A String
Returns a parsed hex String from bech32.
Param | Type | Description |
---|---|---|
bech32 | string |
The address Bech32 string |
Returns A String
Returns a parsed bech32 String from hex.
Param | Type | Description |
---|---|---|
bech32 | string |
The address Bech32 string |
bech32_hrp | string |
The Bech32 hrp string |
Returns A String
Checks if a given address is valid.
Param | Type | Description |
---|---|---|
address | string |
The address Bech32 string |
Returns A boolean.
Retries (promotes or reattaches) the message associated with the given id.
Param | Type | Description |
---|---|---|
messageId | string |
The id of the message to retry |
Returns A promise resolving to the new Message instance.
Retries (promotes or reattaches) the message associated with the given id until it's included in the Tangle. Default interval is 5 seconds and max_attempts is 10.
Param | Type | Description |
---|---|---|
messageId | string |
The id of the message to retry |
[options.interval] | int |
The interval in seconds in which we retry the message. |
[options.maxAttempts] | int |
The maximum of attempts we retry the message. |
Returns the message ids and Message of reattached messages.
Function to consolidate all funds from a range of addresses to the address with the lowest index in that range
Param | Type | Description |
---|---|---|
seed | string |
The seed |
accountIndex | int |
The account index. |
startIndex | int |
The lowest address index, funds will be consolidated to this address. |
endIndex | int |
The address index until which funds will be consolidated |
Returns the address to which the funds got consolidated, if any were available.
Gets information about the node.
Returns a promise resolving to the NodeInfoWrapper object.
Gets two non-lazy tips.
Returns a promise resolving to an array of length 2 containing the message ids of the tips.
Submits a message.
Param | Type | Description |
---|---|---|
message | MessageDto |
The message to submit |
Returns the message identifier.
Gets a message from its identifier.
Returns an instance of the MessageFinder for choices of response.
Gets the UTXO outputs associated with the given output id.
Param | Type | Description |
---|---|---|
outputId | string |
The id of the output to search |
Returns a promise resolving to the associated OutputMetadata.
Gets the UTXO outputs associated with the given output ids and addresses.
Param | Type | Description |
---|---|---|
addresses | string[] |
The list of addresses to search |
outputIds | string[] |
The list of output ids to search |
Returns a promise resolving to a list of OutputMetadata.
Gets the UTXO outputs associated with the given address.
Param | Type | Description |
---|---|---|
address | string |
The address Bech32 string |
[options.includeSpent] | boolean |
Whether the query should include spent outputs or not |
[options.outputType] | 'SignatureLockedSingle' | 'SignatureLockedDustAllowance' |
The output type filter |
Returns a promise resolving to a list of output ids.
Gets the balance of the given address.
Param | Type | Description |
---|---|---|
address | string |
The address Bech32 string |
Gets the milestone by the given index.
Param | Type | Description |
---|---|---|
index | number |
The index of the milestone |
Returns a promise resolving to the MilestoneMetadata.
Gets the utxo changes by the given milestone index.
Param | Type | Description |
---|---|---|
index | number |
The index of the milestone |
Returns a promise resolving to the MilestoneUTXOChanges.
Get all receipts.
Returns a promise resolving to the Receipts.
Get all receipts for a given milestone index
Param | Type | Description |
---|---|---|
index | number |
The index of the milestone |
Returns a promise resolving to the Receipts.
Get the treasury amount.
Returns a promise resolving to the Treasury.
Get the included message of a transaction.
Param | Type | Description |
---|---|---|
index | string |
The id of the transaction |
Returns A promise resolving to the new Message instance.
Reattaches the message associated with the given id.
Param | Type | Description |
---|---|---|
messageId | string |
The id of the message to reattach |
Returns A promise resolving to the new Message instance.
Promotes the message associated with the given id.
Param | Type | Description |
---|---|---|
messageId | string |
The id of the message to promote |
Returns A promise resolving to the new Message instance.
Field | Type | Description |
---|---|---|
network | string |
The network |
networkId | number |
The network hashed |
bech32HRP | string |
Bech32 HRP for this network |
minPoWScore | number |
The network's minimum score for PoW |
localPow | boolean |
Whether we are using local PoW or not |
Possible topics:
milestones/latest
milestones/confirmed
messages
messages/referenced
messages/indexation/{index}
messages/{messageId}/metadata
transactions/{transactionId}/included-message
outputs/{outputId}
addresses/{address}/outputs
addresses/ed25519/{address}/outputs
Adds a topic to this manager instance.
Param | Type | Description |
---|---|---|
topic | string |
A MQTT topic |
Returns the topic subscriber instance for chained calls.
Adds a list of topics to this manager instance.
Param | Type | Description |
---|---|---|
topics | string[] |
An array of MQTT topics |
Returns the topic subscriber instance for chained calls.
Subscribe to the provided topics.
Param | Type | Description |
---|---|---|
cb | function |
The topic handler callback in the form of (err, message) => {} |
Returns the topic subscriber instance for chained calls.
Unsubscribes from the provided topics.
Param | Type | Description |
---|---|---|
cb | function |
A callback executed when the unsubscribe is finished in the form of (err, message) => {} |
Returns the topic subscriber instance for chained calls.
Builder to create and submit messages to the Tangle.
Sets the message indexation. This field is required for indexation payloads.
Param | Type | Description |
---|---|---|
index | string |
number[] |
Returns the message submit instance for chained calls.
Sets the indexation data.
Param | Type | Description |
---|---|---|
data | string |
Uint8Array |
Returns the message submit instance for chained calls.
Sets the transaction account seed. This field is required for transaction payloads.
Param | Type | Description |
---|---|---|
seed | string |
The hex-encoded seed of the account to spend |
Returns the message submit instance for chained calls.
Sets 1-8 custom parent message ids.
Param | Type | Description |
---|---|---|
messageId | string[] |
The parents message ids |
Returns the message submit instance for chained calls.
Sets the account index. This field is required for transactions.
Param | Type | Description |
---|---|---|
index | number |
The account index |
Returns the message submit instance for chained calls.
Adds an output to the transaction.
Param | Type | Description |
---|---|---|
transactionId | string |
The transaction id |
index | number |
The input index |
Returns the message submit instance for chained calls.
Defines the range in which to search for addresses fro custom inputs.
Param | Type | Description |
---|---|---|
start | number |
The start index |
end | number |
The end index |
Returns the message submit instance for chained calls.
Adds an output to the transaction.
Param | Type | Description |
---|---|---|
address | string |
The output address |
amount | number |
The output amount |
Returns the message submit instance for chained calls.
Adds a dust allowance output to the transaction.
Param | Type | Description |
---|---|---|
address | string |
The output address |
amount | number |
The output amount |
Returns the message submit instance for chained calls.
Sets the initial address index to search for balance. Defaults to 0 if the function isn't called.
Param | Type | Description |
---|---|---|
index | number |
The initial address index |
Returns the message submit instance for chained calls.
Submits the message.
Returns a promise resolving to the message identifier.
Gets a valid unspent address associated with the seed.
Sets the account index. This field is required.
Param | Type | Description |
---|---|---|
index | number |
The account index |
Returns the address getter instance for chained calls.
Sets the initial address index. Defaults to 0 if the function isn't called.
Param | Type | Description |
---|---|---|
index | number |
The initial address index |
Returns the address getter instance for chained calls.
Performs the operation.
Returns a promise resolving to the Address instance and its index.
Generates addresses with a given seed.
Sets the account index. This field is required.
Param | Type | Description |
---|---|---|
index | number |
The account index |
Returns the address finder instance for chained calls.
Defines the range of addresses to get. Defaults to 0..20
if the function isn't called.
Param | Type | Description |
---|---|---|
start | number |
The first address index |
end | number |
The last address index |
Returns the address finder instance for chained calls.
Defines that public and internal address will be returned instead of only public addresses.
Returns the address finder instance for chained calls.
Defines the bech32Hrp for the bech32 encoded addresses, required when generating addresses offline(with disableNodeSync()).
Param | Type | Description |
---|---|---|
bech32Hrp | string |
The bech32Hrp for the addresses |
Returns the address finder instance for chained calls.
Performs the operation.
Returns an array of public Address instances or an array of arrays with an Address and a bool, where the bool defines whether it's an internal address or not.
Gets balance on a given seed.
Sets the account index. This field is required.
Param | Type | Description |
---|---|---|
index | number |
The account index |
Returns the balance getter instance for chained calls.
Sets the initial address index. Defaults to 0 if the function isn't called.
Param | Type | Description |
---|---|---|
index | number |
The initial address index |
Returns the balance getter instance for chained calls.
Sets the gapLimit to specify how many addresses will be checked each round. If gapLimit amount of addresses in a row have no balance the BalanceGetter will return. Defaults to 20 if the function isn't called.
Param | Type | Description |
---|---|---|
gapLimit | number |
The initial address index |
Returns the balance getter instance for chained calls.
Performs the operation.
Returns a promise resolving to the account balance.
Gets a message by indexation key or identifier.
Param | Type | Description |
---|---|---|
index | string |
The indexation key |
Gets a list of message identifiers associated with the given indexation key.
Returns a promise resolving to the list of associated ids.
Gets the message object associated with the given identifier.
Param | Type | Description |
---|---|---|
id | string |
The message identifier |
Returns a Message object.
Gets the message raw data.
Param | Type | Description |
---|---|---|
id | string |
The message identifier |
Returns the message raw data as string.
Gets the children of the given message.
Param | Type | Description |
---|---|---|
id | string |
The message identifier |
Returns the list of message ids of the message children.
Gets the metadata of the given message.
Param | Type | Description |
---|---|---|
id | string |
The message identifier |
Returns a MessageMetadata object.
All fields are optional.
Field | Type | Description |
---|---|---|
automaticDisconnect | boolean |
Whether the MQTT broker should be automatically disconnected when all topics are unsubscribed or not. |
timeout | number |
MQTT connection timeout in secods |
useWs | boolean |
Defines if websockets should be used (true) or TCP (false) |
maxReconnectionAttempts | number |
Defines the maximum reconnection attempts before it returns an error |
port | number |
Defines the port to be used for the MQTT connection |
Field | Type | Description |
---|---|---|
jwt | string |
Optional JSON Web Token. |
basicAuthName | string |
Optional name for basic authentication |
basicAuthPassword | string |
Optional password for basic authentication |
Field | Type | Description |
---|---|---|
data | string |
Address as a Bech32 string |
Field | Type | Description |
---|---|---|
networkId | number |
Network identifier |
parents | string[] |
Message ids of the message references |
payload | Payload |
Message payload |
nonce | number |
Message nonce |
Field | Type | Description |
---|---|---|
message | Message |
Message |
messageId | string |
The message id |
Field | Type | Description |
---|---|---|
data | { type: 'Transaction', data: TransactionPayload } | { type: 'Indexation', data: IndexationPayload } | { type: 'Milestone', data: MilestonePayload} |
Payload data |
Field | Type | Description |
---|---|---|
essence | TransactionPayloadEssence |
Transaction essence |
unlock_blocks | UnlockBlock[] |
Unlock blocks |
- TransactionPayloadEssence
Field | Type | Description |
---|---|---|
inputs | Input[] |
Inputs |
outputs | Output[] |
Outputs |
payload | Payload | undefined |
Payload for chaining |
- Input
Field | Type | Description |
---|---|---|
type | 'UTXO' |
Input type identifier |
data | string |
The associated output id |
- Output
Field | Type | Description |
---|---|---|
type | 'SignatureLockedSingle' |
Output type identifier |
data | { address: string, amount: number } |
The output definition |
- UnlockBlock
Field | Type | Description |
---|---|---|
type | 'Signature' | 'Reference' |
Unlock block type identifier |
data | Ed25519SignatureUnlockBlock | number |
Unlock block data (signature type or reference index) |
- Ed25519SignatureUnlockBlock
Field | Type | Description |
---|---|---|
public_key | number[] |
Ed25519 public key |
signature | number[] |
Ed25519 signature |
Field | Type | Description |
---|---|---|
index | string |
Indexation key |
data | number[] |
Indexation data as byte array |
Field | Type | Description |
---|---|---|
essence | MilestoneEssence |
Milestone essence |
signatures | number[][] |
Milestone signatures |
- MilestoneEssence
Field | Type | Description |
---|---|---|
index | number |
Milestone index |
timestamp | number |
Timestamp |
parents | string[] |
Message ids of the messages the milestone references |
merkleProof | number[] |
Merkle proof |
nextPoWScore | number |
Next PoW score |
nextPoWScoreMilestoneIndex | number |
Milestone index at which the nextPoWScore will be used |
publicKeys | number[][] |
public keys |
Field | Type | Description |
---|---|---|
parents | string[] | undefined |
Message ids of the messages it references. getTips is used by default |
payload | PayloadDto |
Message payload |
Field | Type | Description |
---|---|---|
data | TransactionPayloadDto | IndexationPayloadDto |
Payload data |
Field | Type | Description |
---|---|---|
essence | TransactionPayloadEssenceDto |
Transaction essence |
unlockBlocks | UnlockBlockDto[] |
Unlock blocks |
- TransactionPayloadEssenceDto
Field | Type | Description |
---|---|---|
inputs | string[] |
Inputs |
outputs | Output[] |
Outputs |
payload | PayloadDto | undefined |
Payload for chaining |
- OutputDto
Field | Type | Description |
---|---|---|
address | string |
Output address |
amount | amount |
Output amount |
- UnlockBlockDto
Field | Type | Description |
---|---|---|
data | Ed25519SignatureUnlockBlockDto | number |
Unlock block data (signature type or reference index) |
- Ed25519SignatureUnlockBlockDto
Field | Type | Description |
---|---|---|
publicKey | number[] |
Ed25519 public key |
signature | number[] |
Ed25519 signature |
Field | Type | Description |
---|---|---|
index | string |
Indexation key |
data | Uint8Array |
Indexation data |
Field | Type | Description |
---|---|---|
address | string |
Bech32 encoded address |
balance | number |
Address balance |
dustAllowed | boolean |
Dust allowed |
Field | Type | Description |
---|---|---|
messageId | string |
Message identifier |
parents | string[] |
Message id of the messages it references |
isSolid | boolean |
Message solid state |
shouldPromote | boolean | undefined |
Indicates whether the message should be promoted or not |
shouldReattach | boolean | undefined |
Indicates whether the message should be reattached or not |
referencedByMilestoneIndex | number | undefined |
Index of the milestone that references this message |
ledgerInclusionState | string | undefined |
Ledger inclusion state |
Field | Type | Description |
---|---|---|
url | string |
Node url |
nodeinfo | NodeInfo |
NodeInfo |
Field | Type | Description |
---|---|---|
name | string |
Node name |
version | string |
Node version |
isHealthy | boolean |
Node health status |
networkId | string |
Node network identifier |
bech32HRP | string |
Bech32 HRP for this network |
minPoWScore | number |
Min PoW score |
messagesPerSecond | number |
Network stats: Messages per second in the network |
referencedMessagesPerSecond | number |
Network stats: Referenced messages per second |
referencedRate | number |
Network stats: referenced rate |
latestMilestoneTimestamp | number |
Timestamp of the latest milestone |
latestMilestoneIndex | number |
Index of the latest milestone |
confirmedMilestoneIndex | number |
Index of the confirmed milestone |
pruningIndex | number |
Pruning index |
features | string[] |
List of node features |
Field | Type | Description |
---|---|---|
messageId | string |
Id of the message associated with the output |
transactionId | string |
Id of the transaction associated with the output |
outputIndex | number |
Output index |
isSpent | boolean |
Output spent state |
address | string |
Output address |
amount | number |
Output amount |
Field | Type | Description |
---|---|---|
milestoneIndex | number |
Milestone index |
messageId | string |
Id of the message associated with the milestone |
timestamp | number |
Milestone timestamp |
Field | Type | Description |
---|---|---|
index | number |
Milestone index |
createdOutputs | string[] |
OutputIds from new created outputs |
consumedOutputs | string[] |
OutputIds from consumed outputs |
Field | Type | Description |
---|---|---|
receipt | receipt |
Receipt |
milestoneIndex | number |
Milestone index |
Field | Type | Description |
---|---|---|
milestoneId | string |
Milestone id |
amount | number |
Amount |