TxIn

TxIn: A Transaction Input (Non-Coinbase)

Each non-coinbase input spends an outpoint from a previous transaction. (Coinbase inputs are described separately after the example section below.)

Name

Data Type

Bytes

Description

previous_outpoint

Outpoint

36

The previous outpoint being spent.

signature script

string

Varies

A script-language script which satisfies the conditions placed in the outpoint’s pubkey script. Should only contain data pushes; see the signature script modification warning. Maximum length if the script is 10,000 bytes.

sequence

uint32

4

Transaction version as defined by the sender. Intended Sequence number.

Coinbase Input: The Input Of The First Transaction In A Block

TODO: adapt format and example for coinbase (add snapshot hash (see UIP-11), use p2wpkh, …)

The first transaction in a block, called the coinbase transaction, must have exactly one input, called a coinbase. The coinbase input currently has the following format.

Name

Data Type

Bytes

Description

hash (null)

char[32]

32

A 32-byte null, as a coinbase has no previous outpoint.

index (UINT32_MAX)

uint32

4

0xffffffff, as a coinbase has no previous outpoint.

script bytes

CompactSize

Varies

The number of bytes in the coinbase script, up to a maximum of 100 bytes.

height

coinbasescript

Varies

The block height of this block as required by BIP-34. Uses script language: starts with a data-pushing opcode that indicates how many bytes to push to the stack followed by the block height as a little-endian unsigned integer. This script must be as short as possible, otherwise it may be rejected. The data-pushing opcode will be 0x03 and the total size four bytes until block 16,777,216 about 300 years from now.

coinbase script

None

Varies

The coinbase field: Arbitrary data not exceeding 100 bytes minus the (4) height bytes. Miners commonly place an extra nonce in this field to update the block header merkle root during hashing.

sequence

uint32

4

Sequence number as defined by the sender. Used for replacement of transactions when updated before inclusion of a block.

Most (but not all) blocks prior to block height 227,836 used block version 1 which did not require the height parameter to be prefixed to the coinbase script. The block height parameter is now required.

Although the coinbase script is arbitrary data, if it includes the bytes used by any signature-checking operations such as “OP_CHECKSIG”, those signature checks will be counted as signature operations (sigops) towards the block’s sigop limit. To avoid this, you can prefix all data with the appropriate push operation.

An itemized coinbase transaction:

01000000 .............................. Version

01 .................................... Number of inputs
| 00000000000000000000000000000000
| 00000000000000000000000000000000 ...  Previous outpoint TXID
| ffffffff ............................ Previous outpoint index
|
| 29 .................................. Bytes in coinbase
| |
| | 03 ................................ Bytes in height
| | | 4e0105 .......................... Height: 328014
| |
| | 062f503253482f0472d35454085fffed
| | f2400000f90f54696d65202620486561
| | 6c74682021 ........................ Arbitrary data
| 00000000 ............................ Sequence

01 .................................... Output count
| 2c37449500000000 .................... Satoshis (25.04275756 UTE)
| 1976a914a09be8040cbf399926aeb1f4
| 70c37d1341f3b46588ac ................ P2PKH script
| 00000000 ............................ Locktime