1

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)

{
  "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.

1 Answer 1

2

Since OP_RETURN are "provably" unspendable 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).

4
  • 1
    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? Feb 8 at 15:24
  • There are other ways but this is preferred by most users.
    – user103136
    Feb 8 at 19:19
  • 1
    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
    Feb 9 at 1:54
  • 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? Feb 9 at 5:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.