How can I retrieve transaction details (including the input data) from a txHash using Web3j?

enter image description here

I tried the following method:

public void buscarHhash(Web3j web3, String txHash) throws IOException {
    String inputdata;

    EthSendTransaction ethSendTransaction = null;
    Request<?, EthTransaction> transactionReceipt = web3.ethGetTransactionByHash(txHash);
            .ifPresent(tx -> {
                inputdata = tx.getInput();

This method does not seem to work, and I don't know if I'm doing it right.

Does anyone know how to do it? Not necessarily with the method that I used.

enter image description here

1 Answer 1


The error you're having appears to be from your handling of the optional value through a lambda function. You could perhaps try it the following way (without the use of a lambda function):

String inputdata;

Optional<Transaction> tx = web3.ethGetTransactionByHash(txHash).send().getTransaction();

if (tx.isPresent()) {
    inputdata = tx.get().getInput();
  • thank you very much for your help. I am now receiving this data "receive ===> 0x070ec83b000000000000000000000000000000000000 - ad infinitum" and I wanted to know if you could recommend me to decode them or it might be possible to receive them as the "input data" image shows. Commented Jan 8, 2019 at 23:50
  • 1
    I'm not sure, perhaps this can help github.com/web3j/web3j/issues/489 Commented Jan 9, 2019 at 10:13
  • Thank you very much, it helps me to get uint and the address, but with the chain I could not: / Commented Jan 14, 2019 at 23:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.