hive-tx v7
GitHub npm

Use

Transactions

A Transaction object holds operations, signatures, and expiration data.

Create a transaction

const tx = new Transaction()
const txLong = new Transaction({ expiration: 120_000 })

Expiration is in milliseconds. The default is 60000 (1 minute). The maximum is 86400000 (24 hours).

You can wrap an existing transaction object:

const tx = new Transaction({ transaction: rawTx })

Add an operation

addOperation is async. The first call gets chain properties and sets ref_block_num and ref_block_prefix.

await tx.addOperation('transfer', {
  from: 'sender',
  to: 'receiver',
  amount: '1.000 HIVE',
  memo: 'payment'
})

You can add more than one operation to the same transaction.

Sign

sign accepts one PrivateKey or an array of keys.

tx.sign(privateKey)
tx.sign([postingKey, activeKey])

If there is no transaction, sign throws an error. Call addOperation first.

Broadcast

const quick = await tx.broadcast()
const confirmed = await tx.broadcast(true)
ArgumentResult
false (default)The function returns after the node accepts the transaction. Status is unknown.
trueThe function waits until the transaction is in an irreversible block, or until the transaction expires.

If there is no signature, broadcast throws an error.

If a retry causes a duplicate transaction error, the library ignores that error.

Digest and transaction id

const { digest, txId } = tx.digest()

digest is a 32-byte hash. Use the digest to verify a signature. txId is the first 40 hex characters of the SHA-256 hash of the serialized transaction.

Add an external signature

Use addSignature when an external tool creates the signature. The signature must be a hex string with 130 characters.

tx.addSignature(hexSignature)

Status values

StatusMeaning
unknownThe library did not wait for a block, or the wait ended at expiration.
within_irreversible_blockThe transaction is in an irreversible block.
expired_irreversibleThe transaction expired.
too_oldThe transaction is too old for the node.