<h3>How do I add metadata to the blockchain?</h3>
<p>Essentially, one of the output <a href="https://en.bitcoin.it/wiki/Script" rel="nofollow noreferrer">scripts</a> should be</p>
<pre><code>OP_RETURN &lt;the data you want to add&gt;
</code></pre>
<p>That's it.</p>
<p>Let me give an example. Say you want to add the string &quot;Melons.&quot; to the blockchain.</p>
<ol>
<li>Convert to binary<br />
&quot;Melons.&quot; -&gt; <code>4d656c6f6e732e</code></li>
<li>Add the push-data-onto-stack command at the start. This is the length of your metadata if it's less than 75 bytes, or OP_PUSHDATAx otherwise.<br />
<code>074d656c6f6e732e</code></li>
<li>Add OP_RETURN at the start<br />
<code>6a074d656c6f6e732e</code></li>
<li>Put this in the scriptPubKey of an output of a transaction. I wrote a guide on this <a href="https://bitcoin.stackexchange.com/a/36439/2306">here</a>.</li>
</ol>
<h3>How do I find it again?</h3>
<p>That's... trickier. Bitcoin is not optimized for searching the metadata of transactions.</p>
<p>Possibilities:</p>
<ul>
<li>Look through all of the transactions you get with something like <code>bitcointools</code>.</li>
<li>Use a website like <a href="http://coinsecrets.org" rel="nofollow noreferrer">coinsecrets.org</a>.</li>
</ul>

CC BY-SA 3.0
2017-02-07T15:27:47.093Z
So to find the data again, we should traverse through the blockchain, find OP_RETURN patterns, grab associated data, index them ..., right?
anhldbk
CC BY-SA 3.0
2014-10-20T23:32:06.220Z
2017-02-07T17:41:00.093Z
2020-06-16T11:10:03.350Z
Nick ODell
<p>You might find our OP_RETURN libraries useful, for <a href="https://github.com/coinspark/php-OP_RETURN" rel="nofollow">PHP</a> and <a href="https://github.com/coinspark/python-OP_RETURN" rel="nofollow">Python</a>. If you look at the code you can also see exactly how they work.</p>

CC BY-SA 3.0
2015-07-16T07:41:22.360Z
2015-07-16T07:41:22.360Z
Gideon Greenspan
<p>This might be a possible duplicate with <a href="https://bitcoin.stackexchange.com/questions/25224/what-is-a-step-by-step-way-to-insert-data-in-op-return" title="What is a step by step way to insert data in OP_RETURN?">this</a>.</p>

<p>I want to know a proper way to insert additional string with OP_RETURN and retrieve the transaction from block chain and decode it accordingly.</p>

<p>Thank you</p>

<bitcoind><op-return>
Insert data to transaction with OP_RETURN
Rasela Don
# Insert data to transaction with OP_RETURN

(Asked by: username_0 on 2014-10-16)

This might be a possible duplicate with [this](https://bitcoin.stackexchange.com/questions/25224/what-is-a-step-by-step-way-to-insert-data-in-op-return "What is a step by step way to insert data in OP_RETURN?").

I want to know a proper way to insert additional string with OP\_RETURN and retrieve the transaction from block chain and decode it accordingly.

Thank you

**Tags:** bitcoind, op-return


---

## 2 answers

### Answer by username_1 on 2014-10-20. Score: 9

### How do I add metadata to the blockchain?

Essentially, one of the output [scripts](https://en.bitcoin.it/wiki/Script) should be

```
OP_RETURN <the data you want to add>

```

That's it.

Let me give an example. Say you want to add the string "Melons." to the blockchain.

1. Convert to binary  
   "Melons." -> `4d656c6f6e732e`
2. Add the push-data-onto-stack command at the start. This is the length of your metadata if it's less than 75 bytes, or OP\_PUSHDATAx otherwise.  
   `074d656c6f6e732e`
3. Add OP\_RETURN at the start  
   `6a074d656c6f6e732e`
4. Put this in the scriptPubKey of an output of a transaction. I wrote a guide on this [here](https://bitcoin.stackexchange.com/a/36439/2306).

### How do I find it again?

That's... trickier. Bitcoin is not optimized for searching the metadata of transactions.

Possibilities:

* Look through all of the transactions you get with something like `bitcointools`.
* Use a website like [coinsecrets.org](http://coinsecrets.org).

> **Comments:**
> **username_2**: So to find the data again, we should traverse through the blockchain, find OP_RETURN patterns, grab associated data, index them ..., right?  

---

### Answer by username_3 on 2015-07-16. Score: 1

You might find our OP\_RETURN libraries useful, for [PHP](https://github.com/coinspark/php-OP_RETURN) and [Python](https://github.com/coinspark/python-OP_RETURN). If you look at the code you can also see exactly how they work.


---

