2

Context: I have a bitcoin core node(v.24), and using bitcoinrpc library.

So, when I am running the getrawtransaction() function, sometimes the vout doesn't have the key "address", and the key "desc" looks like pk(....)#.... .

How can I figure out the id of the destiny address ? I already checked in two bitcoin explorers, that the output address of this transaction: "9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5" it is : 11HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1

In addition, I also tried to decode the hex valur of the vout, but there is no address key. Therefore, there is a p2sh key with and value that looks like an address id: 3ARTFmbLhbpY4BAhV6Ukvb9ULa6eHawAWW

What it is the way to obtain the right destiny address?

Example:

blockid: 2
txid: 9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5

Output of getrawtransaction(txid,1):

{'txid': '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5',
 'hash': '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5',
 'version': 1,
 'size': 134,
 'vsize': 134,
 'weight': 536,
 'locktime': 0,
 'vin': [{'coinbase': '04ffff001d010b', 'sequence': 4294967295}],
 'vout': [{'value': Decimal('50.00000000'),
   'n': 0,
   'scriptPubKey': {'asm': '047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77 OP_CHECKSIG',
    'desc': 'pk(047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77)#rgrfa75n',
    'hex': '41047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77ac',
    'type': 'pubkey'}}],
 'hex': '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d010bffffffff0100f2052a010000004341047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77ac00000000',
 'blockhash': '000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd',
 'confirmations': 792949,
 'time': 1231469744,
 'blocktime': 1231469744}


vout_hex = '41047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77ac'

Ouput of decodescript("vout_hex"):


{'asm': '047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77 OP_CHECKSIG',
 'desc': 'pk(047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77)#rgrfa75n',
 'type': 'pubkey',
 'p2sh': '3ARTFmbLhbpY4BAhV6Ukvb9ULa6eHawAWW'}

All in all, what should I do to get the right output address: 1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1?

2 Answers 2

3

It is impossible to give the correct address for this output, because this output doesn’t follow one of the patterns that have an address standard. The correct way to refer to this output’s “destination” is either “no address” and/or directly surfacing the output script (scriptPubKey) labeled accordingly.

I would recommend not to calculate and use arbitrary related data, since using a made-up address will only be confusing and misleading.

4

Those block explorers use an outdated notion of "address". This output simply has no address. The RPC output, as well as more modern block explorers such as https://mempool.space and https://blockstream.info correctly don't show one.

It is a pay-to-pubkey output, and no address format was ever defined for those. Historically, an address was simply a shorthand way of referring to a public key, and so it became established practice of showing pay-to-pubkey outputs as having the same address as their corresponding pay-to-pubkey-hash output with the same key.

This is now considered misleading, because one for example cannot send to this address and hope it'll be received by the same person; after all, it is actually a different output.

4
  • Hi Pieter, thanks 4 your answer it is true all you said. However, I use this code to obtain the address where the bitcoins were sent: import base58 import hashlib def decode_descriptor(desc): public_key_hex = desc.replace('pk(', '').replace(')#qnv32gt7', '') public_key_bytes = bytes.fromhex(public_key_hex) sha256_hash = hashlib.sha256(public_key_bytes).digest() sha256_hash = hashlib.sha256(sha256_hash).digest() checksum = sha256_hash[:4] extended_key = public_key_bytes + checksum address = base58.b58encode(extended_key) return address.decode('utf-8')
    – Block_Mole
    Jun 5, 2023 at 11:51
  • # Example: desc= 'pk(047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77)#rgrfa75n' decoded_address = decode_descriptor(descriptor) print(decoded_address) b'1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1'
    – Block_Mole
    Jun 5, 2023 at 11:54
  • 1
    @Block_Mole You can compute things that way if you want to match the historical behavior, but it's still meaningless. Jun 5, 2023 at 12:14
  • 1
    Again: that output has no address; there simply is no answer to the question "Which address were those BTC sent to?". Not all outputs have addresses. Jun 5, 2023 at 12:24

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.