Adding custom data to bitcoin transaction

Adding custom data to bitcoin transaction

Posted by

As you probably know, most of the people talk about Bitcoin blockchain as to distributed ledger, meaning it is a distributed database of transactions. The are some ways that allow to embed in this database of transactions additional information. In this article I am going to cover one of the official techniques. By embedding data in transactions using this methods, your new transactions will be saved to the blockchain and not filtered.

Why you actually want to do it?

  • Stenography – you want to hide something for the years to come in every bitcoin node.
  • You are looking for reliable distributed database (this is costly).
  • Adding 3rd part application id to the bitcoin transaction.
  • You are wallet developer and you want all your transactions marked in a special way.
  • Proof of existence for documents. You can hash document and save this data in bitcoin transaction.
    Example for such service is https://www.proofofexistence.com/

In this article I am going to deep dive into the “Hello World” message embedded in this transaction:
tx 6dfb16dd580698242bcfd8e433d557ed8c642272a368894de27292a8844a4e75
Other similar example can be found here:
tx 968a6d9afc4eadda6b12be6e2a31c05358419200af79bda22d63302bff01efd7

Disadvantages
Price depends on the transaction size. Adding additional data to transaction actually make the transaction longer. As a result you will pay a bit more for the transaction to be mined in a reasonable time.

How this method actually works?
From the technical perspective it is very easy, you need to add additional receiver of the funds with zero sum. This receiver will receive 0 satoshies. This receiver’ bitcoin script should have the following code:

OP_RETURN {80 bytes of whatever data you want}

For example lets take a look at the “hello-world” transaction above. It has the following hex value:

01000000018c0bfefccb5755874ea0872a17b0d682c84981eed93fccd3ef86556f51f21522010000006a47304402204bbbefdc49e7289b0f36fe8c7623e93ff7ff751664d63caf49c1d9d8a4cbefd402200582f12a9490bdf8e6980025c08f83c43c50bc472706e3a38e7f1a972404bc4d0121035533036f3a7e9dc4c76e9d3697eb9d573aa76844baaadda347893a793797b639ffffffff0410270000000000001976a914303962c3ad29f08d13d98218ceeb7057e9bc184888ac10270000000000001976a914c6a3b95415d3fe9a9161c4b5100c1b6f2ad1e90c88ac00000000000000000d6a0b68656c6c6f20776f726c64e5490600000000001976a914e6228f7a5ee6b15c7cccfd9f9cb7e8699261084588ac00000000

After decoding it, you will get something as following (I deleted 2 unrelated addresses in vout)

hello world bitcoin transaction

Now, lets decode the hex message: “6a0b68656c6c6f20776f726c64”.
0x6A is a OP_RETURN Bitcoin script operation
0x0b – length of the data following
0x68656c6c6f20776f726c6 – “hello world” message in hex. You can use this table to decode: Ascii table.

Other ideas
If you actually do not need the money transferred in the transactions, you can hide the data in the target address of the transaction. As long as you do not care about the money, target address can contain any information.

PS. I am not the author of the original hello world transactions. I just found it when researching this topic.