CHAPTER 6Transactions

Bitcoins do not reside in user’s computers. They are entries into a distributed database called the blockchain, which will be explored in Chapter 7. Unlike centralized digital currencies, Bitcoin’s blockchain does not store accounts and balances. The blockchain stores transactions.

Transactions are composed of a list of transaction inputs (TxIn) and a list of transaction outputs (TxOut). Each transaction output (TxOut) holds two pieces of data: an amount and the recipient address1. The address is derived from the public key, as explained in section 5.6. Thus only the owner of the private key can unlock the funds stored in the TxOut. To unlock the funds, the owner of the private key must sign a transaction sending the funds to a new Bitcoin address.

A transaction input (TxIn) holds a reference to a previous transaction output, and a signature that proves that the funds in the previous TxOut it references can be spent2. This signature must be done with the private key associated with the public key in the Bitcoin address. If the signature does not match, the transaction is deemed invalid and dropped by the network.

A transaction groups several TxIns and TxOuts (at least one of each). The purpose of a transaction is to distribute the funds from the inputs to the outputs. Inputs in a transaction reference outputs in previous transactions. These outputs must not have been spent, otherwise the transaction is invalid.

For the transaction to be valid, the sum ...

Get Understanding Bitcoin: Cryptography, Engineering and Economics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.