Skip to content

Transaction API Reference

Transaction

Construction Examples:

  • tx(0x0200000001…)
  • tx[ "inputs": …, "outputs": ]

→ See the Transactions guide for more options.

Coerces from:

  • Bytes – raw transaction serialization
  • Array – transaction construction fields (see tx())
  • Psbt – as the unsigned_tx

Underlying Type: bitcoin::Transaction

tx()

txid Txid

wtxid Hash

version Int

locktime Int

inputs Array<TxIn>

outputs Array<TxOut>

weight Int

vsize Int

size Int

txid()

tx::sighash()

tx::sighash(
  tx: Transaction,
  input_index: Int,
  utxos: Array<TxOut>,
  sighash_ty: Bytes<1>|Int|String = SIGHASH_ALL,
  tap_leaf: Script|Miniscript<Tap>|Policy|TapLeafHash = None
) -> Bytes

tx::sign()

tx::sign(
  tx: Transaction,
  utxos: Array<TxOut>,
  keys: SecKey|Array<SecKey>,
  sighash_ty: Bytes<1>|Int|String = SIGHASH_ALL,
  inputs_fields: Array = None,
) -> Transaction

Sign all tx inputs using the provided keys.

Also see: psbt::sign()

tx::fee()

tx::fee(tx: Transaction, utxos: Array<TxOut>) -> Int

Calculate the tx fee given the utxos spent by it.

Errors:

  • If the number of utxos doesn't match the number of tx inputs
  • If output amount > input amount
  • If integer overflow occurs when adding UTXO amounts (uses signed i64, can represent up to ~92 billion BTC)

Also see: psbt::fee()

tx::with_witness()

tx::with_witness(tx: Transaction, witnesses: Array<Array<Bytes>>) -> Transaction
tx::with_witness(tx: Transaction, witnesses: Array<Int:Array<Bytes>>) -> Transaction

tx::strip_witness()

tx::strip_witness(Transaction) -> Transaction

Txid

TxIn

prevout OutPoint

sequence Int

witness Array<Bytes>

script_sig Script

TxOut

script_pubkey Script

amount Int

OutPoint

txid Txid

vout Int

SIGHASH_DEFAULT Bytes

SIGHASH_DEFAULT = 0x00

SIGHASH_ALL Bytes

SIGHASH_ALL = 0x01

SIGHASH_NONE Bytes

SIGHASH_NONE = 0x02

SIGHASH_SINGLE Bytes

SIGHASH_SINGLE = 0x03

SIGHASH_ANYONECANPAY_ALL Bytes

SIGHASH_ANYONECANPAY_ALL = 0x81

SIGHASH_ANYONECANPAY_NONE Bytes

SIGHASH_ANYONECANPAY_NONE = 0x82

SIGHASH_ANYONECANPAY_SINGLE Bytes

SIGHASH_ANYONECANPAY_SINGLE = 0x83

DUST_AMOUNT Int

DUST_AMOUNT = 330

DUST_TR Int

DUST_TR = 330

DUST_WSH Int

DUST_WSH = 330

DUST_WPKH Int

DUST_WPKH = 294

DUST_LEGACY Int

DUST_LEGACY = 546

DUST_P2A Int

DUST_P2A = 240

ENABLE_RBF Bytes

ENABLE_RBF = 0xFFFFFFFD