@nexajs/transaction
v24.11.1
Published
Manages transaction building and signing.
Downloads
267
Readme
NEXA.js Transaction
Manage the construction of a new or existing Transaction; as well as handle the unlocking (by use of redeem scripts) and authorize the transaction for on-chain broadcast.
The Transaction Builder represents a transaction internally and is used to build a transaction step-by-step. It can then be expressed as a hexadecimal string ready to be sent to a Nexa node and broadcast to the entire network.
The necessary steps to create a Transaction are:
- Add input(s)
- Add output(s)
- Set lock time (optional)
- Sign input(s)
Simple Transaction
import { Transaction } from '@nexajs/transaction'
// Provide one or more Locksmiths (e.g. Wallet Import Format WIF).
const locksmith = [
// TODO
]
// Initialize the transaction.
const tx = new Transaction()
// Add inputs.
tx.addInputs([{
// TODO
}])
// Add outputs.
tx.addOutputs([{
// TODO
}])
console.log(tx) // without signatures
// {
// inputs: [...],
// outputs: [...],
// }
// Sign the transaction (using an array of one or more Locksmiths).
tx.sign(locksmith)
console.log(tx) // with signatures
// {
// inputs: [...],
// outputs: [...],
// }
console.log(tx.hex) // in hexadecimal format (for broadcast via node)
// abc123...
TODO: Add more examples...