web3.js – 查询区块中的交易

要查询某个区块中的指定交易信息,可以使用web3.eth.getTransactionFromBlock(txHash, blockNum)函数。

示例

app.js

const Web3 = require('web3')
const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY') // YOUR_INFURA_API_KEY替换为你自己的key

// 查询某个区块中的指定交易信息
const hash = '0x66b3fd79a49dafe44507763e9b6739aa0810de2c15590ac22b5e2f0a3f502073'
web3.eth.getTransactionFromBlock(hash, 2).then(console.log)

运行app.js:

$ node app

输出

{ blockHash:
   '0x66b3fd79a49dafe44507763e9b6739aa0810de2c15590ac22b5e2f0a3f502073',
  blockNumber: 5855123,
  from: '0xF7848Afd92397fbA7b08915639faE4f29F16e4cf',
  gas: 66666,
  gasPrice: '66000000000',
  hash:
   '0x2d14bc5f3ff31f312297715e73d7a04c72ae93f4466b881f2a2780b41b6e3c4f',
  input:
   '0xa9059cbb00000000000000000000000099fe5d6383289cdd56e54fc0baf7f67c957a88880000000000000000000000000000000000000000000001144b9d7142dc2b0000',
  nonce: 1,
  r:
   '0xb96c587cb0ddcb147b04a72a857431660d52ad0dcb49b136652e07beee2da66a',
  s:
   '0x4e1d1547b99c8c338483d1ff7521e575547f5dde85b990ebe8e6cbbf21763067',
  to: '0x8912358D977e123b51EcAd1fFA0cC4A7e32FF774',
  transactionIndex: 2,
  v: '0x26',
  value: '0' }


浙ICP备17015664号 浙公网安备 33011002012336号 联系我们 网站地图  
@2019 qikegu.com 版权所有,禁止转载