为什么BLOCKCHAIN.COM API只返回接收者的BASE58地址而省略BECH32?
根据这篇帖子,我想查看比特币区块链中#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)