5

I am trying to parse all transactions.

I found that some transactions do not have addresses in their vout.

There are two situations that vout does not have addresses.

The first one is the miner reward.

For example, run this:

bitcoin-cli getrawtransaction 4bec1175f9682fc10118bbb146d1def8fd82fdffdf27da8beea327469f79b2b0 true.

Here is the result:

{

  "txid": "4bec1175f9682fc10118bbb146d1def8fd82fdffdf27da8beea327469f79b2b0",

  "hash": "4bec1175f9682fc10118bbb146d1def8fd82fdffdf27da8beea327469f79b2b0",

  "version": 1,

  "size": 135,

  "vsize": 135,

  "weight": 540,

  "locktime": 0,

  "vin": [

    {

      "coinbase": "048521131a028d00",

      "sequence": 4294967295

    }

  ],

  "vout": [

    {

      "value": 50.25892368,

      "n": 0,

      "scriptPubKey": {

        "asm": "04994b2548a865ad7e786c691bb9cac7d15afc60b8b4500e24e79ec1cd910830b7dd799defdfdc1a7136e4976d2086daa319a7923f633987905a86aaece612ab9b OP_CHECKSIG",

        "hex": "4104994b2548a865ad7e786c691bb9cac7d15afc60b8b4500e24e79ec1cd910830b7dd799defdfdc1a7136e4976d2086daa319a7923f633987905a86aaece612ab9bac",

        "type": "pubkey"

      }

    }

  ],

  "hex": "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff08048521131a028d00ffffffff011008912b01000000434104994b2548a865ad7e786c691bb9cac7d15afc60b8b4500e24e79ec1cd910830b7dd799defdfdc1a7136e4976d2086daa319a7923f633987905a86aaece612ab9bac00000000",

  "blockhash": "00000000000009e63c0dc84756b1f535b0c8d7c51b849e60b6ce893a9c6a4d51",

  "confirmations": 506698,

  "time": 1308295622,

  "blocktime": 1308295622

}

You can see there is no addresses field in the first and only object of vout.

The second one is not a miner reward.

For example, run this:

bitcoin-cli getrawtransaction 4caea993e7caa859840a8ebac457c31420bb4fb79b528d870556c5a2eec5da7a true.

Here is the result:

{

  "txid": "4caea993e7caa859840a8ebac457c31420bb4fb79b528d870556c5a2eec5da7a",

  "hash": "4caea993e7caa859840a8ebac457c31420bb4fb79b528d870556c5a2eec5da7a",

  "version": 1,

  "size": 234,

  "vsize": 234,

  "weight": 936,

  "locktime": 0,

  "vin": [

    {

      "txid": "c245fbf8c03de1ab3372f72cafbd40ef47882fc0aba02c424e70cb4b44c65241",

      "vout": 0,

      "scriptSig": {

        "asm": "304502200eee831084af8de8ebac477d3c56b5a4d428522df0ccaed41ede77570eac27a5022100af5786d35cdef15a97a775542217a7e9ee85b06d4f07c50bab768bce189e3d9e[ALL]",

        "hex": "48304502200eee831084af8de8ebac477d3c56b5a4d428522df0ccaed41ede77570eac27a5022100af5786d35cdef15a97a775542217a7e9ee85b06d4f07c50bab768bce189e3d9e01"

      },

      "sequence": 4294967295

    }

  ],

  "vout": [

    {

      "value": 115.00000000,

      "n": 0,

      "scriptPubKey": {

        "asm": "OP_DUP OP_HASH160 208bbec311f62e7881ee746d7f3a6ba097203815 OP_EQUALVERIFY OP_CHECKSIG",

        "hex": "76a914208bbec311f62e7881ee746d7f3a6ba09720381588ac",

        "reqSigs": 1,

        "type": "pubkeyhash",

        "addresses": [

          "13y62oZbRtF4SJx2sezC3PvvDBfXx42jJb"

        ]

      }

    },

    {

      "value": 2.00000000,

      "n": 1,

      "scriptPubKey": {

        "asm": "0405d71f20e493a0721e705944e7151a1d7c1b9a9cd546cc44c2f348fa6e27b588ddfdd7b3e52c9af208598f3b2ac519af9d7ee78cea4f237ee5028020e33633c9 OP_CHECKSIG",

        "hex": "410405d71f20e493a0721e705944e7151a1d7c1b9a9cd546cc44c2f348fa6e27b588ddfdd7b3e52c9af208598f3b2ac519af9d7ee78cea4f237ee5028020e33633c9ac",

        "type": "pubkey"

      }

    }

  ],

  "hex": "01000000014152c6444bcb704e422ca0abc02f8847ef40bdaf2cf77233abe13dc0f8fb45c2000000004948304502200eee831084af8de8ebac477d3c56b5a4d428522df0ccaed41ede77570eac27a5022100af5786d35cdef15a97a775542217a7e9ee85b06d4f07c50bab768bce189e3d9e01ffffffff02001374ad020000001976a914208bbec311f62e7881ee746d7f3a6ba09720381588ac00c2eb0b0000000043410405d71f20e493a0721e705944e7151a1d7c1b9a9cd546cc44c2f348fa6e27b588ddfdd7b3e52c9af208598f3b2ac519af9d7ee78cea4f237ee5028020e33633c9ac00000000",

  "blockhash": "000000000000098444048edc683a41d26be975e302019a51a7ca3c2cc21d4813",

  "confirmations": 506676,

  "time": 1308309497,

  "blocktime": 1308309497

}

