Current location - Music Encyclopedia - Chinese History - How does Ethereum use web3.js or rpc interface to obtain transaction data, transaction time and confirmation number?
How does Ethereum use web3.js or rpc interface to obtain transaction data, transaction time and confirmation number?
If you want to query the transaction records on the main network, you can use etherscan. However, if you build your own private chain, how should you query the transaction records?

The answer is that you need to monitor the logs on the chain yourself, save them in the database, and then query them in this database. For example:

var? addr? =? " 0x bfb 2 e 296d 9 cf 3 e 593 e 7998 1235 aed 29 ab 9984 c0f "

var? Filter? =? Web3.eth.filter({fromBlock:0, toBlock:' latest',? Address:? addr });

Filter.get (function? (er,? Trading)? {

Transactions.forEach (function? (tx)? {

var? txInfo? =? web 3 . eth . get transaction(tx . transaction hash);

//At this time, the transaction information txInfo can be stored in the database.

});

}); Web3.eth.filter () is used to monitor the logs on the chain, and web3.eth.getTransaction () is used to extract the information of the specified transaction. Once the transaction information is obtained, it can be stored in the database for query.

Recommend an introduction to actual combat, which can be read: Ethereum Tutorial.