获取比特币交易记录 比特币交易可以查到记录吗
importrequests
defget_address_transactions(address):
"通过Blockchain.infoAPI获取指定比特币地址的交易记录
"url=f"://blockchain.info/rawaddr/{address}"try:
response=requests.get(url)
response.raise_for_status()检查请求是否成功
data=response.json()
print(f"地址{address}的交易记录摘要:"print(f"交易数:{data.get('n_tx',0)}"print(f"接收:{data.get('total_received',0)/108}BTC"print(f"发送:{data.get('total_sent',0)/108}BTC"print(f"余额:{data.get('final_balance',0)/108}BTC"print(
最近交易:"
fortxindata.get('txs',[])[:5]:只显示最近5笔交易
print(f"交易哈希:{tx['hash']}"print(f"时间:{tx['time']}"print(f"确认数:{tx.get('block_height','未确认')}"print(""exceptrequests.exceptions.RequestExceptionase:
print(f"请求出错:{e}"__name__=="__"示例:查询一个公开的比特币地址
bitcoin_address="1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"比特币创世地址
get_address_transactions(bitcoin_address)
requests==2.31.0