json 确定交易确认的区块链API

vohkndzv  于 2023-02-10  发布在  其他
关注(0)|答案(2)|浏览(212)

我正在尝试识别比特币区块链中的一笔交易是否已经确认,我使用以下URL从www.example.com访问了该交易的JSON表示blockchain.info:https://blockchain.info/tx/62f9419e56ac1b628840aaf52307867f9856d7a52b3c1d945a9938a3021cbf2c?show_adv=false&format=json
我找不到任何在响应中表明它有多少确认...

{"block_height":221580,"time":1361068368,"inputs":[{"prev_out":{"n":0,"value":100000000,"addr":"1NaPjDPGcfaVCBd3cTmy4zEPjRbDwzkW49","tx_index":53213157,"type":0}},{"prev_out":{"n":0,"value":100000,"addr":"1FDBdn8cseukiteu1myGQCfgYnncdMNpFk","tx_index":53252395,"type":0}},{"prev_out":{"n":0,"value":100000000,"addr":"13QRi4W5bq3FWrNGrWGcF1dH4mSWD6Huun","tx_index":52575903,"type":0}},{"prev_out":{"n":0,"value":100000000,"addr":"1MhEJx1BodWATGxoZ7az3GnmUQwx2adCG2","tx_index":53376409,"type":0}},{"prev_out":{"n":1,"value":90000000,"addr":"1FosGa87ZSjoagVu1j8djiJKzUeLkhhp6P","tx_index":53308634,"type":0}},{"prev_out":{"n":0,"value":200000,"addr":"1DZzEunCP1SxBsz2aZah2q9WAFuYSsDrq9","tx_index":53272656,"type":0}},{"prev_out":{"n":1,"value":98500000,"addr":"19q8NEgZKQcQMMx5z16JETbe1bx6StNZfj","tx_index":53506579,"type":0}},{"prev_out":{"n":0,"value":100000000,"addr":"15LXjh36usUspAYsGnhURVEnPn86W7SPSu","tx_index":53532799,"type":0}},{"prev_out":{"n":1,"value":119000000,"addr":"1PNbeqfPgMjjL6sLdXqkNZyCSkGFHop3bz","tx_index":53492488,"type":0}},{"prev_out":{"n":1,"value":150000000,"addr":"153hqmnNqUM8RGWdLE12tj74aAyS9U2pe7","tx_index":53283295,"type":0}},{"prev_out":{"n":0,"value":100000000,"addr":"149BGgDjaMyYfYnrja4asYtuUnpsBjobnH","tx_index":53440208,"type":0}},{"prev_out":{"n":167,"value":35000,"addr":"1F3eAsYGC45s2Q8XiE7ywGXMr8QLB8FTCD","tx_index":53578752,"type":0}},{"prev_out":{"n":862,"value":5000,"addr":"1CD4Dcy3yUiBejmQX1hKfJi1y5ysAX9RwZ","tx_index":53578752,"type":0}},{"prev_out":{"n":0,"value":60000000,"addr":"1Q7hDXko9U8MxoAZGmYk2se6tf8WFSQbUK","tx_index":53305081,"type":0}},{"prev_out":{"n":1,"value":98000000,"addr":"1RuMjWETvUPAUqfJKhZ4GBo5tKuszbDTA","tx_index":53521527,"type":0}},{"prev_out":{"n":0,"value":100000000,"addr":"17rBkeKtc7APY5PQjbicBbucfaUA1PZSpm","tx_index":53511134,"type":0}},{"prev_out":{"n":0,"value":169216027,"addr":"1EBz5v7dJfBPJzSwivVQcY19eT5hUBxa8w","tx_index":53194652,"type":0}},{"prev_out":{"n":1,"value":80000000,"addr":"1KLn85reRxN1JZL1S3gD2Kp2x8LZ14rz6S","tx_index":53194567,"type":0}},{"prev_out":{"n":0,"value":100000000,"addr":"1EppQ2h8Ddvp1vsoSb2DLJqJAws2DrYnv9","tx_index":53190665,"type":0}},{"prev_out":{"n":174,"value":2,"addr":"1CDDR1vZtZPWc48v4brHmka3tDpXbuT9wd","tx_index":53620404,"type":0}},{"prev_out":{"n":1,"value":100000000,"addr":"12zQxFPPh5rsUyakdZZyADj2N5bFRFZRcd","tx_index":53540021,"type":0}},{"prev_out":{"n":1,"value":801624197,"addr":"1JEjtpHB7aZJm3QSRp76qQqchFfs4TjDeE","tx_index":53526428,"type":0}},{"prev_out":{"n":1,"value":100000000,"addr":"1K1Sn9V775d7i94voiYLLUSaFNUQ9BVj9Q","tx_index":53430153,"type":0}},{"prev_out":{"n":1156,"value":1,"addr":"1CxXkpmJ9Nr4S9b3rKeKU5WWLXGp5nv553","tx_index":53619724,"type":0}},{"prev_out":{"n":0,"value":99950000,"addr":"1Hp5GdoX4oXmjUD6ZRKvXNJQCZp2sk712c","tx_index":53229930,"type":0}},{"prev_out":{"n":1,"value":98000000,"addr":"12aqif4GXBd17N6EFj4onrHLd8febY4n6j","tx_index":53160076,"type":0}},{"prev_out":{"n":0,"value":357452267,"addr":"146eveRJD2YnxvNBw4hHtZn8xR3LHHVxtH","tx_index":53651895,"type":0}},{"prev_out":{"n":1,"value":60000000,"addr":"1FZximueHPa9sqTZSg2Q4LAsg91dZaJK5D","tx_index":53640062,"type":0}},{"prev_out":{"n":1,"value":100000000,"addr":"12VL7U1BLf8kLrkN3sca9w5dGVhVAy1kvD","tx_index":53578503,"type":0}},{"prev_out":{"n":0,"value":67315003,"addr":"1BbYNxYAGJJJz6wP4pK5eHmwcieRSiPDZm","tx_index":53437082,"type":0}},{"prev_out":{"n":1,"value":100000000,"addr":"1DoTTLAs5VUm2QHBXeL34h2kSfYnqSpsCj","tx_index":53116751,"type":0}},{"prev_out":{"n":1,"value":195951000,"addr":"1Epje2MuDrckP4zVJmRXyEu5jWby2MvgHy","tx_index":53599874,"type":0}},{"prev_out":{"n":25,"value":1,"addr":"1CdACYi1JQDGekGPPc8bd3vq5d5v6s2KKY","tx_index":53620401,"type":0}},{"prev_out":{"n":105,"value":2,"addr":"15dsKW8yotixATZdDomBkRJh7YvzJJ4z7X","tx_index":53620401,"type":0}},{"prev_out":{"n":1,"value":90000000,"addr":"17ra7TQoPSmrxvLXGhupexd3Dk9fnZLM8Q","tx_index":53675760,"type":0}},{"prev_out":{"n":0,"value":100000000,"addr":"1Fm2j4k7XK8veWdeJaxDuZdujdQQh3mj9j","tx_index":53696368,"type":0}},{"prev_out":{"n":39,"value":1500,"addr":"1PB3DrsvvTMkxv7AoV5FdMAVbrnv1R9AvF","tx_index":53366964,"type":0}},{"prev_out":{"n":1,"value":70000000,"addr":"1HDxhL7H8thYC9RaLwACRoeTP6cjTERzkq","tx_index":53197639,"type":0}},{"prev_out":{"n":0,"value":60000000,"addr":"1Mzt5Y815fnf3rbCigx411bmUGqTiAMMMf","tx_index":53534495,"type":0}},{"prev_out":{"n":0,"value":3000000,"addr":"191cP1rSfJX9kATiujqbavKPHta8ryPbUk","tx_index":53397518,"type":0}},{"prev_out":{"n":0,"value":80000000,"addr":"1E7zhSRBexQYN98PxKZrnocZzb7yuCoobF","tx_index":53616202,"type":0}},{"prev_out":{"n":0,"value":60000000,"addr":"1DNGJSkn2jaBtzHpeu2EV8Za7GzLkYRKrk","tx_index":53211317,"type":0}},{"prev_out":{"n":0,"value":100000000,"addr":"1FPHkZfftpfBVYg46sBAZmU7k4R6nMWjgm","tx_index":53714935,"type":0}},{"prev_out":{"n":1,"value":80000000,"addr":"1NJmpCAfoeZa8M8RoWCT1PAs85k4URKwuL","tx_index":53437066,"type":0}},{"prev_out":{"n":1,"value":320000000,"addr":"17MCmBPgv2SEKsmGf1o7X6qbK59C1Pnwr3","tx_index":53584050,"type":0}},{"prev_out":{"n":0,"value":100000000,"addr":"1KrtH7ceJthEfBFd8t9G4Vohj2myGB1eDj","tx_index":53212472,"type":0}},{"prev_out":{"n":1,"value":103000000,"addr":"13zZzqKR3XYPUKpLWvGkimSJbDMaJim9Ru","tx_index":53218032,"type":0}},{"prev_out":{"n":1,"value":92500000,"addr":"1G5EdCerj7Yryoc4tpmCrFe7rvkbLcjHtz","tx_index":53633538,"type":0}},{"prev_out":{"n":0,"value":97800000,"addr":"1K59Q1UJSULsHhs4Rv8PiakEhDK689jQSj","tx_index":53232395,"type":0}}],"vout_sz":2,"relayed_by":"184.71.200.221","hash":"62f9419e56ac1b628840aaf52307867f9856d7a52b3c1d945a9938a3021cbf2c","vin_sz":52,"tx_index":53744354,"ver":1,"out":[{"n":0,"value":1000000,"addr":"1cm8zPZqjfWs5MBg8yKxJwWvDAkqF4CVu","tx_index":53744354,"type":0},{"n":1,"value":5000000000,"addr":"1EGP5pSnttKRdAcPxdiTviSrjsyHEAnXhy","tx_index":53744354,"type":0}],"size":9439}
mlmc2os5

mlmc2os51#

比特币上的“确认”概念本质上是指自包含交易的区块以来,已经生成了多少个区块。换句话说,你必须发出另一个请求,才能获得当前的网络区块数(http://blockchain.info/q/getblockcount),并且确认计数变为current_block_count - transaction_block_height + 1。注意,block_height仅在至少一个块从(即,新事务甚至可以不包括该元素)。

46qrfjad

46qrfjad2#

下面是用于确定事务的块计数的示例nodejs代码。

const axios = require('axios');

async function getConfirmations(transactionId) {
  try {
    const response = await 

    axios.get(`https://blockchain.info/rawtx/${transactionId}`);
    const blockHeight = response.data.block_height;
    const currentBlockHeight = await axios.get(`https://blockchain.info/latestblock`)
      .then(res => res.data.height);

    const confirmations = currentBlockHeight - blockHeight + 1;
    return confirmations;
  } catch (error) {
    console.error(error);
  }
}

相关问题