Step 2: Create Transaction Outputs

Each output in a Bitcoin transaction requires:

  • Amount (8 bytes): Value in satoshis
  • ScriptPubKey: Locking script that defines spending conditions
SVG Image

Code Implementation

python
def create_output(
    amount: int,
    script_pubkey: bytes
) -> bytes:
    # Amount (8 bytes, little-endian)
    amount_bytes = int_to_little_endian(amount, 8)
    
    return (
        amount_bytes +          # value in satoshis
        script_pubkey          # includes length prefix
    )

The following table summarizes our outputs from test vector:

OutputAmount (BTC)ScriptPubKey
#11.21976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac
#22.21976a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac

Our transaction structure at this stage is:

text
1Transaction Breakdown:
2═══════════════════════════════════════════════════════════════════════════════════
3
4Version: 01000000
5
6Input Count: 02
7
8input[0]:
9Previous TXID: fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f
10Output Index: 00000000
11ScriptSig Size: 00
12ScriptSig:
13Sequence: eeffffff
14
15input[1]:
16Previous TXID: ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a
17Output Index: 01000000
18ScriptSig Size: 00
19ScriptSig:
20Sequence: ffffffff
21
22Output Count: 02
23
24output[0]:
25Amount: 202cb20600000000
26ScriptPubKey Size: 19
27ScriptPubKey: 76a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac
28
29output[1]:
30Amount: 9093510d00000000
31ScriptPubKey Size: 19
32ScriptPubKey: 76a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac
33
34Locktime: 11000000

Test Vector from BIP-143

Let's test our code with the test vector from the official BIP143 proposal.

Suggest Edits
View our public visitor count
Built with 🧡 by the Bitcoin Dev Project
We'd love to hear your feedback on this project?Give Feedback