How BEN wrote to Satoshi Nakamoto in an immutable way.

I decided to do a small experiment on behalf of BEN.

As I was writing a module for the Blockchain Education Month (BEM), an open-source collaborative course organised by the ever growing Blockchain Education Network (BEN). I decided to search a few of the possible wallets that Satoshi Nakamoto, the creator of Bitcoin, possesses.

I began my search with the Genesis block (block “0” in the blockchain) where the very first Coinbase transaction was done. For people that are not familiar, “coinbase” is a transaction that a miner adds to a successfully “mined” block to pay himself for the work done. Not only does this transaction benefit the miner, but it also means that the total amount of bitcoin in circulation has increased by that exact amount.

Now a miner cannot add an infinite amount of bitcoin to his account, he is only allowed to give himself a pre-determined amount according to the rules in the network. At first, bitcoin miners saw a reward of 50 BTC, 4 years later a reward of 25 BTC and now miners can only give themselves 12.5 BTC per successful block. This halving trend will keep going until 2140, when no more bitcoin will be created.

If any of this talk doesn't make sense all is not lost! Make sure to check out the course that BEN is currently building, it should be live and ready after on November 1st 2016.


Going back to my search. As I was looking at the genesis block I decided to look at the address where the first transaction went to, and I got quite a surprise. People are still sending money to that address! No one knows who owns this address, this address has never made a transaction, but all we know is that it got the very first bitcoins ever. (At the time of writing, this address holds ~66 BTC which evaluates currently at 46 000 $ USD).

Those transactions were actually quite interesting. There are many and they are mostly low value. Why would someone send small transactions to this address? Upon analysis, many of those were actually OP_return transactions, or transactions that save data on the blockchain!

This is how I decided to add my own on behalf of BEN, as an educational opportunity on how to make a valid bitcoin transaction.

DISCLAIMER: it is not recommended to save lots of data on the blockchain as it takes lots of resources to do so. Remember that every miner/full node needs to save that data onto their hard drive. This exercise is for educational purposes only.


I will be using bitcoin-cli, the bitcoin core client to generate a custom transaction, sign it with my private key and broadcast it to other nodes. I decided to go this way to show how an actual node works, but there are many other ways one can do this without needing to download the whole blockchain.

So first and foremost you will need to get acquainted with bitcoind and its client bitcoin-cli. You can find the source code here. You will need to install it on your computer and create an account along with a valid public address and then send a few bitcoins to it (I used a mobile wallet that holds my day-to-day bitcoins to do it).

If you are not up-to-date with the blockchain in your node, you will need to download it from the network up to at least the transaction made to your current public key. The reason is simple: your node is not capable of finding your transaction in an old blockchain, thus until you download a sufficient chunk of the blockchain your account balance will be 0.

Assuming your node is up-to-date and you have money in your account, we can go ahead and start.

To pay our respects to the great Satoshi Nakamoto, we will be sending a small amount of bitcoin (0.0005 BTC) along with a message (using an OP_return script). We will be sending this to the first Coinbase address, 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.

Creating an OP_return used to be quite involved, you needed to change the source code of bitcoind and send it to nodes that accept non-standard transactions (which are not so popular these days) but thankfully after v0.9 of bitcoind, OP_returns were added for our convenience as standard transactions.

There are 5 different types of standard transactions :

  • pay-to-public-key-hash (P2PKH)
  • public-key
  • multi-signature (limited to 15 keys)
  • pay-to-script-hash (P2SH)
  • data output (OP_RETURN)

Within the data output (OP_return), to qualify as a standard transaction, the data can be no bigger than 80 bytes and you can only have one OP_return per transaction. If this is not the case, then you have a non-standard transaction and you will need to find nodes that will accept it (also usually for a higher fee). You can find a list of them here.

The first step is to start the software by typing bitcoind in a command terminal (or bitcoind -daemon if you want it to run in the background). Next, we need to find the right UTXO to use for our transaction (remember the transaction where you sent bitcoin to your address?). You can do this using the listunspent method that will return all the UTXO’s associated with your address. You will need to get the txid and the corresponding vout of a valid UTXO for the transaction. You may need multiple of them to send the appropriate amount of money (the total UTXO should be bigger than the total that you send).

Next, we need to create the transaction, we will be using bitcoin-cli and the method createrawtransaction. If you need to look at how to pass in the right arguments type bitcoin-cli help “createrawtransaction”. Here is the transactions that I used:

bitcoin-cli createrawtransaction '[{"txid": "14d890ca693a355de62ea7878166ca0ea1406a54151c4be4dc007f6459e2bde0","vout":1}]' '{"data": "54686520426c6f636b636861696e20456475636174696f6e204e6574776f726b202842454e292073616c7574657320796f7521","1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa":0.0005}'

Notice that this transaction has 1 input, my valid UTXO, and 2 outputs, a transaction of 0.0005 BTC to an address and a data transaction. Now I could have added a third output, a change address, but I calculated the value of the transaction such that my UTXO was 0.0008 BTC, and I am sending 0.0005 BTC, thus giving 0.0003 BTC as a mining fee.

BE CAREFUL, IF YOU DO NOT PROVIDE A CHANGE ADDRESS, ALL OF THE REMAINING BTC IN YOUR TRANSACTION WILL BE TAKEN BY THE MINER AS A FEE.

