【问题标题】:Does bitcoin-js have a method to check unspent transaction status?bitcoin-js 是否有检查未使用交易状态的方法?
【发布时间】:2019-06-01 14:42:59
【问题描述】:

BlockCypher explorer 如何获取有关已用或未用交易状态的数据?

bitcoin-js 库是否有一些方法?

【问题讨论】:

    标签: blockchain bitcoin bitcoin-testnet blockcypher


    【解决方案1】:

    我不确定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 } ]
    

    【讨论】:

      猜你喜欢
      • 2019-02-14
      • 1970-01-01
      • 2018-09-21
      • 1970-01-01
      • 2015-09-12
      • 2013-02-12
      • 2022-09-22
      • 2021-12-02
      • 1970-01-01
      相关资源
      最近更新 更多