为什么BLOCKCHAIN.COM API只返回接收者的BASE58地址而省略BECH32?

-1 投票
1 回答
543 浏览
提问于 2025-06-18 04:09

根据这篇帖子,我想查看比特币区块链中#630873这个区块里的所有交易。

import requests

r = requests.get('https://blockchain.info/block-height/630873?format=json')
data = r.json()

在检查这个区块中(通过data['blocks'][0]['tx'][4]['out'])的第4笔交易时,我得到了这个结果:

[{'n': 0,
  'script': '0014d0aba2c93bac0fcafafe43f2ad39d664ba51910d',
  'spent': False,
  'tx_index': 0,
  'type': 0,
  'value': 19571491},
 {'addr': '1A7tWftaGHohhGcJMVkkm4zAYnF53KjRnU',
  'n': 1,
  'script': '76a9146406a0a47d4ed716f6ddf2eeca20c725932763f188ac',
  'spending_outpoints': [{'n': 0, 'tx_index': 0}],
  'spent': True,
  'tx_index': 0,
  'type': 0,
  'value': 3928145371}]

这里只包含了这笔交易第二个收款人的addr。在blockchain.com网站上,这笔交易的样子是这样的:

这里插入图片描述

在那儿可以看到bc1q6z469jfm4s8u47h7g0e26wwkvja9rygdqpeykd这个地址。请问如何通过API访问它呢?

这个无法访问的地址是BECH32格式,而可以访问的那个是BASE58格式(我在网站上点击地址时得知的)。我能获取到收款人地址的那些交易,都是BASE58格式的。

这是我提到的区块的链接。

相关问题:

  • 暂无相关问题
暂无标签

1 个回答

1

Blockchain.com 的 API 目前还不完全支持 bech32 地址。

所以你可以选择其他服务提供商,比如 Blockstream 或 Blockchair。

或者你也可以通过 P2WPKH 脚本来生成地址。例如,可以使用 BitcoinLib(免责声明:这是我自己的库):

from bitcoinlib.transactions import script_deserialize
from bitcoinlib.keys import Address

locking_script = '0014d0aba2c93bac0fcafafe43f2ad39d664ba51910d'
scr = script_deserialize(locking_script)
a = Address(hashed_data=scr['hashes'][0], script_type=scr['script_type'])
print(a.address)

撰写回答