DEV Community

drake
drake

Posted on • Edited on

查询BTC地址的账户余额和交易记录

import requests
import time

# address = '15aayQV7Dx6u22wLnR2fe8DVmuVraUQXQn'
address = 'bc1qa9sw3l5ucl9zse3sjmtmxh5zkzylaw0vp3xtky'
url = f"https://blockchain.info/rawaddr/{address}"
response = requests.get(url)
data = response.json()

# data = response.json()

# 输出地址的基本信息
total_received = data['total_received'] / 1e8  # 转换为 BTC
total_sent = data['total_sent'] / 1e8  # 转换为 BTC
final_balance = data['final_balance'] / 1e8  # 转换为 BTC

print(f"地址: {address}")
print(f"接收到的总金额: {total_received} BTC")
print(f"发送的总金额: {total_sent} BTC")
print(f"当前余额: {final_balance} BTC")
print("-" * 60)



# 输出交易记录
for tx in data['txs']:
    # print(tx)
    print(f"交易哈希: {tx['hash']}")
    output_addr = tx['out']
    if output_addr:
        output_addr = output_addr[0]['addr']
        print(f'转出接受地址:{output_addr}')
    date_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(tx['time']))
    print(f"时间: {date_str}")
    print(f"总金额: {tx['result'] / 1e8} BTC")
    print("-" * 30)


Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up