You can see there is no addresses field in the second object of vout.

Please explain this or provide some keyword for me to search! Thank you guys!

2 Answers 2

10

An address is a convenience feature designed to make human usage of Bitcoin easier - the Bitcoin protocol itself does not know anything about addresses.

All outputs are actually sent to programs written in the Bitcoin Script language. These programs can take any form.

We have defined certain programs that can be encoded as addresses - namely, pay-to-public-key-hash, pay-to-script-hash, pay-to-witness-public-key-hash, and pay-to-witness-script-hash.

An output going to any other program will not be encodeable as an address - in your example, the program is known as a Pay to Public Key output, which locks coins directly to a public key, instead of locking them to the more commonly used public key hash (p2pkh addresses, starting with 1).

The output can still be spent.

7
  • I'm sorry, I don't see before your answer and I posted also my answer. I want leave also my answer because I think there are different explanations that can exist together. (I can remove if the my contains errors) Sorry again Jul 7, 2020 at 5:38
  • I removed my answer, my dyslexia problem win again :) the problem are where is the address (if exist :)). Jul 7, 2020 at 5:49
  • 4
    @vincenzopalazzo No problem - note that usually, there is no issue in multiple people posting answers to the same question right after one another, even if they cover mostly the same content. Stack Exchange as a forum encourages it as long as each answer is in good faith - I personally upvote many competing answers to my own if they are of good quality :) Jul 7, 2020 at 6:02
  • Thank you for answering. Like you said, any other program will not be encodeable as an address, but some bitcoin explorer can still get the address. Plz visit this link to see the example for transaction 4caea993e7caa859840a8ebac457c31420bb4fb79b528d870556c5a2eec5da7a bitinfocharts.com/bitcoin/tx/…
    – Mars Lee
    Jul 9, 2020 at 5:47
  • 3
    Some explorers decide on their own system to convert these kinds of scripts into addresses - they are wrong, and if you try to send coins to the address they display, it will not be easily spendable by the person who actually owns the keys. In a best case scenario, they will have to manually recover the coins. In a worst case, the coins will be permanently lost Jul 9, 2020 at 5:50
3

I don't really know why it doesn't include some addresses. Here's how to get both of the addresses for your second transaction example:

For vout index 0, it says the type is a pubkeyhash. The hex value is the actual script run by bitcoin. Here it is 76a914208bbec311f62e7881ee746d7f3a6ba09720381588ac, and if you have an opcode guide like this, you can decipher it. Let's break it down:

opcode        word

0x76          OP_DUP  
0xa9          OP_HASH160    
0x14          PUSH the next 0x14 bytes (20 in dec): 208bbec311f62e7881ee746d7f3a6ba097203815
0x88          OP_EQUALVERIFY
0xac          OP_CHECKSIG

Those 20 bytes (208bbec311f62e7881ee746d7f3a6ba097203815) are a pubkey hash. Now all you have to do is Base58Check those 20 bytes and you've got your address. You can use this to do that: copy the 20 bytes into step 3 and hit send. The address (13y62oZbRtF4SJx2sezC3PvvDBfXx42jJb) is shown at the bottom. Steps 4 through 9 are what I refer to as "Base58Check" above.

For vout index 1, it says the type is a pubkey. Let's break down the script (410405d71f20e493a0721e705944e7151a1d7c1b9a9cd546cc44c2f348fa6e27b588ddfdd7b3e52c9af208598f3b2ac519af9d7ee78cea4f237ee5028020e33633c9ac):

opcode        word

0x41          PUSH the next 0x41 bytes (65 in dec):  0405d71f20e493a0721e705944e7151a1d7c1b9a9cd546cc44c2f348fa6e27b588ddfdd7b3e52c9af208598f3b2ac519af9d7ee78cea4f237ee5028020e33633c9
0xac          OP_CHECKSIG

Those 65 bytes are the public key for the address. Now you have to SHA256 hash those bytes, then ripemd hash THOSE bytes, then run Base58Check on that. You can use the link above again to do this, just paste the 65 bytes into step 1 and hit send. The address (12WSoZ84ZJAKDo4MbbgKQtw3qT8gTF2o4e) is shown at the bottom. You can also use this procedure to get the address for the miner reward example you mentioned. Try it- you should get 19wBtLQYtLgriGWLjgAXWwedTBgPYbjE97.

2
  • This is the most complete guide to get addresses. Thank you so much!
    – Mars Lee
    Jul 14, 2020 at 3:21
  • I wish I can give you more point!!
    – Mars Lee
    Jul 14, 2020 at 3:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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