In Bitcoin, the OP_RETURN opcode is used in the locking script (scriptPubKey) of a transaction output to encode arbitrary data. This output type is marked as provably unspendable, meaning the output value cannot be redeemed. The primary purpose is to store data immutably on the blockchain, enabling applications like document notarization, digital asset tracking, and metadata storage. Let’s dive into the protocol-level specifics of how this is achieved.
1. Transaction Overview
A Bitcoin transaction is composed of inputs and outputs. An OP_RETURN output does not carry spendable value (value = 0) and its locking script contains the opcode OP_RETURN (0x6a) followed by the data payload.
At the protocol level, here’s how an OP_RETURN output is structured:
- value field: Set to 0 satoshis, as the output is unspendable.
- scriptPubKey field: Contains OP_RETURN followed by a data push opcode and the arbitrary data.