How does BlockCypher explorer get data about spent or unspent transaction status?
Does bitcoin-js
library have some methods for it?
I'm not sure about bitcoin-js
lib, but Blockcypher has API method:
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))
and you'll get sth like this
[ { 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 } ]