Every block in the Bitcoin blockchain contains transactions made by the users. Every transaction records the transfer of Bitcoin from one entity/person to another. We can use these records to trace every Bitcoin to its point of creation. The basic structure of a Bitcoin transaction is as follows:
Every Bitcoin transaction has two main parts:
Inputs are the coins the user owns and wants to transfer to another person/entity. Every input has essential subfields to locate and unlock that coin in the Bitcoin blockchain. These fields are as follows:
Previous transaction ID: This is the ID of the transaction in which that Bitcoin was created as output and assigned to the current owner.
Previous transaction index: Every Bitcoin transaction can have multiple outputs (an array of outputs), and every output is identified by a unique index (index of the array). This index, along with the previous transaction ID, can be used to locate the transaction where that Bitcoin was created and to identify its real owner.
ScriptSig: It is short for script signature. It encodes the public key and the signature of the current owner of the Bitcoin (payer). It is stored in the following format:
Outputs are the newly generated Bitcoins locked to the hash of the public key of the payee.
Note: Bitcoin uses the unspent transaction output (UTXO) model. Thus every Bitcoin can only be used once, and after every transaction, old Bitcoins are discarded, and the same amount of new coins are generated.
Two main parts of a Bitcoin transaction's output are described below:
Value: The number of Bitcoins being transferred to the payee. The minimum value that a user can transfer is one satoshi where
ScriptPubKey: This is a sequence of instructions (like a function) that takes ScriptSig as input and returns true
if a legitimate owner tries to unlock that Bitcoin. Otherwise, it returns false
. The format of a ScriptPubKey is as follows:
Every Bitcoin transaction can have multiple inputs and outputs. Every input can be from a different user/payer (these are called multiSig transactions), and every output can be from another user/payee. The format of a Bitcoin transaction with two inputs and three outputs is shown below:
Free Resources