How to write stuff on the Blockchain

Since ancient times, people have always tried to write messages that could last beyond human life.

Today everybody knows that Bitcoin is great to move and store money in an easy and secure way, but less people are aware that you can also use the Bitcoin blockchain to write forever lasting immutable messages.

Some use this awesome feature to write love messages, to share an important thought or to celebrate a special event.

There are some very user friendly services, such as Eternity Wall, that allow you to easily write messages on the Bitcoin blockchain, but what’s the point of having a trustless and censorship resistant tool if we rely on third party services? Let’s learn how you can do it by yourself.

All you are going to need is a synchronized Bitcoin Core wallet and some satoshi to pay for the transaction fees.

STEP 1

First we start up the Bitcoin Core client and open the console window (help/debug window/console). In this guide we are using Bitcoin Core from the GUI client, but case you are using it from a terminal, remember to prepend bitcoin-cli to the commands of this tutorial.

So, before we can to anything else, we need to list the unspent outputs of the Bitcoin address you we are going to use. In this example I will use a personalized vanity address (because it’s cool).

Command:

listunspent ( minconf maxconf ["address",…] )

Example:

listunspent 0 999999 '["1BENoCzVT3awc3y1GCbWiCM25cEX9KAw7B"]'

Output:

[
{
"txid": "855a32647ffb88aaa08dbb2359bbf1daeb6d9c7faa9d16cd9fd7ede221158352”,
"vout": 1,
"address": "1BENoCzVT3awc3y1GCbWiCM25cEX9KAw7B",
"account": "",
"scriptPubKey": "76a9147038dc3b8533a422d1225ecbcc3c85e282fd92b388ac",
"amount": 0.00100000,
"confirmations": 0,
"spendable": true
}
]

STEP 2

Now we have everything you need to create the raw transaction that later we will push on the blockchain, but we still have to convert in hexadecimal the message we want on the Blockchain.

In my example I am going to write “#GenerationBlockchain was here”, but to give some extra visibility to the message I will add “EW” at the beginning of the string, so it will also appear on the home page of Eternity Wall (without actually using their client). To easily convert the message in hex you can use an online service.

The hex of “EW#GenerationBlockchain was here” is “4557202347656E65726174696F6E426C6F636B636861696E207761732068657265”. Using this string, we can proceed to create the raw transaction.

Command:

createrawtransaction '[{"txid":"paste here txid form previous step output","vout":number from previous step}]' '{"data":"the message you want to write on the blockchain converted in hex ","the address you are using":change}'

Example:

createrawtransaction '[{"txid":"855a32647ffb88aaa08dbb2359bbf1daeb6d9c7faa9d16cd9fd7ede221158352","vout":1}]' '{"data":"4557202347656E65726174696F6E426C6F636B636861696E207761732068657265","1BENoCzVT3awc3y1GCbWiCM25cEX9KAw7B":0.00080000}'

Output:

010000000152831521e2edd79fcd169daa7f9c6debdaf1bb5923bb8da0aa88fb7f64325a850100000000ffffffff020000000000000000236a214557202347656e65726174696f6e426c6f636b636861696e20776173206865726580380100000000001976a9147038dc3b8533a422d1225ecbcc3c85e282fd92b388ac00000000

N.B. If you don’t set the change, all the bitcoin you have on the address you are using will go to the miner. In this example I set up the change is such a way that I left 0.0002 btc to pay the transaction fee. The ideal transaction fee may change in the future.

STEP 3

This one is quite simple, all we have to do is to sign the transaction just created:

Command:

signrawtransaction "hexstring from previous step output"

Example:

signrawtransaction 010000000152831521e2edd79fcd169daa7f9c6debdaf1bb5923bb8da0aa88fb7f64325a850100000000ffffffff020000000000000000236a214557202347656e65726174696f6e426c6f636b636861696e20776173206865726580380100000000001976a9147038dc3b8533a422d1225ecbcc3c85e282fd92b388ac00000000

Output:

{
"hex": "010000000152831521e2edd79fcd169daa7f9c6debdaf1bb5923bb8da0aa88fb7f64325a85010000008b483045022100ec8d66045f7bbe1953a0937b2e5970b84d2f5462c6080802055c7cdfb2d19cc402204db3880775534df762e8afdc0814372ce706337ef129d8d35839093bd88734140141045d443089b4587d355b4cb5ac39b0156afc92152627693149de16d0d2269cea2417010c0bc6930e9b47573dab76a951e01d884b2bed9eaf92cc2369b6ddc7f98cffffffff020000000000000000236a214557202347656e65726174696f6e426c6f636b636861696e20776173206865726580380100000000001976a9147038dc3b8533a422d1225ecbcc3c85e282fd92b388ac00000000",
"complete": true
}

STEP 4

Very last step, let’s just broadcast the signed transaction:

Command:

sendrawtransaction "hexstring from previous step output"

Example:

sendrawtransaction 010000000152831521e2edd79fcd169daa7f9c6debdaf1bb5923bb8da0aa88fb7f64325a85010000008b483045022100ec8d66045f7bbe1953a0937b2e5970b84d2f5462c6080802055c7cdfb2d19cc402204db3880775534df762e8afdc0814372ce706337ef129d8d35839093bd88734140141045d443089b4587d355b4cb5ac39b0156afc92152627693149de16d0d2269cea2417010c0bc6930e9b47573dab76a951e01d884b2bed9eaf92cc2369b6ddc7f98cffffffff020000000000000000236a214557202347656e65726174696f6e426c6f636b636861696e20776173206865726580380100000000001976a9147038dc3b8533a422d1225ecbcc3c85e282fd92b388ac00000000

Output:

af91176121c91234cc99387f35f3e1d3f8853afc7f156a5873e48c67260eb7ae

The output from this last step is the transaction ID that we can use to find this message on any block explorer. Since this message starts with “EW”, after one confirmation it appeared also on Eternity Wall.

Next time you have something important to share with the world and future generations, consider the idea of writing it on the blockchain.