Skip to main content
Version: IOTA

Node.js API Reference

initLogger(config: LogOptions)

Initializes the logging system.

LogOptions

ParamTypeDefaultDescription
color_enabledbooleanundefinedWhether to enable colored output or not
outputsLogOutput[]undefinedThe log outputs

LogOutput

ParamTypeDefaultDescription
namestringundefined'stdout' or a path to a file
level_filterstring'info'The maximum log level that this output accepts
target_filtersstring[][]Filters on the log target (library and module names)

addEventListener(event, cb)

Adds a new event listener with a callback in the form of (err, data) => {}.

Supported event names:

  • ErrorThrown
  • BalanceChange
  • NewTransaction
  • ConfirmationStateChange
  • Reattachment
  • Broadcast
  • TransferProgress
  • MigrationProgress

AccountManager

constructor([ManagerOptions])

Creates a new instance of the AccountManager.

ParamTypeDefaultDescription
ManagerOptionsobjectundefinedThe options to configure the account manager

ManagerOptions

You can use any of the following parameters when constructing the ManagerOptions. All the parameters are optional.

ParamTypeDefaultDescription
storagePathstringundefinedThe path where the database file will be saved
storagePasswordstringundefinedThe storage password
outputConsolidationThresholdnumber100The number of outputs an address must have to trigger the automatic consolidation process
automaticOutputConsolidationbooleantrueDisables the automatic output consolidation if false
syncSpentOutputsbooleanfalseEnables fetching spent output history on account sync
persistEventsbooleanfalseEnables event persistence
allowCreateMultipleEmptyAccountsbooleanfalseEnables creating accounts with latest account being empty
skipPollingbooleanfalseEnables creating accounts without automatic polling (background syncing)
pollingIntervalnumber30Sets the polling interval in seconds

setStrongholdPassword(password): void

Sets the Stronghold password and initialises it.

ParamTypeDefaultDescription
passwordstringundefinedThe Stronghold snapshot password

changeStrongholdPassword(currentPassword, newPassword): void

Changes the Stronghold password.

ParamTypeDefaultDescription
currentPasswordstringundefinedThe current Stronghold password
newPasswordstringundefinedThe new Stronghold password

createAccount(account): Account

Creates a new account.