Notice the data field in the transaction. Those seemingly random numbers are actually the words “The Blockchain Education Network (BEN) salutes you!” in Hex. You do need to convert any data passed in to Hex or else it won’t work. The output to this method call is hex string:

0100000001e0bde259647f00dce44b1c15546a40a10eca668187a72ee65d353a69ca90d8140100000000ffffffff020000000000000000356a3354686520426c6f636b636861696e20456475636174696f6e204e6574776f726b202842454e292073616c7574657320796f752150c30000000000001976a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac00000000

You can use the method decoderawtransaction to evaluate your newly created, well formatted transaction:

bitcoin-cli decoderawtransaction 0100000001e0bde259647f00dce44b1c15546a40a10eca668187a72ee65d353a69ca90d8140100000000ffffffff020000000000000000356a3354686520426c6f636b636861696e20456475636174696f6e204e6574776f726b202842454e292073616c7574657320796f752150c30000000000001976a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac00000000
{
"txid": "27cf26ccdfd8855bba36c0029cbb7e2a5dc6a06f1447e30d6780cf9325a846ac",
"hash": "27cf26ccdfd8855bba36c0029cbb7e2a5dc6a06f1447e30d6780cf9325a846ac",
"size": 147,
"vsize": 147,
"version": 1,
"locktime": 0,
"vin": [
{
"txid": "14d890ca693a355de62ea7878166ca0ea1406a54151c4be4dc007f6459e2bde0",
"vout": 1,
"scriptSig": {
"asm": "",
"hex": ""
},
"sequence": 4294967295
}
],
"vout": [
{
"value": 0.00000000,
"n": 0,
"scriptPubKey": {
"asm": "OP_RETURN 54686520426c6f636b636861696e20456475636174696f6e204e6574776f726b202842454e292073616c7574657320796f7521",
"hex": "6a3354686520426c6f636b636861696e20456475636174696f6e204e6574776f726b202842454e292073616c7574657320796f7521",
"type": "nulldata"
}
},
{
"value": 0.00050000,
"n": 1,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 62e907b15cbf27d5425399ebf6f0fb50ebb88f18 OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": [
"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
]
}
}
]
}

Now everything seems correct except for the signature fields that are empty. We now need to sign the transaction to make it valid.

In your account, you probably will need to “unlock” your private key for the signing privilege, you can do it using the walletpassphrase method.

bitcoin-cli walletpassphrase <YOUR PASSWORD> 360

(The number you give as argument is telling the wallet how long you want the private key to be “accessible”)

Now let’s go ahead and sign the transaction using signrawtransaction:

bitcoin-cli signrawtransaction 0100000001e0bde259647f00dce44b1c15546a40a10eca668187a72ee65d353a69ca90d8140100000000ffffffff020000000000000000356a3354686520426c6f636b636861696e20456475636174696f6e204e6574776f726b202842454e292073616c7574657320796f752150c30000000000001976a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac00000000
{
"hex": "0100000001e0bde259647f00dce44b1c15546a40a10eca668187a72ee65d353a69ca90d814010000006b483045022100e55276ff910f1d552499b80c134c7fc2200220dbb590c50b003b87a96d5bcc55022014871144bd6bf82319cd5141db926061f7328f4d552c919323d77208588a3f77012102ffe995c83d08661a97f3b0ca980fa61c72ef589f322cc574c8dc0fb0ff40b067ffffffff020000000000000000356a3354686520426c6f636b636861696e20456475636174696f6e204e6574776f726b202842454e292073616c7574657320796f752150c30000000000001976a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac00000000",
"complete": true
}

If you decode the newly formed hex in the “hex” field, you will now see that the signatures have been filled!

We now have a valid transaction that we can broadcast to the network, we will use sendrawtransaction with the newly formed “hex”.

bitcoin-cli sendrawtransaction 0100000001e0bde259647f00dce44b1c15546a40a10eca668187a72ee65d353a69ca90d814010000006b483045022100e55276ff910f1d552499b80c134c7fc2200220dbb590c50b003b87a96d5bcc55022014871144bd6bf82319cd5141db926061f7328f4d552c919323d77208588a3f77012102ffe995c83d08661a97f3b0ca980fa61c72ef589f322cc574c8dc0fb0ff40b067ffffffff020000000000000000356a3354686520426c6f636b636861696e20456475636174696f6e204e6574776f726b202842454e292073616c7574657320796f752150c30000000000001976a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac00000000

If there were no error messages, this method should have returned the transaction id for it to be searchable. After the call, the method returned

54ec6f264f7dae1793aff25da319b0fcd63ca40491d232076c4f963a09618d76

You will now have to wait a bit for your transaction to be propagated to the network, accepted in a block and wait for confirmation. Once that is done (shouldn’t take more than 10 minutes if you give a decent fee) then you can search it on the blockchain. I used blockchain.info to do this. Searching our transaction using our txid:

A look at our transaction. Notice the OP_return at the bottom.

Looking at the Output Scripts section we see :

Output scripts of the transaction

And looking at the genesis block :

The transaction is now recorded in the first bitcoin address!

Our transaction is there! We successfully gave 0.0005 BTC to the presumed Satoshi Nakamoto while passing him a message. And now our message is immutable, no one can change it! It will be there as long as bitcoin exists!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.