The wallet signs the 50,000-sat payment and sends it as bytes. A node decodes those bytes, finds the UTXO named by the input, and runs the scripts that authorize the spend.
Find the UTXO the input spends
Input 0 names the 100,000-sat funding UTXO by its outpoint. Read that as “output 0 of the funding transaction.” The recipient and change amounts are recorded as two new UTXOs.
The input gives the outpoint and the unlocking script (scriptSig). The UTXO supplies its 100,000-sat value and the locking script (scriptPubKey) that CashVM checks.
Use bigint for BCH amounts in JavaScript and TypeScript, with satoshis as the unit. A payment of 50,000 sats is 50_000n.
Transaction byte format
The signed payment takes 219 bytes to describe how 100,000 sats are spent. Satoshis measure value. Bytes measure the size of the message. In hex, two digits represent one byte.
- Recipient UTXO · Output 050,000 sats
- Change UTXO · Output 149,700 sats
- Fee to miner300 sats
The transaction lists 99,700 sats across the two new UTXOs. Subtract that from the funding value to get the 300-sat fee.
Field offsets
An offset is the number of bytes before a field. Start at zero. Little-endian integers put the least significant byte first. Counts and lengths use CompactSize, which uses more bytes for larger numbers.
| Byte offsets | Field | What the node reads |
|---|---|---|
| 0–3 | Version | 02000000 is version 2 in little-endian order. |
| 4 | Input count | 01 is a CompactSize count of one. |
| 5–145 | Input 0 | Outpoint, length-prefixed unlocking bytecode, then the sequence number. The final sequence ffffffff sets no relative delay. |
| 146 | Output count | 02 is a CompactSize count of two. |
| 147–180 | Output 0 | 50c3000000000000 is 50,000 sats, followed by the length and 25 bytes of recipient locking bytecode. |
| 181–214 | Output 1 | 24c2000000000000 is 49,700 sats, followed by the length and 25 bytes of change locking bytecode. |
| 215–218 | Locktime | 00000000 sets no absolute locktime. |
Reveal the 219-byte transaction in hex
Each line corresponds to one row in the offsets table.
02000000
01
3eeebc625a8343f3152bd47bba0169bd4ca1e16610648538e0b11c470db0555f0000000064415fd87feafcd53fbd3c282e8f07f82fde8c4baa460a428bd88c9cd884a96e592db7f34f23361abfcc59f1a6de94edb0c3f753097766852c3235dcdd89047faf4f41210374ca17fc2bda67e23228697245ab054d2a8d018cc92cd504ab0b40c08e4489d1ffffffff
02
50c30000000000001976a914d9ca20f307017d7b126f9ff227ff0341289262f488ac
24c20000000000001976a914b2557abfebaf263824b75ec473fd7b3db74957ea88ac
00000000
Input and output counts and script lengths can occupy more bytes in other transactions. The displayed transaction ID uses the reverse byte order of the hash inside a serialized input outpoint. A token-bearing output can also carry a CashTokens prefix before its locking bytecode.
Inspect every byte on Mocknet · Transaction format reference · CashTokens serialization
Libauth transaction fields
Libauth's decodeTransaction takes the byte array and returns the structured fields below. Scripts and transaction hashes are Uint8Array values. The amount fields are bigint. Unfold the hex above and join the lines to try it. Libauth transaction decoder
import { decodeTransaction, encodeTransaction, hexToBin } from '@bitauth/libauth';
const bytes = hexToBin(rawHex.replace(/\s/g, ''));
const transaction = decodeTransaction(bytes);
if (typeof transaction === 'string') throw new Error(transaction);
const encoded = encodeTransaction(transaction);
| Libauth field | Value in the example |
|---|---|
version, locktime | 2, 0 |
inputs[0].outpointTransactionHash | 5f55b00d471cb1e03885641066e1a14cbd6901ba7bd42b15f343835a62bcee3e in display order |
inputs[0].outpointIndex, sequenceNumber | 0, 0xffffffff |
inputs[0].unlockingBytecode | 100 bytes, containing pushes of a 65-byte signature with sighash flag and a 33-byte public key. |
outputs[0] | valueSatoshis: 50_000n, lockingBytecode: 76a914d9ca20f307017d7b126f9ff227ff0341289262f488ac (hex) |
outputs[1] | valueSatoshis: 49_700n, lockingBytecode: 76a914b2557abfebaf263824b75ec473fd7b3db74957ea88ac (hex) |
Funding UTXO data
The spending input supplies the outpoint. To get the 100,000-sat value and locking script, fetch the funding transaction with blockchain.transaction.get and decode output 0. The Fulcrum protocol’s blockchain.scripthash.listunspent identifies which outpoints remain unspent.
a086010000000000 19 76a914b2557abfebaf263824b75ec473fd7b3db74957ea88ac
| Bytes encoding the funding UTXO | Decoded field |
|---|---|
a086010000000000 | valueSatoshis: 100_000n (8-byte unsigned little-endian integer) |
19 | CompactSize length of the following 25-byte script |
76a914…88ac | lockingBytecode, the P2PKH script matching the example key |
Use fundingTransaction.outputs[0] for the funding UTXO’s value and locking script. encodeTransactionOutput serializes that output record. Compare the two transactions in the Mocknet explorer. Mocknet explorer · Libauth output encoder
Signature digest
To sign, the wallet assembles the bytes it is committing to, then hashes them to get the signing digest. It uses the spending transaction plus the funding UTXO’s value and relevant locking bytecode. The signature ends in the sighash flag 0x41 (SIGHASH_ALL | SIGHASH_FORKID), which commits to both new UTXOs. The first byte of the unlocking script is also 0x41. In that position it tells CashVM to push 65 bytes, including the flag at the end.
For implementers, the transaction signing reference and the replay-protected signature digest explain the serialized commitment.
CashVM stack trace
Run the unlocking script first. It pushes the signature and then the public key. Next run the funding UTXO’s locking script against that stack. The table lists the top item first, like the interactive trace.
| Script | Instruction | Stack, top first |
|---|---|---|
| Unlocking | 41 · Push 65 bytes | [signature + sighash flag] |
| Unlocking | 21 · Push 33 bytes | [publicKey, signature] |
| Locking | 76 · OP_DUP | [publicKey, publicKey, signature] |
| Locking | a9 · OP_HASH160 | [computedHash, publicKey, signature] |
| Locking | 14 · Push 20 bytes | [expectedHash, computedHash, publicKey, signature] |
| Locking | 88 · OP_EQUALVERIFY | [publicKey, signature] when the hashes match |
| Locking | ac · OP_CHECKSIG | [01] when the signature verifies |
Verify with Libauth
Pass each funding UTXO in input order as sourceOutputs. A node also checks that the outpoints are available and that the transaction follows chain rules.
import { createVirtualMachineBCH } from '@bitauth/libauth';
const vm = createVirtualMachineBCH();
const result = vm.verify({
transaction,
sourceOutputs: [fundingTransaction.outputs[0]],
});
if (result !== true) throw new Error(result);
For address decoding, see Wallets and Addresses. For the signature math, see BCH Schnorr verification.
Software or a device that manages addresses and tracks UTXOs, with signing wallets also holding private keys to authorize payments.The smallest unit of BCH, equal to 0.00000001 BCH.The basic unit of spendable value on Bitcoin Cash, holding satoshis and any attached tokens under the spending rules defined by its locking bytecode.A transaction record that identifies a UTXO to spend and supplies its unlocking bytecode and sequence number.A transaction ID and zero-based output index that together identify the UTXO an input spends.A Bitcoin Cash record that defines new outputs and, for a payment, identifies the UTXOs being spent.The bytecode supplied by an input to satisfy the locking conditions of the UTXO it spends.The program in an output that specifies the conditions required to spend it.The Bitcoin Cash virtual machine that executes the scripts authorizing an input to spend its UTXO.The currency unit of Bitcoin Cash, equal to 100,000,000 satoshis.A new output sent back to your wallet with value left over after the payment and fee.The difference between a transaction’s total input and output values, which the miner can claim in the block’s coinbase.An encoding that places the least significant byte of an integer first, as BCH does for serialized output amounts.A variable-length encoding used for nonnegative integers such as the number of transaction outputs or the byte length of a script.A transaction’s double-SHA-256 hash, displayed in reverse byte order and used to identify it in an outpoint.A fixed-length digest used to identify data or commit to its contents, such as a transaction ID or public-key hash.Bitcoin Cash’s native fungible token and NFT format, carried in transaction outputs and enforced by consensus.The protocol wallets use to query Fulcrum for script history, UTXOs, and headers, subscribe to updates, and submit transactions.BCH Ninja’s isolated browser chain for building and inspecting transactions using its own keys and UTXOs.A value made with a private key that lets someone with the corresponding public key verify authorization of the signed data.The signature hash type that selects which transaction fields the signer hashes and commits to.A cryptographic value derived from a private key and used to verify its signatures.A shareable identifier a wallet decodes into a payment’s locking script, usually in CashAddr format on BCH.