Skip to content
Developer Handbook

CashVM and transactions

On this page

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.

50,000-sat payment1 input · 2 outputs · 219 bytes
Existing UTXO · Spent by input 0 100,000 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 offsetsFieldWhat the node reads
0–3Version02000000 is version 2 in little-endian order.
4Input count01 is a CompactSize count of one.
5–145Input 0Outpoint, length-prefixed unlocking bytecode, then the sequence number. The final sequence ffffffff sets no relative delay.
146Output count02 is a CompactSize count of two.
147–180Output 050c3000000000000 is 50,000 sats, followed by the length and 25 bytes of recipient locking bytecode.
181–214Output 124c2000000000000 is 49,700 sats, followed by the length and 25 bytes of change locking bytecode.
215–218Locktime00000000 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 fieldValue in the example
version, locktime2, 0
inputs[0].outpointTransactionHash5f55b00d471cb1e03885641066e1a14cbd6901ba7bd42b15f343835a62bcee3e in display order
inputs[0].outpointIndex, sequenceNumber0, 0xffffffff
inputs[0].unlockingBytecode100 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 UTXODecoded field
a086010000000000valueSatoshis: 100_000n (8-byte unsigned little-endian integer)
19CompactSize length of the following 25-byte script
76a914…88aclockingBytecode, 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.

ScriptInstructionStack, top first
Unlocking41 · Push 65 bytes[signature + sighash flag]
Unlocking21 · Push 33 bytes[publicKey, signature]
Locking76 · OP_DUP[publicKey, publicKey, signature]
Lockinga9 · OP_HASH160[computedHash, publicKey, signature]
Locking14 · Push 20 bytes[expectedHash, computedHash, publicKey, signature]
Locking88 · OP_EQUALVERIFY[publicKey, signature] when the hashes match
Lockingac · 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.