简体   繁体   中英

Web3j: How to get Ethereum transaction information (Java not JS)

I've just started using Web3j and am having some basic trouble.

I've successfully figured out how to get an EthBlock and retrieve all of the information inside of it. I'd like to see the list of transactions in the block, but I can't figure out how.

I can call

 List<TransactionResult> transactions = ethBlock.getBlock().getTransactions();

I should be able to look through this list and get information about each transaction. But all I can seem to do with a TransactionResult is cast it to the very unuseful TransactionHash. What I'd like is a TransactionObject from which I can extract lots of information.

How do I get at the real transaction data?

And on another note: is there any reason why there doesn't seem to be any Web3j JavaDoc??

It's in there, it's just confusing on how to get to it because of how they used generics. Example below will output the sender of each transaction in the LATEST block:

List<EthBlock.TransactionResult> txs = web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, true).send().getBlock().getTransactions();
txs.forEach(tx -> {
  EthBlock.TransactionObject transaction = (EthBlock.TransactionObject) tx.get();

  System.out.println(transaction.getFrom());
});

Keep in mind that this is the TransactionObject (the tx sent), not the resulting TransactionReceipt that contains the result of the tx being mined.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM