Getting started

In order to store our message into a blockchain, we will set up two bitcoin clients (a receiver and a sender). Then we will build a raw transaction, sending one bitcoin along with our message.

Technically speaking, one of the best-known practices for storing data in the bitcoin blockchain is to create a zero-value OP_RETURN output. As defined in bitcoin's protocol, the OP_RETURN script opcode enables us to store up to 80 bytes. You can check it out in bitcoin's code base—script/standard.h (see https://github.com/bitcoin/bitcoin/blob/0.15/src/script/standard.h):

static const unsigned int MAX_OP_RETURN_RELAY = 83;

As mentioned in the standard.h header file, the three additional bytes are for the necessary opcodes, and the remainder is for the extra message. More importantly, the OP_RETURN output can be pruned, helping to avoid bloating the blockchain in the future.

Don't worry if you feel lostwe will dive deep into bitcoin concepts such as outputs and scripting in the next chapter.

We will achieve our goal using two different methods:

  • By creating a raw transaction with an OP_RETURN output, using RPC commands and a bitcoin client
  • By writing a Node.js program to create and send the raw transaction using an online REST API

The second method will require some familiarity with the JavaScript programming language.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset