<p>Since <code>OP_RETURN</code> are <a href="https://github.com/bitcoin/bitcoin/blob/280a7777d3a368101d667a80ebc536e95abb2f8c/src/script/script.h#L539-L547" rel="nofollow noreferrer">&quot;provably&quot; unspendable</a> they are not stored in the chainstate database (nor cached in RAM).</p>
<p>If you want to see your <code>OP_RETURN</code> outputs you'll have to parse the block chain (or use <code>-txindex</code> and <code>getrawtransaction</code> on your node).</p>

CC BY-SA 4.0
2022-02-08T15:24:48.487Z
Thanks, I'll try this out and let you know. I have a followup question: OP_RETURN is the only way to add arbitrary data onto the chain, right? Are there any other ways for the same?
Nirmal Khedkar
CC BY-SA 4.0
2022-02-09T01:54:20.897Z
Before OP_RETURNs were introduced, people would write data into output scripts instead. This had more overhead size for the data written, and since these outputs weren't provably unspendable, everyone has to carry them around in their UTXO set forever. So, OP_RETURNs were the middleground. Users can write stuff to the blockchain, but at least we don't need to keep it in the UTXO set.
Murch
CC BY-SA 4.0
2022-02-09T05:17:16.327Z
But information about OP_RETURN transaction must have been stored _somewhere_, right? How else would I be getting transaction info when running 'bitcoin-cli listunspent' then?
Nirmal Khedkar
CC BY-SA 4.0
2022-02-08T15:17:57.500Z
2022-02-08T15:17:57.500Z
Antoine Poinsot
<p>I'm running a bitcoin node on regtest. I'm writing scripts to interact with the chain-state database.</p>
<p>For my purpose, I'm creating, signing and sending a transaction to my node (pretty much following the instructions from <a href="https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line" rel="nofollow noreferrer">here, specifically chapter 4 and 8</a>)</p>
<pre><code>{
  &quot;amount&quot;: 0.00000000,
  &quot;fee&quot;: -14.28700000,
  &quot;confirmations&quot;: 200,
  &quot;blockhash&quot;: &quot;41dd1e98ab12148e8cd5c0ad06aab27beb4117f54b1e51916b7238535884cac2&quot;,
  &quot;blockheight&quot;: 1001,
  &quot;blockindex&quot;: 1,
  &quot;blocktime&quot;: 1644326961,
  &quot;txid&quot;: &quot;9286a6f8e3814977efa6acd6320a4d4367f0bed85f9477c78da6c122086f49df&quot;,
  &quot;walletconflicts&quot;: [
  ],
  &quot;time&quot;: 1644326955,
  &quot;timereceived&quot;: 1644326955,
  &quot;bip125-replaceable&quot;: &quot;no&quot;,
  &quot;details&quot;: [
    {
      &quot;category&quot;: &quot;send&quot;,
      &quot;amount&quot;: 0.00000000,
      &quot;vout&quot;: 0,
      &quot;fee&quot;: -14.28700000,
      &quot;abandoned&quot;: false
    }
  ],
  &quot;hex&quot;: &quot;...&quot;
}
</code></pre>
<p>Below is the transaction outputs:</p>
<pre><code> &quot;vout&quot;: [
    {
      &quot;value&quot;: 0.00000000,
      &quot;n&quot;: 0,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;OP_RETURN 6268696a6b6c0a&quot;,
        &quot;hex&quot;: &quot;6a076268696a6b6c0a&quot;,
        &quot;type&quot;: &quot;nulldata&quot;
      }
    },
    {
      &quot;value&quot;: 10.71300000,
      &quot;n&quot;: 1,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;0 e2698bbd6d475f022f8e5f852fa10ac761faa9c7&quot;,
        &quot;hex&quot;: &quot;0014e2698bbd6d475f022f8e5f852fa10ac761faa9c7&quot;,
        &quot;reqSigs&quot;: 1,
        &quot;type&quot;: &quot;witness_v0_keyhash&quot;,
        &quot;addresses&quot;: [
          &quot;bcrt1quf5ch0tdga0sytuwt7zjlgg2casl42w8c2pr6d&quot;
        ]
      }
    }
  ]
</code></pre>
<p><strong>My problem:</strong> When I query the chainstate database and decode the TXIDs and output indexes, I see only the second output and not the first (i.e. the OP_RETURN one). I've retried on clean slate, other wallets, etc, but the problem still persists.</p>
<p>I've read 200 confirmations is as good as go, but I've tried the same after generating 400 more blocks too. Even still, that doesnt explain why I cant find my OP_RETURN UTXO in the chainstate folder.</p>
<p>For reference, this is my Python script that queries the chainstate folder:</p>
<pre><code>db=plyvel.DB(chainstate_folder_path,compression=None)
arr=[]
for key,value in db:
    hexval=key.replace(b'C',b'')[::-1].hex()
    arr.append((int(hexval[:2]),hexval[2:]))

arr.sort(key=lambda x:x[1])
for i in arr:
    print(i)
</code></pre>
<p>What am I missing out? I really want to be able to parse my OP_RETURN UTXOs.</p>

<bitcoin-cli><utxo><op-return>
Are OP_RETURN transactions not stored in chainstate database?
Nirmal Khedkar
# Are OP_RETURN transactions not stored in chainstate database?

(Asked by: username_0 on 2022-02-08)

I'm running a bitcoin node on regtest. I'm writing scripts to interact with the chain-state database.

For my purpose, I'm creating, signing and sending a transaction to my node (pretty much following the instructions from [here, specifically chapter 4 and 8](https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line))

```
{
  "amount": 0.00000000,
  "fee": -14.28700000,
  "confirmations": 200,
  "blockhash": "41dd1e98ab12148e8cd5c0ad06aab27beb4117f54b1e51916b7238535884cac2",
  "blockheight": 1001,
  "blockindex": 1,
  "blocktime": 1644326961,
  "txid": "9286a6f8e3814977efa6acd6320a4d4367f0bed85f9477c78da6c122086f49df",
  "walletconflicts": [
  ],
  "time": 1644326955,
  "timereceived": 1644326955,
  "bip125-replaceable": "no",
  "details": [
    {
      "category": "send",
      "amount": 0.00000000,
      "vout": 0,
      "fee": -14.28700000,
      "abandoned": false
    }
  ],
  "hex": "..."
}

```

Below is the transaction outputs:

```
 "vout": [
    {
      "value": 0.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_RETURN 6268696a6b6c0a",
        "hex": "6a076268696a6b6c0a",
        "type": "nulldata"
      }
    },
    {
      "value": 10.71300000,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 e2698bbd6d475f022f8e5f852fa10ac761faa9c7",
        "hex": "0014e2698bbd6d475f022f8e5f852fa10ac761faa9c7",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1quf5ch0tdga0sytuwt7zjlgg2casl42w8c2pr6d"
        ]
      }
    }
  ]

```

**My problem:** When I query the chainstate database and decode the TXIDs and output indexes, I see only the second output and not the first (i.e. the OP\_RETURN one). I've retried on clean slate, other wallets, etc, but the problem still persists.

I've read 200 confirmations is as good as go, but I've tried the same after generating 400 more blocks too. Even still, that doesnt explain why I cant find my OP\_RETURN UTXO in the chainstate folder.

For reference, this is my Python script that queries the chainstate folder:

```
db=plyvel.DB(chainstate_folder_path,compression=None)
arr=[]
for key,value in db:
    hexval=key.replace(b'C',b'')[::-1].hex()
    arr.append((int(hexval[:2]),hexval[2:]))

arr.sort(key=lambda x:x[1])
for i in arr:
    print(i)

```

What am I missing out? I really want to be able to parse my OP\_RETURN UTXOs.

**Tags:** bitcoin-cli, utxo, op-return


---

## 1 answers

### Answer by username_1 on 2022-02-08. Score: 2

Since `OP_RETURN` are ["provably" unspendable](https://github.com/bitcoin/bitcoin/blob/280a7777d3a368101d667a80ebc536e95abb2f8c/src/script/script.h#L539-L547) they are not stored in the chainstate database (nor cached in RAM).

If you want to see your `OP_RETURN` outputs you'll have to parse the block chain (or use `-txindex` and `getrawtransaction` on your node).

> **Comments:**
> **username_0**: Thanks, I'll try this out and let you know. I have a followup question: OP_RETURN is the only way to add arbitrary data onto the chain, right? Are there any other ways for the same?  
> **username_2**: Before OP_RETURNs were introduced, people would write data into output scripts instead. This had more overhead size for the data written, and since these outputs weren't provably unspendable, everyone has to carry them around in their UTXO set forever. So, OP_RETURNs were the middleground. Users can write stuff to the blockchain, but at least we don't need to keep it in the UTXO set.  
> **username_0**: But information about OP_RETURN transaction must have been stored _somewhere_, right? How else would I be getting transaction info when running 'bitcoin-cli listunspent' then?  

---