ParamTypeDefaultDescription
accountobject{}The account to be created
account.clientOptions[ClientOptions](#clientoptions)undefinedThe node configuration
[account.mnemonic]stringundefinedThe account BIP39 mnemonic
[account.alias]stringAccount ${index + 1}The account alias
[account.createdAt]stringthe current date and timeThe ISO 8601 date string of the account creation
[account.signerType]number1 = StrongholdThe account signer type. 1 = Stronghold, 2 = EnvMnemonic

getAccount(accountId)

Gets the account with the given identifier or index.

ParamTypeDefaultDescription
accountIdstring \| numbernullThe account identifier or account index

Returns the associated Account instance or undefined if the account wasn't found.

getAccountByAlias(alias)

Gets the account with the given alias (case-insensitive).

ParamTypeDefaultDescription
aliasstringnullThe account alias

Returns the associated Account instance or undefined if the account wasn't found.

getAccounts()

Gets all stored accounts.

Returns an array of Account objects.

removeAccount(accountId)

Removes the account with the given identifier or index.

ParamTypeDefaultDescription
accountIdstring \| numbernullThe account identifier or account index

startBackgroundSync(pollingInterval, automaticOutputConsolidation): Promise

Starts the background polling and MQTT monitoring.

ParamTypeDefaultDescription
pollingIntervalnumbernullThe polling interval in seconds
automaticOutputConsolidationbooleannullIf outputs should get consolidated automatically

stop_background_sync(): void

Stops the background polling and MQTT monitoring.

syncAccounts([options])

Synchronize all stored accounts with the Tangle.

ParamTypeDefaultDescription
[options]object{}The sync options
[options.addressIndex]numberlatest address indexThe index of the first account address to sync
[options.gapLimit]number10The number of addresses to check on each account sync

Returns a promise resolving to an array of SyncedAccount.

internalTransfer(fromAccount, toAccount, amount)

Transfers an amount from one sub-account to another.

ParamTypeDefaultDescription
fromAccount[Account](#account)nullThe source account
toAccount[Account](#account)nullThe destination account
amountnumberundefinedThe transfer amount

Returns a promise resolving to the transfer's Message.

backup(destination, password)

Backups the database.

ParamTypeDefaultDescription
destinationstringundefinedThe path to the backup file
passwordstringundefinedThe backup Stronghold password

Returns the full path to the backup file.

importAccounts(source)

Imports a database file.

ParamTypeDefaultDescription
sourcestringundefinedThe path to the backup file
passwordstringundefinedThe backup Stronghold password

isLatestAddressUnused()

Determines whether all accounts have unused their latest address after syncing with the Tangle.

Returns a promise resolving to the boolean value.

setClientOptions(options)

Updates the client options for all accounts.

ParamTypeDefaultDescription
options[ClientOptions](#clientoptions)nullThe new account client options

generateMigrationAddress(address)

Convert a Ed25519 to a Tryte migration address with checksum (last 9 Trytes)

ParamTypeDefaultDescription
addressstringnullBech32 encoded Ed25519 address

getBalanceChangeEvents([count, skip, fromTimestamp])

Gets the persisted balance change events.

ParamTypeDefaultDescription
[count]number0The number of events to return (0 to return all)
[skip]number0The number of events to skip
[fromTimestamp]numbernullFilter events that were stored after the given UTC timestamp

Event object: { indexationId: string, accountId: string, messageId?: string, remainder?: boolean, balanceChange: { spent: number, received: number } }

getBalanceChangeEventCount([fromTimestamp])

Gets the number of persisted balance change events.

ParamTypeDefaultDescription
[fromTimestamp]numbernullFilter events that were stored after the given UTC timestamp

getTransactionConfirmationEvents([count, skip, fromTimestamp])

Gets the persisted transaction confirmation change events.

ParamTypeDefaultDescription
[count]number0The number of events to return (0 to return all)
[skip]number0The number of events to skip
[fromTimestamp]numbernullFilter events that were stored after the given UTC timestamp

Event object: { indexationId: string, accountId: string, message: Message, confirmed: boolean }

getTransactionConfirmationEventCount([fromTimestamp])

Gets the number of persisted transaction confirmation change events.

ParamTypeDefaultDescription
[fromTimestamp]numbernullFilter events that were stored after the given UTC timestamp

getNewTransactionEvents([count, skip, fromTimestamp])

Gets the persisted new transaction events.

ParamTypeDefaultDescription
[count]number0The number of events to return (0 to return all)
[skip]number0The number of events to skip
[fromTimestamp]numbernullFilter events that were stored after the given UTC timestamp

Event object: { indexationId: string, accountId: string, message: Message }

getNewTransactionEventCount([fromTimestamp])

Gets the number of persisted new transaction events.

ParamTypeDefaultDescription
[fromTimestamp]numbernullFilter events that were stored after the given UTC timestamp

getReattachmentEvents([count, skip, fromTimestamp])

Gets the persisted transaction reattachment events.

ParamTypeDefaultDescription
[count]number0The number of events to return (0 to return all)
[skip]number0The number of events to skip
[fromTimestamp]numbernullFilter events that were stored after the given UTC timestamp

Event object: { indexationId: string, accountId: string, message: Message }

getReattachmentEventCount([fromTimestamp])

Gets the number of persisted transaction reattachment events.

ParamTypeDefaultDescription
[fromTimestamp]numbernullFilter events that were stored after the given UTC timestamp

getBroadcastEvents([count, skip, fromTimestamp])

Gets the persisted transaction broadcast events.

ParamTypeDefaultDescription
[count]number0The number of events to return (0 to return all)
[skip]number0The number of events to skip
[fromTimestamp]numbernullFilter events that were stored after the given UTC timestamp

Event object: { indexationId: string, accountId: string, message: Message }

getBroadcastEventCount([fromTimestamp])

Gets the number of persisted transaction broadcast events.

ParamTypeDefaultDescription
[fromTimestamp]numbernullFilter events that were stored after the given UTC timestamp

SyncedAccount

The result of a sync operation on an Account.

Account

id()

Returns the account's identifier.

index()

Returns the account's index.

alias()

Returns the account's alias.

balance(): AccountBalance

Returns the account's balance information object.

Balance object: { total: number, available: number, incoming: number, outgoing: number }

messageCount([type])

Returns the number of messages associated with the account.

ParamTypeDefaultDescription
[type]numbernullThe message type filter (Received = 1, Sent = 2, Failed = 3, Unconfirmed = 4, Value = 5)

listMessages([count, from, type])

Returns the account's messages.

ParamTypeDefaultDescription
[count]number0The number of messages to return (0 to return all)
[skip]number0The number of messages to skip
[type]numbernullThe message type filter (Received = 1, Sent = 2, Failed = 3, Unconfirmed = 4, Value = 5)

Message object: { confirmed: boolean, broadcasted: boolean, incoming: boolean, value: number }

listAddresses([unspent])

Returns the account's addresses.

ParamTypeDefaultDescription
[unspent]booleannullThe unspent status filter

Address object: { address: string, keyIndex: number }

sync([options])

Synchronizes the account with the Tangle.

ParamTypeDefaultDescription
[options]object{}The sync options
[options.addressIndex]numberlatest address indexThe index of the first address to sync
[options.gapLimit]number10The number of addresses to check

Returns a SyncedAccount instance.

send(address, amount[, options])

Send funds to the given address.

ParamTypeDefaultDescription
addressstringnullThe bech32 string of the transfer address
amountnumberundefinedThe transfer amount
optionsTransferOptionsundefinedThe transfer options

TransferOptions

ParamTypeDefaultDescription
remainderValueStrategyRemainderValueStrategynullThe strategy to use for the remainder value if any
indexation{ index: string, data?: Uint8Array }nullMessage indexation
skipSyncbooleanfalseSend transfer without synchronising the account first
outputKindOutputKindsignatureLockedSingleOutput kind

RemainderValueStrategy

changeAddress()

Send the remainder value to an internal address.

reuseAddress()

Send the remainder value to its original address.

accountAddress(address: string)

Send the remainder value to a specific address that must belong to the account.

getNodeInfo([url, auth]): NodeInfoWrapper

Gets information about the node.

ParamTypeDefaultDescription
urlstringNode from client optionsThe node url
authAuthundefinedThe node auth options

Returns the NodeInfoWrapper

NodeInfoWrapper

ParamTypeDefaultDescription
urlstringNode from client optionsThe node url
nodeinfoNodeInfonullThe node info
NodeInfo

All the values are for the NodeInfo are set by the nodes.

ParamTypeDefaultDescription
[name]stringnullThe node name
[version]stringnullThe node version
[isHealthy]booleannullIndicates if the node is healthy
[networkId]numbernullThe network ID
[bech32HRP]stringnullThe human-readable part of the bech32 string
[minPoWScore]numbernullThe node minimum proof of work score
[messagesPerSecond]numbernullThe node messages per second
[referencedMessagesPerSecond]numbernullThe node references per second
[referencedRate]numbernullThe node reference rate
[latestMilestoneTimestamp]numbernullThe node's latest milestone timestamp
[latestMilestoneIndex]numbernullThe node's latest milestone index
[confirmedMilestoneIndex]numbernullThe node's confirmed milestone index
[pruningIndex]numbernullThe node's pruning index
[features]string[]nullThe node's features.

retry(messageId)

Retries (promotes or reattaches) the given message.

ParamTypeDefaultDescription
messageIdstringnullThe message's identifier

reattach(messageId)

Reattach the given message.

ParamTypeDefaultDescription
messageIdstringnullThe message's identifier

promote(messageId)

Promote the given message.

ParamTypeDefaultDescription
messageIdstringnullThe message's identifier

consolidateOutputs([includeDustAllowanceOutputs])

Consolidate the outputs on all account addresses.

ParamTypeDefaultDescription
includeDustAllowanceOutputsbooleanfalseIf true, also consolidates dust allowance outputs

isLatestAddressUnused()

Determines whether the account has an unused latest address after syncing with the Tangle.

Returns a promise resolving to the boolean value.

setAlias(alias)

Updates the account alias.

ParamTypeDefaultDescription
aliasstringnullThe new account alias

setClientOptions(options)

Updates the account client options.

ParamTypeDefaultDescription
options[ClientOptions](#clientoptions)nullThe new account client options

getMessage(messageId)

Gets the message associated with the given identifier.

ParamTypeDefaultDescription
messageIdstringnullThe message's identifier

getAddress(addressBech32)

Gets the address object by its bech32 representation.

ParamTypeDefaultDescription
addressBech32stringnullThe address bech32 representation

generateAddress()

Generates a new unused address and returns it.

ParamTypeDefaultDescription
amountnumberundefinedThe amount of addresses

latestAddress()

Returns the latest address (the one with the biggest keyIndex).

getUnusedAddress()

Synchronizes the account addresses with the Tangle and returns the latest address in the account, which is an address without balance.

ClientOptions

FieldTypeDefaultDescription
[network]numberundefinedThe tangle network to connect to (Mainnet = 1, Devnet = 1, Comnet = 3)
[primaryNode]`NodeUrlNode`undefinedA node URL to alway connect to first
[primaryPoWNode]`NodeUrlNode`undefinedA node URL to alway connect to first when using remote PoW, will be used before primaryNode
[node]`NodeUrlNode`undefinedA node URL to connect to
[nodes]`NodeUrlNode[]`undefinedA list node URL to connect to
[quorumSize]numberundefinedIf multiple nodes are provided, quorum size determines the number of nodes to query to check for quorum.
[quorumThreshold]numberundefinedMinimum number of nodes from the quorum pool that need to agree to consider a result true.
[localPow]booleantrueWhether to use local or remote PoW.
[MqttBrokerOptions]MqttBrokerOptionsundefinedOptions for the MQTT broker

MqttBrokerOptions

All fields are optional.

FieldTypeDescription
automaticDisconnectbooleanWhether the MQTT broker should be automatically disconnected when all topics are unsubscribed or not.
timeoutnumberMQTT connection timeout in seconds
useWsbooleanDefines if websockets should be used (true) or TCP (false)
maxReconnectionAttemptsnumberDefines the maximum reconnection attempts before it returns an error
portnumberDefines the port to be used for the MQTT connection

Auth

FieldTypeDefaultDescription
[jwt]stringundefinedOptional JSON Web Token.
[username]stringundefinedOptional name for basic authentication
[password]stringundefinedOptional password for basic authentication

Node

NodeUrl = string

FieldTypeDefaultDescription
[url]NodeUrlundefinedNode url
[auth]AuthundefinedOptional authentication options
[disabled]booleanfalseOptional password for basic authentication

OutputKind

Possible output kinds.

FieldTypeDefaultDescription
[signatureLockedSingle]stringnullDefault output type
[signatureLockedDustAllowance]stringnullOutput type to enable receiving dust on an address