enter image description here

I receive the input data as the image shows. And when I try to decode it with the method:

String inputdata = null;

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

if (tx.isPresent()) {
    inputdata = tx.get().getInput();

byte[] bytes = Hex.decodeHex(inputdata.substring(2).toCharArray());
System.out.println(new String(bytes, "UTF-8"));

this is what I have in the output:

enter image description here

So I wanted to know if there is another way to decode or what am I doing wrong to decode it?

  • 2
    You would essentially need the ABI for the smart contract to do this. Without that, you don't know what the data types of the parameters are, so you can't decode them.
    – user19510
    Jan 9, 2019 at 3:59
  • 1
    I have the ABI file and the container, as well as having the contract envelope. Also in Rinkeby.etherscan.io add the contract code so that the input data can be decoded. Jan 9, 2019 at 20:32
  • 1
    I don't know what a "container" or "contract envelope" mean in this context. But if you have the ABI, then you can accomplish this task, though I don't know how to do it in web3j. You may have to write your own code or dive into the ABI module.
    – user19510
    Jan 9, 2019 at 20:59

1 Answer 1


I had the same requirement and started to hack this into web3j contract wrapper generator. Due to the (IMHO) overly complicated approach I abandoned this and instead wrote my own, standalone java library for this. You don't need web3j at all, you'll only need to Contract's ABI in JSON format.


Usage Example:

// Abi can be found here: https://etherscan.io/address/0x7a250d5630b4cf539739df2c5dacb4c659f2488d#code
AbiDecoder uniswapv2Abi=new AbiDecoder(pathToAbiJsonFile).getFile());

// tx: https://etherscan.io/tx/0xde2b61c91842494ac208e25a2a64d99997c382f6aaf0719d6a719b5cff1f8a07
String inputData="0x18cbafe5000000000000000000000000000000000000000000000000000000000098968000000000000000000000000000000000000000000000000000165284993ac4ac00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000d4cf8e47beac55b42ae58991785fa326d9384bd10000000000000000000000000000000000000000000000000000000062e8d8510000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";

 * #  Name          Type       Data
 * ----------------------------------------------------------------------
 * 0  amountIn      uint256    10000000
 * 1  amountOutMin  uint256    6283178947560620
 * 2  path          address[]  0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
 *                             0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
 * 3  to            address    0xD4CF8e47BeAC55b42Ae58991785Fa326d9384Bd1
 * 4  deadline      uint256    1659426897

DecodedFunctionCall decodedFunctionCall=uniswapv2Abi.decodeFunctionCall(inputData);

System.out.println(decodedFunctionCall.getName()); // prints swapExactTokensForETH

It's still a young project, if you encounter problems (e.g. with specific contracts) please let me know via the github project issue tracker.

Hope that helps!

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.