2

I am trying to get all existing addresses on the bitcoin blockchain with bitcoin-cli. It seems that I can get addresses from vout that are of type "pubkeyhash". If the type of vout is "pubkey" there are no addresses.

pubkeyhash type:

  "vout": [
    {
      "value": 0.00000001,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 b04e3fb6f6c96ba23233c809e42d8e6a0e0e31ca OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914b04e3fb6f6c96ba23233c809e42d8e6a0e0e31ca88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1H5DfbDtCnKUdke9xH9svwwxqga41Z5xbz"
        ]
      }
    }

pubkey type:

  "vout": [
    {
      "value": 50.63517500,
      "n": 0,
      "scriptPubKey": {
        "asm": "04b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7b OP_CHECKSIG",
        "hex": "4104b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7bac",
        "type": "pubkey"
      }
    }

Is there an easy way to get ALL the addresses on the blockchain?

2 Answers 2

5

Answering this question requires first defining what an address means.

  1. Historically (before BIP16 activated in 2012) an address was a synonym with a "public key identifier", as there were no addresses for multisig constructions or anything like that. Under this interpretation, pay-to-pubkey or pay-to-pubkey-hash outputs would be seen as having the same address - after all, the key is the same. This is problematic, because sending to the "address" corresponding to a pay-to-pubkey script would not actually send to that script, but to its corresponding pay-to-pubkey-hash script. Sufficiently old software, and some newer software (including some block explorers) use this interpretation, leading to confusion.

  2. Most software now treats an address to be a human-readable notation for encoding specific scripts (corresponding to the script that would be constructed if a wallet were to be instructed to pay to said address). Under this interpretation, pay-to-pubkey outputs simply don't have an address (as there is no way to make wallet produce such outputs), and certainly not the same address as for the pay-to-pubkey-hash output with the same key.

The software you're using follows interpretation (2), so the question makes little sense. It is showing you all addresses observed, but in this case, there just isn't any address involved. Transaction outputs in Bitcoin are freeform scripts, and only some of those have a corresponding address notation. Others are just scripts.

2

The second output you are showing is using the pay to pubkey output script. Pay to pubkey (P2PK) eponymously locks funds to a public key. The corresponding input script only needs to provide a signature by the corresponding private key to spend the funds. The P2PK fell out of disuse for everything except mining outputs early on, and there never was a standard for encoding P2PK output scripts as addresses. The best way to track these is probably via the paid public key.

2
  • So for the second transaction here is what I see on blockchain explorer: (blockchain.com/btc/tx/…) It shows the address 1MdYC22Gmjp2ejVPCxyYjFyWbQCYTGhGq8 You say there is no way to get this address directly from scriptPubKey ? When you say paid public key does it mean I have to check this output as the VIN of another transaction? (if so JSON RPC doesn't show addresses for VIN) Thank you very much !
    – Daniel
    Aug 28, 2020 at 22:08
  • 1
    @Daniel See my answer, it's not that the address can't be computed from the scriptPubKey, it's that depending on interpretation, that script doesn't have an address. Aug 29, 2020 at 0:07

Your Answer

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

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