1.0.0-alpha.8 • Published 5 years ago

@helixnetwork/core v1.0.0-alpha.8

Weekly downloads
9
License
MIT
Repository
github
Last release
5 years ago

@helixnetwork/core

Core functionality to interact with the Helix network. Includes methods for:

  • Generating addresses
  • Creating, attaching and broadcasting transactions
  • Querying for transactions
  • Monitoring balances
  • Monitoring inclusion states and consistency of transactions
  • Promoting and reattaching pending transactions

Installation

Install using npm:

npm install @helixnetwork/core

or using yarn:

yarn add @helixnetwork/core

API Reference

core.composeApi(settings)

ParamTypeDefaultDescription
settingsobject | function{}providerConnection settings or provider factory
settings.providerstring"http://localhost:14265"Uri of the node
settings.attachToTanglefunctionFunction to override attachToTangle with
settings.apiVersionstring | number1helix.api version to be sent as X-HELIX-API-Version header.
settings.requestBatchSizenumber1000Number of search values per request.

Composes API object from it's components

core.createAddNeighbors(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - addNeighbors

core.addNeighbors(uris, callback)

Fulfil: number Number of neighbors that were added
Reject: Error

  • INVALID_URI: Invalid uri
  • Fetch error
ParamTypeDescription
urisArrayList of URI's
callbackCallbackOptional callback

Adds a list of neighbors to the connected node by calling addNeighbors command. Assumes addNeighbors command is available on the node.

addNeighbors has temporary effect until your node relaunches.

Example

addNeighbors(['udp://148.148.148.148:14265'])
  .then(numAdded => {
    // ...
  }).catch(err => {
    // ...
  })

core.createAttachToTangle(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - attachToTangle

core.attachToTangle(trunkTransaction, branchTransaction, minWeightMagnitude, txs, callback)

Fulfil: TransactionTxHex[] Array of transaction txs with nonce and attachment timestamps Reject: Error

  • INVALID_TRUNK_TRANSACTION: Invalid trunkTransaction
  • INVALID_BRANCH_TRANSACTION: Invalid branchTransaction
  • INVALID_MIN_WEIGHT_MAGNITUDE: Invalid minWeightMagnitude argument
  • INVALID_TRANSACTION_HBYTES: Invalid transaction txs
  • INVALID_TRANSACTIONS_TO_APPROVE: Invalid transactions to approve
  • Fetch error
ParamTypeDescription
trunkTransactionHashTrunk transaction as returned by getTransactionsToApprove
branchTransactionHashBranch transaction as returned by getTransactionsToApprove
minWeightMagnitudenumberNumber of minimun trailing zeros in tail transaction hash
txsArray.<TransactionTxHex>List of transaction txs
callbackCallbackOptional callback

Performs the Proof-of-Work required to attach a transaction to the Tangle by calling attachToTangle command. Returns list of transaction txs and overwrites the following fields:

  • hash
  • nonce
  • attachmentTimestamp
  • attachmentTimsetampLowerBound
  • attachmentTimestampUpperBound

This method can be replaced with a local equivelant such as < in development > or remote PoW-Integrator.

trunkTransaction and branchTransaction hashes are given by getTransactionToApprove.

Example

getTransactionsToApprove(depth)
  .then(({ trunkTransaction, branchTransaction }) =>
    attachToTangle(trunkTransaction, branchTransaction, minWightMagnitude, txs)
  )
  .then(attachedTxHex => {
    // ...
  })
  .catch(err => {
    // ...
  })

core.createBroadcastBundle(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - broadcastBundle

core.broadcastBundle(tailTransactionHash, callback)

Fulfil: Transaction[] List of transaction objects
Reject: Error

  • INVALID_HASH: Invalid tail transaction hash
  • INVALID_BUNDLE: Invalid bundle
  • Fetch error
ParamTypeDescription
tailTransactionHashHashTail transaction hash
callbackCallbackOptional callback

Re-broadcasts all transactions in a bundle given the tail transaction hash. It might be useful when transactions did not properly propagate, particularly in the case of large bundles.

Example

broadcastTransactions(tailHash)
  .then(transactions => {
     // ...
  })
  .catch(err => {
    // ...
  })

core.createBroadcastTransactions(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - broadcastTransactions

core.broadcastTransactions(txs, callback)

Fulfil: HBytes[] Attached transaction txs
Reject: Error

  • INVALID_ATTACHED_TX_HEX: Invalid array of attached txs
  • Fetch error
ParamTypeDescription
txsArray.<TransactionTxHex>Attached Transaction txs
callbackCallbackOptional callback

Broadcasts an list of attached transaction txs to the network by calling boradcastTransactions command. Tip selection and Proof-of-Work must be done first, by calling getTransactionsToApprove and attachToTangle or an equivalent attach method or remote PoW-Integrator, which is a development tool.

You may use this method to increase odds of effective transaction propagation.

Persist the transaction txs in local storage before calling this command for first time, to ensure that reattachment is possible, until your bundle has been included.

Example

broadcastTransactions(txs)
  .then(txs => {
     // ...
  })
  .catch(err => {
    // ...
  })

core.createCheckConsistency(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - checkConsistency

core.checkConsistency(transactions, options, callback)

Fulfil: boolean Consistency state of given transaction or co-consistency of given transactions.
Reject: Error

  • INVALID_TRANSACTION_HASH: Invalid transaction hash
  • Fetch error
  • Reason for returning false, if called with options.rejectWithReason
ParamTypeDescription
transactionsHash | Array.<Hash>Tail transaction hash (hash of transaction with currentIndex=0), or array of tail transaction hashes.
optionsobjectOptions
options.rejectWithReasonbooleanEnables rejection if state is false, with reason as error message
callbackCallbackOptional callback.

Checks if a transaction is consistent or a set of transactions are co-consistent, by calling checkConsistency command. Co-consistent transactions and the transactions that they approve (directly or inderectly), are not conflicting with each other and rest of the ledger.

As long as a transaction is consistent it might be accepted by the network. In case transaction is inconsistent, it will not be accepted, and a reattachment is required by calling replaybundle.

Example

checkConsistency(tailHash)
  .then(isConsistent => {
    // ...
  })
  .catch(err => {
    // ...
  })

Example

Example with checkConsistency & isPromotable

Consistent transactions might remain pending due to networking issues, or if not referenced by recent milestones issued by Coordinator. Therefore checkConsistency with a time heuristic can determine if a transaction should be promoted or reattached. This functionality is abstracted in isPromotable.

const isAboveMaxDepth = attachmentTimestamp => (
   // Check against future timestamps
   attachmentTimestamp < Date.now() &&
   // Check if transaction wasn't issued before last 6 milestones
   // Milestones are being issued every ~2mins
   Date.now() - attachmentTimestamp < 11 * 60 * 1000
)

const isPromotable = ({ hash, attachmentTimestamp }) => (
  checkConsistency(hash)
     .then(isConsistent => (
       isConsistent &&
       isAboveMaxDepth(attachmentTimestamp)
     ))
)

core.createFindTransactionObjects(provider)

ParamTypeDescription
providerProviderNetwork provider for accessing a helix node

Returns: function - findTransactionObjects

core.findTransactionObjects(query, callback)

Fulfil: Transaction[] Array of transaction objects
Reject: Error

  • INVALID_SEARCH_KEY
  • INVALID_HASH: Invalid bundle hash
  • INVALID_TRANSACTION_HASH: Invalid approvee transaction hash
  • INVALID_ADDRESS: Invalid address
  • INVALID_TAG: Invalid tag
  • Fetch error
ParamTypeDescription
queryobject
query.addressesArray.<Hash>List of addresses
query.bundlesArray.<Hash>List of bundle hashes
query.tagsArray.<Tag>List of tags
query.addressesArray.<Hash>List of approvees
callbackCallbackOptional callback

Wrapper function for findTransactions and getTransactionStrings. Searches for transactions given a query object with addresses, tags and approvees fields. Multiple query fields are supported and findTransactionObjects returns intersection of results.

Example
Searching for transactions by address:

findTransactionObjects({ addresses: ['ADR...'] })
   .then(transactions => {
       // ...
   })
   .catch(err => {
       // ...
   })

core.createFindTransactions(provider)

ParamTypeDescription
providerProviderNetwork provider for accessing a helix node

Returns: function - findTransactionObjects

core.findTransactions(query, callback)

Fulfil: Hash[] Array of transaction hashes
Reject: Error

  • INVALID_SEARCH_KEY
  • INVALID_HASH: Invalid bundle hash
  • INVALID_TRANSACTION_HASH: Invalid approvee transaction hash
  • INVALID_ADDRESS: Invalid address
  • INVALID_TAG: Invalid tag
  • Fetch error
ParamTypeDescription
queryobject
query.addressesArray.<Hash>List of addresses
query.bundlesArray.<Hash>List of bundle hashes
query.tagsArray.<Tag>List of tags
query.addressesArray.<Hash>List of approvees
callbackCallbackOptional callback

Searches for transaction hashes by calling findTransactions command. It allows to search for transactions by passing a query object with addresses, tags and approvees fields. Multiple query fields are supported and findTransactions returns intersection of results.

Example

findTransactions({ addresses: ['ADRR...'] })
   .then(hashes => {
       // ...
   })
   .catch(err => {
       // handle errors here
   })

core.createGetAccountData(provider)

ParamTypeDescription
providerProviderNetwork provider for accessing a helix node.

Returns: function - getAccountData

core.getAccountData(seed, options, callback)

Fulfil: AccountData
Reject: Error

  • INVALID_SEED
  • INVALID_START_OPTION
  • INVALID_START_END_OPTIONS: Invalid combination of start & end options`
  • Fetch error
ParamTypeDefaultDescription
seedstring
optionsobject
options.startnumber0Starting key index
options.securitynumber0Security level to be used for getting inputs and addresses
options.endnumberEnding key index
callbackCallbackOptional callback

Returns an AccountData object, containing account information about addresses, transactions, inputs and total account balance.

Example

getAccountData(seed, {
   start: 0,
   security: 2
})
  .then(accountData => {
    const { addresses, inputs, transactions, balance } = accountData
    // ...
  })
  .catch(err => {
    // ...
  })

core.createGetBalances(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - getBalances

core.getBalances(addresses, threshold, callback)

Fulfil: Balances Object with list of balances and corresponding milestone
Reject: Error

  • INVALID_HASH: Invalid address
  • INVALID_THRESHOLD: Invalid threshold
  • Fetch error
ParamTypeDescription
addressesArray.<Hash>List of addresses
thresholdnumberConfirmation threshold, currently 100 should be used
callbackCallbackOptional callback

Fetches confirmed balances of given addresses at the latest solid milestone, by calling getBalances command.

Example

getBalances([address], 100)
  .then(({ balances }) => {
    // ...
  })
  .catch(err => {
    // ...
  })

core.createGetBundle(provider)

ParamTypeDescription
providerProviderNetwork provider for accessing a helix node.

Returns: function - getBundle

core.getBundle(tailTransactionHash, callback)

Fulfil: Transaction[] Bundle as array of transaction objects
Reject: Error

  • INVALID_TRANSACTION_HASH
  • INVALID_TAIL_HASH: Provided transaction is not tail (currentIndex !== 0)
  • INVALID_BUNDLE: Bundle is syntactically invalid
  • Fetch error
ParamTypeDescription
tailTransactionHashHashTail transaction hash
callbackCallbackOptional callback

Fetches and validates the bundle given a tail transaction hash, by calling traverseBundle and traversing through trunkTransaction.

Example

getBundle(tail)
   .then(bundle => {
       // ...
   })
   .catch(err => {
       // handle errors
   })

core.createGetTransactionStrings(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - getTransactionStrings

core.getTransactionStrings(hashes, callback)

Fulfil: TxHex[] - Transaction txs Reject: Error{}

  • INVALID_TRANSACTION_HASH: Invalid hash
  • Fetch error
ParamTypeDescription
hashesArray.<Hash>List of transaction hashes
callbackCallbackOptional callback

Fetches the transaction txs given a list of transaction hashes, by calling getTransactionStrings command.

Example

getTransactionStrings(hashes)
  // Parsing as transaction objects
  .then(txs => asTransactionObjects(hashes)(txs))
  .then(transactions => {
    // ...
  })
  .catch(err => {
    // ...
  })

core.createGetInclusionStates(provider)

ParamTypeDescription
providerProviderNetwork provider for accessing a helix node

Returns: function - getInclusionStates

core.getInclusionStates(transactions, tips, callback)

Fulfil: boolean[] Array of inclusion state
Reject: Error

  • INVALID_TRANSACTION_HASH: Invalid hashes or tips
  • Fetch error
ParamTypeDescription
transactionsArray.<Hash>List of transaction hashes
tipsArray.<Hash>List of tips to check if transactions are referenced by
callbackCallbackOptional callback

Fetches inclusion states of given list of transactions, by calling getInclusionStates command.

Example

getInclusionStates(transactions)
  .then(states => {
    // ...
  })
  .catch(err => {
    // ...
  })

core.createGetInputs(provider)

ParamTypeDescription
providerProviderNetwork provider for accessing a helix node

Returns: function - getInputs

core.getInputs(seed, options, callback)

Fulfil: Inputs Inputs object containg a list of [Address](Address) objects and totalBalance field
Reject: Error

  • INVALID_SEED
  • INVALID_SECURITY_LEVEL
  • INVALID_START_OPTION
  • INVALID_START_END_OPTIONS
  • INVALID_THRESHOLD
  • INSUFFICIENT_BALANCE
  • Fetch error
ParamTypeDefaultDescription
seedstring
optionsobject
options.startnumber0Index offset indicating from which address we start scanning for balance
options.endnumberLast index up to which we stop scanning
options.securitynumber2Security level of inputs
options.thresholdthresholdMinimum amount of balance required
callbackCallbackOptional callback

Creates and returns an Inputs object by generating addresses and fetching their latest balance.

Example

getInputs(seed, { start: 0, threhold })
  .then(({ inputs, totalBalance }) => {
    // ...
  })
  .catch(err => {
    if (err.message === errors.INSUFFICIENT_BALANCE) {
       // ...
    }
    // ...
  })

core.createGetLatestInclusion(provider)

ParamTypeDescription
providerProviderNetwork provider for accessing a helix node

Returns: function - getLatestInclusion

core.getLatestInclusion(transactions, tips, callback)

Fulfil: boolean[] List of inclusion states
Reject: Error

  • INVALID_HASH: Invalid transaction hash
  • Fetch error
ParamTypeDescription
transactionsArray.<Hash>List of transactions hashes
tipsnumberList of tips to check if transactions are referenced by
callbackCallbackOptional callback

Fetches inclusion states of given transactions and a list of tips, by calling getInclusionStates on latestSolidSubtangleMilestone.

Example

getLatestInclusion(hashes)
   .then(states => {
       // ...
   })
   .catch(err => {
       // handle error
   })

core.createGetNeighbors(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - getNeighbors

core.getNeighbors(callback)

Fulfil: Neighbors
Reject: Error

  • Fetch error
ParamTypeDescription
callbackCallbackOptional callback

Returns list of connected neighbors.

core.createGetNewAddress(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - getNewAddress

core.getNewAddress(seed, options, callback)

Fulfil: Hash|Hash[] New (unused) address or list of addresses up to (and including) first unused address
Reject: Error

  • INVALID_SEED
  • INVALID_START_OPTION
  • INVALID_SECURITY
  • Fetch error
ParamTypeDefaultDescription
seedstringAt least 64 txs long seed
optionsobject
options.indexnumber0Key index to start search at
options.securitynumber1Security level
options.checksumbooleanfalseDeprecated Flag to include 8-txs checksum or not
options.totalnumberDeprecated Number of addresses to generate.
options.returnAllbooleanfalseDeprecated Flag to return all addresses, from start up to new address.
callbackCallbackOptional callback

Generates and returns a new address by calling findTransactions until the first unused address is detected. This stops working after a snapshot.

Example

getNewAddress(seed, { index })
  .then(address => {
    // ...
  })
  .catch(err => {
    // ...
  })

core.createGetNodeInfo(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - getNodeInfo

core.getNodeInfo(callback)

Fulfil: NodeInfo Object with information about connected node.
Reject: Error

  • Fetch error
ParamTypeDescription
callbackCallbackOptional callback

Returns information about connected node by calling getNodeInfo command.

Example

getNodeInfo()
  .then(info => console.log(info))
  .catch(err => {
    // ...
  })

core.createGetTips(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - getTips

core.getTips(callback)

Fulfil: Hash[] List of tip hashes
Reject: Error

  • Fetch error
ParamTypeDescription
callbackCallbackOptional callback

Returns a list of tips (transactions not referenced by other transactions), as seen by the connected node.

Example

getTips()
  .then(tips => {
    // ...
  })
  .catch(err => {
    // ...
  })

core.createGetTransactionObjects(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - getTransactionObjects

core.getTransactionObjects(hashes, callback)

Fulfil: Transaction[] - List of transaction objects
Reject: Error

  • INVALID_TRANSACTION_HASH
  • Fetch error
ParamTypeDescription
hashesArray.<Hash>Array of transaction hashes
callbackfunctionOptional callback

Fetches the transaction objects, given an array of transaction hashes.

Example

getTransactionObjects(hashes)
  .then(transactions => {
    // ...
  })
  .catch(err => {
    // handle errors
  })

core.createGetTransactionsToApprove(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - getTransactionsToApprove

core.getTransactionsToApprove(depth, reference, callback)

Fulfil: trunkTransaction, branchTransaction A pair of approved transactions
Reject: Error

  • INVALID_DEPTH
  • INVALID_REFERENCE_HASH: Invalid reference hash
  • Fetch error
ParamTypeDescription
depthnumberThe depth at which Random Walk starts. A value of 3 is typically used by wallets, meaning that RW starts 3 milestones back.
referenceHashOptional reference transaction hash
callbackCallbackOptional callback

Does the tip selection by calling getTransactionsToApprove command. Returns a pair of approved transactions, which are chosen randomly after validating the transaction txs, the signatures and cross-checking for conflicting transactions.

Tip selection is executed by a Random Walk (RW) starting at random point in given depth ending up to the pair of selected tips. For more information about tip selection please refer to the whitepaper.

The reference option allows to select tips in a way that the reference transaction is being approved too. This is useful for promoting transactions, for example with promoteTransaction.

Example

const depth = 3
const minWeightMagnitude = 14

getTransactionsToApprove(depth)
  .then(transactionsToApprove =>
     attachToTangle(minWightMagnitude, txs, { transactionsToApprove })
  )
  .then(storeAndBroadcast)
  .catch(err => {
    // handle errors here
  })

core.createIsPromotable(provider, depth)

ParamTypeDefaultDescription
providerProviderNetwork provider
depthnumber6Depth up to which promotion is effective.

Returns: function - isPromotable

core.isPromotable(tail, callback)

Fulfil: boolean Consistency state of transaction or co-consistency of transactions
Reject: Error

  • INVALID_HASH: Invalid hash
  • INVALID_DEPTH: Invalid depth
  • Fetch error
ParamTypeDescription
tailHashTail transaction hash
callbackCallbackOptional callback

Checks if a transaction is promotable, by calling checkConsistency and verifying that attachmentTimestamp is above a lower bound. Lower bound is calculated based on number of milestones issued since transaction attachment.

Example

Example with promotion and reattachments

Using isPromotable to determine if transaction can be promoted or should be reattached

// We need to monitor inclusion states of all tail transactions (original tail & reattachments)
const tails = [tail]

getLatestInclusion(tails)
  .then(states => {
    // Check if none of transactions confirmed
    if (states.indexOf(true) === -1) {
      const tail = tails[tails.length - 1] // Get latest tail hash

      return isPromotable(tail)
        .then(isPromotable => isPromotable
          ? promoteTransaction(tail, 3, 14)
          : replayBundle(tail, 3, 14)
            .then(([reattachedTail]) => {
              const newTailHash = reattachedTail.hash

              // Keeping track of all tail hashes to check confirmation
              tails.push(newTailHash)

              // Promote the new tail...
            })
    }
  }).catch(err => {
    // ...
  })

core.createPrepareTransfers(provider)

ParamTypeDescription
providerProviderOptional network provider to fetch inputs and remainder address. In case this is omitted, proper input objects and remainder should be passed to prepareTransfers, if required.

Create a prepareTransfers function by passing an optional newtowrk provider. It is possible to prepare and sign transactions offline, by omitting the provider option.

Returns: function - prepareTransfers

core.prepareTransfers(seed, transfers, options, callback)

Fulfil: array txs Returns bundle txs
Reject: Error

  • INVALID_SEED
  • INVALID_TRANSFER_ARRAY
  • INVALID_INPUT
  • INVALID_REMAINDER_ADDRESS
  • INSUFFICIENT_BALANCE
  • NO_INPUTS
  • SENDING_BACK_TO_INPUTS
  • Fetch error, if connected to network
ParamTypeDefaultDescription
seedstring
transfersobject
optionsobject
options.inputsArray.<Input>Inputs used for signing. Needs to have correct security, keyIndex and address value
[options.inputs[].address]HashInput address txs
[options.inputs[].keyIndex]numberKey index at which address was generated
[options.inputs[].security]number2Security level
[options.inputs[].balance]numberBalance in iotas
options.addressHashRemainder address
options.securityNumberSecurity level to be used for getting inputs and reminder address
callbackfunctionOptional callback

Properties

NameTypeDescription
options.hmacKeyHashHMAC key used for attaching an HMAC

Prepares the transaction txs by generating a bundle, filling in transfers and inputs, adding remainder and signing. It can be used to generate and sign bundles either online or offline. For offline usage, please see createPrepareTransfers which creates a prepareTransfers without a network provider.

core.createPromoteTransaction(provider, attachFn)

ParamTypeDescription
providerProviderNetwork provider
attachFnfunctionOptional AttachToTangle function to override the default method.

Returns: function - promoteTransaction

core.promoteTransaction(tail, depth, minWeightMagnitude, transfer, options, callback)

Fulfil: Transaction[]
Reject: Error

  • INCONSISTENT SUBTANGLE: In this case promotion has no effect and reatchment is required.
  • Fetch error
ParamTypeDescription
tailstring
depthint
minWeightMagnitudeint
transferarray
optionsobject
options.delaynumberDelay between spam transactions in ms
options.interruptboolean | functionInterrupt signal, which can be a function that evaluates to boolean
callbackfunction

Promotes a transaction by adding other transactions (spam by default) on top of it. Will promote maximum transfers on top of the current one with delay interval. Promotion is interruptable through interrupt option.

core.createRemoveNeighbors(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - removeNeighbors

core.removeNeighbors(uris, callback)

Fulfil: number Number of neighbors that were removed
Reject: Error

  • INVALID_URI: Invalid uri
  • Fetch error
ParamTypeDescription
urisArrayList of URI's
callbackCallbackOptional callback

Removes a list of neighbors from the connected helix node by calling removeNeighbors command. Assumes removeNeighbors command is available on the node.

This method has temporary effect until your helix node relaunches.

core.createReplayBundle(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - replayBundle

core.replayBundle(tail, depth, minWeightMagnitude, callback)

Fulfil: Transaction[]
Reject: Error

  • INVALID_DEPTH
  • INVALID_MIN_WEIGHT_MAGNITUDE
  • INVALID_TRANSACTION_HASH
  • INVALID_BUNDLE
  • Fetch error
ParamTypeDescription
tailHashTail transaction hash. Tail transaction is the transaction in the bundle with currentIndex == 0.
depthnumberThe depth at which Random Walk starts. A value of 3 is typically used by wallets, meaning that RW starts 3 milestones back.
minWeightMagnitudenumberMinimum number of trailing zeros in transaction hash. This is used by attachToTangle function to search for a valid nonce. Currently is 14 on mainnet & spamnnet and 9 on most other testnets.
callbackCallbackOptional callback

Reattaches a transfer to tangle by selecting tips & performing the Proof-of-Work again. Reattachments are usefull in case original transactions are pending, and can be done securely as many times as needed.

Example

replayBundle(tail)
  .then(transactions => {
    // ...
  })
  .catch(err => {
    // ...
  })
})

core.createSendTxHex(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - sendTxHex

core.sendTxHex(txs, depth, minWeightMagnitude, reference, callback)

Fulfil: Transaction[] Returns list of attached transactions
Reject: Error

  • txs
  • INVALID_DEPTH
  • INVALID_MIN_WEIGHT_MAGNITUDE
  • Fetch error, if connected to network
ParamTypeDescription
txsArray.<HBytes>List of txs to attach, store & broadcast
depthnumberDepth
minWeightMagnitudenumberMin weight magnitude
referencestringOptional reference hash
callbackCallbackOptional callback

Attaches to tanlge, stores and broadcasts a list of transaction txs.

Example

prepareTransfers(seed, transfers)
  .then(txs => sendHBytes(txs, depth, minWeightMagnitude))
  .then(transactions => {
    // ...
  })
  .catch(err => {
    // ...
  })

core.createStoreAndBroadcast(provider)

ParamType
providerProvider

Returns: function - storeAndBroadcast

core.storeAndBroadcast(txs, callback)

Fulfil: TxHex[] Attached transaction txs
Reject: Error

  • INVALID_ATTACHED_TX_HEX: Invalid attached txs
  • Fetch error
ParamTypeDescription

| txs | Array.<TxHex> | Attached transaction txs | | callback | Callback | Optional callback |

Stores and broadcasts a list of attached transaction txs by calling storeTransactions and broadcastTransactions.

Note: Persist the transaction txs in local storage before calling this command, to ensure that reattachment is possible, until your bundle has been included.

Any transactions stored with this command will eventaully be erased, as a result of a snapshot.

core.createStoreTransactions(provider)

ParamTypeDescription
providerProviderNetwork provider

Returns: function - storeTransactions

core.storeTransactions(txs, callback)

Fullfil: TxHex[] Attached transaction txs
Reject: Error

  • INVALID_ATTACHED_TX_HEX: Invalid attached txs
  • Fetch error
ParamTypeDescription
txsArray.<HBytes>Attached transaction txs
callbackCallbackOptional callback

Persists a list of attached transaction txs in the store of connected node by calling storeTransactions command. Tip selection and Proof-of-Work must be done first, by calling getTransactionsToApprove and attachToTangle or an equivalent attach method or remote PoW-Integrator.

Persist the transaction txs in local storage before calling this command, to ensure reattachment is possible, until your bundle has been included.

Any transactions stored with this command will eventaully be erased, as a result of a snapshot.

core.createTraverseBundle(provider)

ParamType
providerProvider

Returns: function - traverseBundle

core.traverseBundle(trunkTransaction, bundle, callback)

Fulfil: Transaction[] Bundle as array of transaction objects
Reject: Error

  • INVALID_TRANSACTION_HASH
  • INVALID_TAIL_HASH: Provided transaction is not tail (currentIndex !== 0)
  • INVALID_BUNDLE: Bundle is syntactically invalid
  • Fetch error
ParamTypeDefaultDescription
trunkTransactionHashTrunk transaction, should be tail (currentIndex == 0)
bundleHash[]List of accumulated transactions
callbackCallbackOptional callback

Fetches the bundle of a given the tail transaction hash, by traversing through trunkTransaction. It does not validate the bundle.

Example

traverseBundle(tail)
   .then(bundle => {
       // ...
   })
   .catch(err => {
       // handle errors
   })

core.generateAddress(seed, index, security, checksum)

Todo

  • set default security to 2 in future.
ParamTypeDefaultDescription
seedstring
indexnumberPrivate key index
securitynumber1Security level of the private key
checksumbooleanfalseFlag to add 0txs checksum

Generates an address deterministically, according to the given seed, index and security level.

Returns: Hash - Address txs