BlockCypher 浏览器如何获取有关已用或未用交易状态的数据?
bitcoin-js
图书馆有一些方法吗?
我不确定bitcoin-js
lib,但 Blockcypher 有 API 方法:
const fetch = require('cross-fetch')
const getAddress = async address => {
const url = `https://api.blockcypher.com/v1/btc/test3/addrs/${address}`
const res = await fetch(url)
return await res.json()
}
getAddress('mitTmNgXyoEANondxZns8dS6GcXTzVhJW6')
.then(({txrefs}) => txrefs.filter(tx => tx.spent === false))
.then(data => console.log(data))
你会得到这样的
[ { tx_hash: 'bdbd9253b052cb17afdf42c006c69f6d9f7513d2176db1c088fdbd2381edf2de',
block_height: 1519165,
tx_input_n: -1,
tx_output_n: 1,
value: 15800000,
ref_balance: 32343852,
spent: false, // @docs tx status
confirmations: 60,
confirmed: '2019-05-31T20:43:22Z',
double_spend: false },
{ tx_hash: '4014e09c48ec4de6c4f1e82b38107f4ca77037e96e4989abe5ba5cf459d57700',
block_height: 1519149,
tx_input_n: -1,
tx_output_n: 1,
value: 10000,
ref_balance: 17044852,
spent: false, // @docs tx status
confirmations: 76,
confirmed: '2019-05-31T18:43:02Z',
double_spend: false } ]