Transactions

The Bitcoin Blockchain serves Bitcoin by generating the supply of coins and facilitating their trade, along with standard Bitcoin trades between users. When transacting on the Blockchain, an atomic unit of transacting called a transaction serves to move funds. All fund movements on the Blockchain occur through transactions. In fact transactions are the sole record stored in the Blockchain, there are no balances or accounts, only chains of transactions between all the Blockchain users.

Transactions themselves are simple short programs called smart contracts which define the source and destination of funds, plus the restrictions and authorizations regarding their transfer. At a simplified high level a transaction smart contract says, "the funds that are provably certified to be moved may be used to fund to another party's re-spending of the funds given their own provable certification restriction". The set of transactions forms a one way chain of spending from first the generation of every coin to the final owner or owners.

Only Bitcoin miners may include transactions into the Blockchain record, through the proof of work system that prevents arbitrary updating of the widely synced record. To submit transactions to the miners any method may be used to convey the data, but most commonly the transactions use the broadcast system of the Bitcoin peer to peer network to send a transaction in its initial unconfirmed state to the network peers who wish to sync unconfirmed transactions. Miners listen to this network for unconfirmed transactions, selecting the ones they see fit to include in their updates to Blockchain blocks, restricted by the network consensus rule regarding block size maximum transaction data.

Transaction Formation

Transactions contain funding inputs to fund the transaction and funding outputs to direct the funds to new ownership. To transmit funds with a transaction, a Bitcoin wallet selects a previously unspent transaction output from a previously received transaction to use to fund a new transaction, turning those unspent outputs into spent outputs and new transaction inputs. Bitcoin wallets aggregate and hide this detail, showing users a simple total balance reflecting the sum of unspent transaction outputs, automatically selecting previously received transaction output funds when forming new transactions.

Previously received transaction outputs may only be spent in full in a transaction: it's not possible to take a partial amount of spent funds. Transactions take the pool of funds created by the transaction inputs to allocate funds to three possible output types: third party destinations to send funds to, change destinations to receive change back from the overflow of unspent output value, and a miner fee, which is indicated by the overflow of unspent output value that is unassigned in third party destinations and change destinations. For privacy reasons, wallets attempt to make change destinations and third party destinations look as similar as possible.

Funds leading into a transaction and funds leading out of a transaction are not linked together, except broadly given that the input funds live together with the output funds in the transaction. Three sources of funds may go into a transaction and three sources exit a transaction, but with no links determining which funding source went to which new owner defined by each output. This feature is sometimes used by the CoinJoin system to collaboratively form transactions between many people to weaken privacy-reducing analyses of input and outputs.

There are many building blocks in transaction programs, but the most important are signatures and public keys. Public keys are used to prove ownership of funds used as transaction inputs, a cryptographic signature proves the public key identity has the authority to persist the transaction in the Blockchain, moving funds.

When evaluating transactions, full nodes look at the inputs, which reference previous transactions. They evaluate the previous transaction's preconditions for spending funds: does the new transaction contain cryptographically correct authority to spend the funds as outlined in the previous transaction? The authority to move funds is defined in a simple programming system, a straightforward stack of operations that combine conditions, supplied data and operations.

The stack based language is simplistic, similar to the PostScript language which is a standard language for defining visual documents. The verification step is also simplistic, each address to send to marks an unfulfilled signature that is fulfilled when funds move. These programs that define the smart contract only execute when the transfers are validated to move funds to the next contract, and the programs simply define a true or false result, true results being required to move funds and false to reject and prevent the relaying and Blockchain inclusion of transactions.

Transaction Types

In standard transactions, called pay-to-pubkey-hash transactions, or P2PKH, or 1xx transactions, the process for proving ownership of coins and authority to spend them is extremely simple. Bitcoin's basic scripting primitives take the address represented as a public key hash, indicating that the funds are locked to the owner of the public key. The transaction to unlock the funds is simply the presentation of the public key to match the hash, plus the signing proof of the public key authorizing the fund transfer.

More involved transactions use a second, newer, BIP16 defined, type of transactions known as pay-to-script-hash, or P2SH, or 3xx transactions. These transactions take addresses representing the hash of an arbitrary script defining merely the signature of a hidden contract. To spend these funds, the spender presents a script matching the hashed address, evaluating to true based on supplied data, such as within the common multiple-signature transaction type. Because these transactions reflect an arbitrary script instead of a fixed public key hash, the script may lock funds in extremely flexible arrangements: multiparty signature locks, time locks, and other future operations as they are added to Bitcoin's consensus logic rule set.

Coinbase Transactions

Each block in the shared Blockchain collection of transactions includes a special transaction as the first transaction in the block, known as the coinbase transaction. These transactions, created by miners through mining or generation, are allowed to create an input that takes funds from the funding overflow of a block, defined by all the excesses of any block transaction inputs not spent by their outputs, also known as fees, plus the block subsidy, a longstanding but exponentially decreasing sum used to mint and distribute the money supply over one hundred years.

The input of a coinbase transaction does not have a script signature in its input, it has arbitrary miner chosen data, plus the difficulty target and a random nonce value called extraNonce used when mining to advance to a new set of hash possibilities for the proof of work mining system.