So you wanna put Chinese pork on the blockchain?

July 6, 2017

When I see headlines like Walmart and IBM Are Partnering to Put Chinese Pork on a Blockchain I’m thinking, sorry, but how do you put Chinese pork on the blockchain?

And it’s not just limited to food. Electronic Medical Records on the Blockchain is big news also.

Let’s now add to the confusion and track beef with a cryptocurrency instead of a blockchain. Russia Gets First Sanctioned Cryptocurrency – And It’s Tracking Beef

What does all this mean?

Studying the blockchain has led me to understand that small bits of information can be included in a transaction. Think of it like adding a custom message when sending a small amount of, in this case, bitcoins.

This article will first look at how one can add a custom message on the blockchain, specifically the bitcoin blockchain, and then figure out how it relates to Chinese pork.


The first thing to understand is that a blockchain is made of blocks and blocks are made of transactions. This is what a transaction looks like.

In hex:

Expanded it looks like this:

Inside a transaction there are fields called op codes that are used to put rules in place to determine who can spend a bitcoin. The example above shows:

OP_DUP OP_HASH160 27f60a3b92e8a92149b18210457cc6bdc14057be OP_EQUALVERIFY OP_CHECKSIG

The op code we are interested in is called OP_RETURN. It is here that arbitrary data can be inserted as part of a transaction.

So how is it done?

There are a few examples around on the web. Here is one in java: Here is one on php:

The one in php is the easiest and quickest to get up and running so we’ll “run” with that. If you’re on a Mac, this example literally takes 2 minutes. The setup however will take over 4 hours. That is because you will need the bitcoin client application and have it sync’d to the testnet blockchain. The testnet blockchain will take about 4-5 hrs to download and is currently around 11.5Gb. I would recommend setting txindex=1 in the config files allowing you to inspect transactions that are not specifically related to your account. It helps immensely when developing. This will only increase the blockchain size to 13.5Gb which is paltry compared to 140Gb+ for the actual bitcoin blockchain.

Step 1:

> git clone

Step 2:

> php send-OP_RETURN.php mxkS5AJgpK5jTDcpvKDWChvuJAT5FFCXqK 0.005 “Why did the chicken cross the road?” 1

You will get this response:

> TxID: cc6d7ce4c4390644bf20071c20ebb21034ef51d55c4f74a1a813150ab0406b4b
Wait a few seconds then check on:

And with that, the most infamous chicken joke is now ingrained in the blockchain for generations to come to ponder herewith. Here is the link in fact.

Tamper Detection

If you look carefully, you would have noticed that I made a spelling mistake. I corrected it in this article but I cannot correct it or edit it in the blockchain. It is there forever which highlights an important characteristic. Immutability.


There is a maximum size of 83 bytes that can be used to store data. There is a big back story to this if you are interested here.

Clear text or gibberish?

Quite often you’ll see a lot of gibberish. This just means it’s not within the human readable ASCII range. ie the message is for computers.


Technically speaking, instead of putting a sentence there, I should have hashed it and put the hash there. That is because a hash function can take an input of any length and produce a constant 64 bytes output that is well within the 83 byte limit.

Doesn’t it bloat the blockchain?

It depends. There is a lot of debate around this. Some groups think that the bitcoin blockchain should be use for purely financial applications. Take your chicken jokes somewhere else! Others think that there are great advantages to including small messages. A compromise has been reach (of 83 bytes) and we all move on.

What about Chinese Pork?

If you are still with me, you would have noticed by now you’re not actually putting real Chinese pork on the blockchain. You probably knew this from the beginning. You are putting information of where the pork came from.

In the middle of the Walmart/IBM article it states that its blockchain is “… designed to provide the retailer with a way to indelibly record a list of transactions indicating how meat has flowed through a commercial network, from producers to processors to distributors to grocers—and finally, to consumers.

So some person or more viably some machine is going to stamp statements such as “Pig RFID 25435(Sally) from feeding location ID 3425 (Jiangsu) arrived in processing facility location ID 8976 (Shanghai)” to a blockchain.

Machines could stamp statements even on cuts of meat themselves!

Why not use a regular database?

One reason is due to the decentralized nature of the blockchain database. There is no database administrator that can be coerced or even forced at gunpoint to change the data to avoid prosecution when there is a public health crisis.

Beef via cryptocurrency?

This one is strange when you first hear about it but if you look at the “Why did the chicken cross the road?” example above, you will have noticed that in order to write a message on the blockchain, I had to provide a bitcoin address and an amount of 0.005BTC or 5 milli bits. The information is piggy backed on the bitcoin or “cryptocurrency” transaction.


Now, whenever you see articles where all sorts of “stuff” are put on the blockchain, you should have a clearer picture on what is being place (statements, claim or any information for that matter), how it is placed (hashed with some software code), where it is placed (in a special area in the blockchain) and why (tamper resistant and decentralized).

Leave a Comment!

Your email address will not be published. Required fields are marked *