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([options])

Creates a new instance of the AccountManager.

ParamTypeDefaultDescription
[options]objectundefinedThe options to configure the account manager
[storagePath]stringundefinedThe path where the database file will be saved
[storagePassword]stringundefinedThe storage password
[outputConsolidationThreshold]number100The number of outputs an address must have to trigger the automatic consolidation process
[automaticOutputConsolidation]booleantrueDisables the automatic output consolidation if false
[syncSpentOutputs]booleanfalseEnables fetching spent output history on account sync
[persistEvents]booleanfalseEnables event persistence
[allowCreateMultipleEmptyAccounts]booleancodeEnables creating accounts with latest account being empty

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.clientOptionsClientOptionsundefinedThe 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

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 subaccount to another.

ParamTypeDefaultDescription
fromAccountAccountnullThe source account
toAccountAccountnullThe 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 has unused 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
optionsClientOptionsnullThe 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, address: string, message?: string, 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
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.

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()

Consolidate the outputs on all account addresses.

isLatestAddressUnused()

Determines whether the account has 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
optionsClientOptionsnullThe 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.

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)
[node]stringundefinedA node URL to connect to
[nodes]string[]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.