I have a private chain now and I want to query the transaction histories.I know that web3 has provide those methods web3.eth.blockNumber / web3.eth.getBlockTransactionCount / web3.eth.getTransactionFromBlock . So I can get the transactions history by get latest blocknumber(suppose it's n). Range from n to 0 to call web3.eth.getBlockTransactionCount(i), then get transactions by web3.eth.getTransactionFromBlock. but it's just time wasting and inefficient. so I'm wondering how can I get transaction histories from blocks efficient via web3 or rpc or anyway?
对于每个块,您可以将true
作为第二个参数传递给getBlock
:
web3.eth.getBlock(blockHashOrBlockNumber [, returnTransactionObjects] [, callback])
This code will give Transactions
details by Block Number.
async function GetBlocks(BlockNumber){
Block =await web3.eth.getBlock(BlockNumber)
Block.transactions.forEach(async(transaction) => {
let t=await web3.eth.getTransaction(transaction)
console.log(t)
})
}
GetBlocks(26154210)
If you have Array of Blocks. eg Blocks=[10000,10001,10002,10003...]. then use a for loop like this:-
Blocks.forEach(e => {
GetBlocks(e)
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.