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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With