Dust in the Blockchain

June 26th, 2015

The blockchain is the distributed database that the Bitcoin protocol uses for recording all its transactions. Since the blockchain is both easily accessible and immutable, it is incredibly useful for other purposes as well, such as Proof of Existence (notarizing). Issuing a tiny fraction of a Bitcoin (called dust) with embedded data allows anyone to easily store data permanently and publicly.

Entire protocols have been built on top of Bitcoin to take advantage of this data storage trick; there are generally referred to as Bitcoin 2.0. Colored Coins, for example, can represent real-world assets. Any asset that would normally have a title or certificate of ownership could have it instead managed on the blockchain: gold, a car, a house, shares in a company. This works because the blockchain has certain consistency guarantees that would make it impossible to sell your house simultaneously to two different people. This type of innovation will likely fundamentally change the way asset ownership is managed.

The Counterparty platform provides a more generalized Bitcoin 2.0 implementation. It allows users to create their own currencies, issue assets, do crowdfunding, or hold escrow, and supports a distributed exchange—all without requiring a trusted third party. Counterparty utterly relies on the Bitcoin blockchain for consistency and immutability.

Of the many features of the blockchain—that it is editable, public, open sourced, and consistent—immutability is the primary attraction for Bitcoin 2.0 protocols. It is nearly impossible for someone to hack the database and, say, steal the title of your house. The proof of work system that supports Bitcoin mathematically guarantees that our data is protected from any system with less computational power. At present, it would take over $100m in hardware and about $20k per hour in electricity cost. So, although it’s not impossible to hack the blockchain, it would take a James Bond supervillian to pull off such an attack.

There has been an empassioned debate about whether storing non-Bitcoin related data in the blockchain is a good idea. The Bitcoin 2.0 protocols are inevitable, but purists argue that the protocol was not originally designed for this, and that it only serves to increase the size of the blockchain.

The debate can be seen in the change history of the source code itself. A default minimum transaction amount was introduced which effectively makes sending less than a tenth of a cent impossible. Also, the OP_RETURN field (generally used for storing data) was reduced from 80 bytes to 40 to discourage data storage. This caused some problems for Counterparty, but they were also able to store data in other fields typically reserved for multi-signature transactions. Then recently, the limit was raised back to 80 again, as developers recognized the value of Bitcoin 2.0 possiblities.

Think about using the blockchain in this way like jailbreaking your iPhone: it’s not what the developers intended, but it allows you to do more with the technology. There do exist other cryptocurrencies (altcoins) that are more “data friendly,” but the reality is: Bitcoin has the largest network (nearly a $4b economy), and therefore the most secure blockchain—so the debate will always be centered there.

How to store data in the blockchain

In the spirit of jailbreaking, below I will demonstrate how to construct a small Bitcoin transaction and add some data to it. Here I’m using node.js with the Bitcoin-js library—to use this library, you’ll need to install both the bitcoinjs-lib and crypto-js node packages using the npm package manager. You will also need to possess some actual Bitcoin so you can execute a transaction with it.

First, create a new random Bitcoin address to send to:

var bitcoin = require('bitcoinjs-lib')
tx = new bitcoin.Transaction()

Find a transaction where you received BTC in the past by browsing the blockchain, entering your receiving address, and retrieving the transaction ID. This will be the input to our new transaction.

tx.addInput("0ac1019aed90516c0892f17f9ef7ac4371f8036b39128288b79b719dccc3cbbc", 0)

Add the receiving address, a public Bitcoin address and amount to send in Satoshis. Very small amounts may not be confirmed by the network quickly as miners may choose to ignore them. 4,000 Satoshi (about one cent) should suffice.

tx.addOutput("1Hw3j39qSYKa9Y4KnJCiwqgG6i4ZT38VcR", 4000)

Find the private key that has access to the funds in the transaction ID above. Most Bitcoin wallets allow you to export a private key in wallet import format (WIF):

key = bitcoin.ECKey.fromWIF("L1YFYg7vF2CanMhBXqMythk4RGtNQErGTkufEwCJHSt5RLTmt5hd")

Add some data in to the transaction in the OP_RETURN field:

var b = new Buffer("I Can Has Cheezburger?");
op_rtn = bitcoin.Script.fromChunks([bitcoin.opcodes.OP_RETURN, b])
tx.addOutput(op_rtn, 0)

Now sign the input with the imported key:

tx.sign(0, key)

Print transaction serialized as hexidecimal:


This string represents the complete transaction and can be posted to the network. We could use CURL on the command line to post it, but here I’ll just paste it into an interface that will do that for us here.

If you’re curious what the complete transaction looks like, paste the Hex string here to decode it.

Once the transaction is confirmed by miners and added to the blockchain it will effectively live forever, preserving the message within it.

Recent data stored in the blockchain in the OP_RETURN field can be viewed here.


Header image by BTC Keychain. Used under CC BY 2.0.