You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The final way to vary how you send a basic transaction is to use the
4
+
transaction to send data instead of funds (or really, in addition to
5
+
funds). This gives you the ability to embed information in the
6
+
blockchain. It is done through a special `OP_RETURN` command.
4
7
5
-
The final way to vary how you send a basic transaction is to use the transaction to send data instead of funds (or really, in addition to funds). This gives you the ability to embed information in the blockchain. It is done through a special `OP_RETURN` command.
6
-
7
-
The catch? You can only store 80 bytes at a time!
8
+
The catch? It's controversial. Many people think you shouldn't put
9
+
data onto the Bitcoin chain at all. For a long time, `OP_RETURN` was
10
+
limited to 80 bytes to minimize its use, but in recent years it's
11
+
become unlimited.
8
12
9
13
## Create Your Data
10
14
11
-
The first thing you need to do is create the 80 bytes (or less) of data that you'll be recording in your `OP_RETURN`. This might be as simple as preparing a message or you might be hashing existing data. For example, `sha256sum` produces 256 bits of data, which is 32 bytes, well under the limits:
15
+
The first thing you need to do is create the data that you'll be
16
+
recording in your `OP_RETURN`. This might be as simple as preparing a
17
+
message or you might be hashing existing data. For example,
18
+
`sha256sum` produces 256 bits of data, which you can use to commit to
> :book:_What is an OP_RETURN?_ All Bitcoin transactions are built upon opcode scripts that we'll meet in the next chapter. The `OP_RETURN` is a simple opcode that defines an OUTPUT as invalid. Convention has resulted in it being used to embed data on the blockchain.
26
+
27
+
> 📖 _What is an OP_RETURN?_ All Bitcoin transactions are built upon
28
+
opcode scripts that we'll meet in later chapters. The `OP_RETURN` is a
29
+
simple opcode that defines an OUTPUT as invalid. Convention has
30
+
resulted in it being used to embed data on the blockchain.
18
31
19
32
## Prepare Some Money
20
33
21
-
Your purpose in creating a data transaction isn't to send money to anyone, it's to put data into the blockchain. However, you _must_ send money to do so. You just need to use a change address as your _only_ recipient. Then you can identify a UTXO and send that to your change address, minus a transaction fee, while also using the same transaction to create an OP_RETURN.
34
+
Your purpose in creating a data transaction isn't to send money to
35
+
anyone, it's to put data into the blockchain. However, you _must_ send
36
+
money to do so. You just need to use a change address as your _only_
37
+
recipient. Then you can identify a UTXO and send that to your change
38
+
address, minus a transaction fee, while also using the same
You can now write a new rawtransaction with two outputs: one is your change address to get back (most of) your money, the other is a data address, which is the `bitcoin-cli` term for an OP_RETURN.
70
+
You can now write a new rawtransaction with two outputs: one is your
71
+
change address to get back (most of) your money, the other is a data
72
+
address, which is the `bitcoin-cli` term for an OP_RETURN.
As you can see, this sends the majority of the money straight back to the change address (`tb1qnx9fkrksw6aaaswc3kj0gademhn4ud3q7cz4fm`) minus a small transaction fee. More importantly, the first output shows an OP_RETURN with the data (`b9f81a8919e5aba39aeb86145c684010e6e559b580a85003ae25d78237a12e75`) right after it.
127
+
128
+
As you can see, this sends the majority of the money straight back to
129
+
the change address (`tb1qkm0w8td03ca8l4gkghgvw6h9ey20kfsyreqwny`)
130
+
minus a small transaction fee. More importantly, the first output
You may note a warning about the data being in an "unknown protocol". If you were designing some regular use of `OP_RETURN` data, you'd probably mark it with a special prefix, to mark that protocol. Then, the actual OP_RETURN data might be something like "CONTRACTS3b110a164aa18d3a5ab064ba93fdce62". This example didn't use a prefix to avoid muddying the data space.
152
+
Some explors may note that the data is in an "unknown protocol". If
153
+
you were designing some regular use of `OP_RETURN` data, you'd
154
+
probably mark it with a special prefix, to mark that protocol. Then,
155
+
the actual OP_RETURN data might be something like
156
+
"CONTRACTS3b110a164aa18d3a5ab064ba93fdce62". This example didn't use a
157
+
prefix to avoid muddying the data space.
114
158
115
159
## Summary: Sending a Transaction with Data
116
160
117
-
You can use an `OP_RETURN` opcode to store up to 80 bytes of data on the blockchain. You do this with the `data` codeword for a `vout`. You still have to send money along too, but you just send it back to a change address, minus a transaction fee.
118
-
119
-
> :fire:_What is the Power of OP_RETURN?_ The OP_RETURN opens up whole new possibilities for the blockchain, because you can embed data that proves that certain things happened at certain times. Various organizations have used OP_RETURNs for proof of existence, for copyright, for colored coins, and [for other purposes](https://en.bitcoin.it/wiki/OP_RETURN). Though 80 bytes might not seem a lot, it can be quite effective if OP_RETURNs are used to store hashes of the actual data. Then, you can prove the existence of your digital data by demonstrating that the hash of it matches the hash on the blockchain.
120
-
121
-
Note that there is some controversy over using the Bitcoin blockchain in this way.
161
+
You can use an `OP_RETURN` opcode to store up to 80 bytes of data on
162
+
the blockchain. You do this with the `data` codeword for a `vout`. You
163
+
still have to send money along too, but you just send it back to a
164
+
change address, minus a transaction fee.
165
+
166
+
> 🔥 _What is the Power of OP_RETURN?_ The OP_RETURN opens up whole
167
+
new possibilities for the blockchain, because you can embed data that
168
+
proves that certain things happened at certain times. Various
169
+
organizations have used OP_RETURNs for proof of existence, for
170
+
copyright, for colored coins, and for other purposes. But beware of
171
+
the possibility for pushback when you use OP_RETURN, and so if you use
172
+
it, do so responsibly, ideally embedding small amounts of data that
173
+
can be used as commitments rather than larger data dumps. This will
174
+
still support proof of existence and timestamping.
122
175
123
176
## What's Next?
124
177
125
-
Move on to "Bitcoin Scripting" with [Chapter Nine: Introducing Bitcoin Scripts](09_0_Introducing_Bitcoin_Scripts.md).
178
+
Move on to "Importing & Exporting Your Secrets" with [Chapter Ten:
0 commit comments