如何从 https://blockchain.info/rawaddr/$address 获取交易金额
How to get the transaction amount from https://blockchain.info/rawaddr/$address
我正在尝试使用 https://blockchain.info/rawaddr/ api 跟踪一些比特币地址及其交易。它 return 我需要的所有交易,但我没有在响应中看到转移的金额。
这是我用来发出请求的代码。
import pandas, json
transactions_url = 'https://blockchain.info/rawaddr/$address?limit=2'
df = pandas.read_json(transactions_url)
transactions = df['txs']
print(json.dumps(transactions[0], indent=4))
结果是这样的
{
"hash": "1b99a2bf4c6031a502317b458505f7d3b281382fcd356b4a772b44359ace97c2",
"ver": 2,
"vin_sz": 1,
"vout_sz": 3,
"size": 330,
"weight": 876,
"fee": 443,
"relayed_by": "0.0.0.0",
"lock_time": 0,
"tx_index": 6846632386013317,
"double_spend": false,
"time": 1646966970,
"block_index": 726792,
"block_height": 726792,
"inputs": [
{
"sequence": 4294967293,
"witness": "03004730440220034fc9a74b0c33a52b23775ba9bbec914e37a6aadacb81555dba82516c20e5030220227a5be7eb380f18dc00a7cdcbb55624d847c0f92cee971ce07a4c406bf2e77f014751210316544e44223d8a1ecac82c34f5356ee75afa0f7077e8e853108ba762d02c93742103787b6696302010cac658700e7eb9e3cb21a7fc2b5d70476d8c4478134a5bab7052ae",
"script": "22002088d160a79f20a5b77c3992b7d3b3cf95f050b3189d8d90d2a15718563ea15aae",
"index": 0,
"prev_out": {
"tx_index": 3467002486392617,
"value": 951574,
"n": 4,
"type": 0,
"spent": true,
"script": "a9146df81ff90e8fa2506d1010fd212d6d10794ceda187",
"spending_outpoints": [
{
"tx_index": 6846632386013317,
"n": 0
}
],
"addr": "3BiUpUPvCsLqp2WP981EM8gci1tAwWsgJ8"
}
}
],
"out": [
{
"type": 0,
"spent": false,
"value": 7558,
"spending_outpoints": [],
"n": 0,
"tx_index": 6846632386013317,
"script": "76a914ee2dd6a6b295ece7f4f90e958fc5dcffdf73b50588ac",
"addr": "1NiNja1bUmhSoTXozBRBEtR8LeF9TGbZBN"
},
{
"type": 0,
"spent": false,
"value": 37761,
"spending_outpoints": [],
"n": 1,
"tx_index": 6846632386013317,
"script": "0014b5aea3218d45f143d344c3bfecca196aaea15e62",
"addr": "bc1qkkh2xgvdghc5856ycwl7ejsed2h2zhnzs432t9"
},
{
"type": 0,
"spent": true,
"value": 905812,
"spending_outpoints": [
{
"tx_index": 2010943634944169,
"n": 8
}
],
"n": 2,
"tx_index": 6846632386013317,
"script": "00149cb174567efa8e3a83737bdbb52c2902dfdef92c",
"addr": "bc1qnjchg4n7l28r4qmn00dm2tpfqt0aa7fvlezahn"
}
],
"result": 7558,
"balance": 3657877538
}
我无法在 JSON 回复中看到转账金额 (0.00951131 BTC / $388.28)。 (这只是我随机发现的一笔交易)
有没有什么我没有看到的,或者我是否必须使用 returned 数据以某种方式计算数量?
谢谢。
我想出了如何获取转账金额。只需将所有输入加在一起并减去费用。 (太糟糕了,我之前不知道区块链究竟是如何工作的)。我放了这段代码来获取金额。
import pandas, json
transactions_url = 'https://blockchain.info/rawaddr/$address?limit=10'
df = pandas.read_json(transactions_url)
transactions = df['txs']
for transaction in transactions:
inputValue = 0
for i in transaction['inputs']:
inputValue += i['prev_out']['value']
print(transaction['hash'])
print((inputValue - transaction['fee'])*0.00000001)
我正在尝试使用 https://blockchain.info/rawaddr/ api 跟踪一些比特币地址及其交易。它 return 我需要的所有交易,但我没有在响应中看到转移的金额。
这是我用来发出请求的代码。
import pandas, json
transactions_url = 'https://blockchain.info/rawaddr/$address?limit=2'
df = pandas.read_json(transactions_url)
transactions = df['txs']
print(json.dumps(transactions[0], indent=4))
结果是这样的
{
"hash": "1b99a2bf4c6031a502317b458505f7d3b281382fcd356b4a772b44359ace97c2",
"ver": 2,
"vin_sz": 1,
"vout_sz": 3,
"size": 330,
"weight": 876,
"fee": 443,
"relayed_by": "0.0.0.0",
"lock_time": 0,
"tx_index": 6846632386013317,
"double_spend": false,
"time": 1646966970,
"block_index": 726792,
"block_height": 726792,
"inputs": [
{
"sequence": 4294967293,
"witness": "03004730440220034fc9a74b0c33a52b23775ba9bbec914e37a6aadacb81555dba82516c20e5030220227a5be7eb380f18dc00a7cdcbb55624d847c0f92cee971ce07a4c406bf2e77f014751210316544e44223d8a1ecac82c34f5356ee75afa0f7077e8e853108ba762d02c93742103787b6696302010cac658700e7eb9e3cb21a7fc2b5d70476d8c4478134a5bab7052ae",
"script": "22002088d160a79f20a5b77c3992b7d3b3cf95f050b3189d8d90d2a15718563ea15aae",
"index": 0,
"prev_out": {
"tx_index": 3467002486392617,
"value": 951574,
"n": 4,
"type": 0,
"spent": true,
"script": "a9146df81ff90e8fa2506d1010fd212d6d10794ceda187",
"spending_outpoints": [
{
"tx_index": 6846632386013317,
"n": 0
}
],
"addr": "3BiUpUPvCsLqp2WP981EM8gci1tAwWsgJ8"
}
}
],
"out": [
{
"type": 0,
"spent": false,
"value": 7558,
"spending_outpoints": [],
"n": 0,
"tx_index": 6846632386013317,
"script": "76a914ee2dd6a6b295ece7f4f90e958fc5dcffdf73b50588ac",
"addr": "1NiNja1bUmhSoTXozBRBEtR8LeF9TGbZBN"
},
{
"type": 0,
"spent": false,
"value": 37761,
"spending_outpoints": [],
"n": 1,
"tx_index": 6846632386013317,
"script": "0014b5aea3218d45f143d344c3bfecca196aaea15e62",
"addr": "bc1qkkh2xgvdghc5856ycwl7ejsed2h2zhnzs432t9"
},
{
"type": 0,
"spent": true,
"value": 905812,
"spending_outpoints": [
{
"tx_index": 2010943634944169,
"n": 8
}
],
"n": 2,
"tx_index": 6846632386013317,
"script": "00149cb174567efa8e3a83737bdbb52c2902dfdef92c",
"addr": "bc1qnjchg4n7l28r4qmn00dm2tpfqt0aa7fvlezahn"
}
],
"result": 7558,
"balance": 3657877538
}
我无法在 JSON 回复中看到转账金额 (0.00951131 BTC / $388.28)。 (这只是我随机发现的一笔交易)
有没有什么我没有看到的,或者我是否必须使用 returned 数据以某种方式计算数量?
谢谢。
我想出了如何获取转账金额。只需将所有输入加在一起并减去费用。 (太糟糕了,我之前不知道区块链究竟是如何工作的)。我放了这段代码来获取金额。
import pandas, json
transactions_url = 'https://blockchain.info/rawaddr/$address?limit=10'
df = pandas.read_json(transactions_url)
transactions = df['txs']
for transaction in transactions:
inputValue = 0
for i in transaction['inputs']:
inputValue += i['prev_out']['value']
print(transaction['hash'])
print((inputValue - transaction['fee'])*0.00000001)