I have a transaction with input data that looks like this:


I know that the last 40 characters is the token address which translates to

0x + 8051325147ec6df28f8f8b7fa4248e84c5a2e486

Is there any way to decode such input data? Do solidity contracts use some default encoding for input parameters?

  • when u send a transaction to a contract to call a function, the function knows what is coming in (type of the data) and that is why It can decode it
    – Majd TL
    Commented Oct 13, 2021 at 19:39
  • @MajdTL I know that it's going to be an address type. I want to basically repeat what contract is doing and decode it the way contract would decode it.
    – Marijus
    Commented Oct 14, 2021 at 10:10
  • Take look at this , they do something similar ethereum.stackexchange.com/questions/11144/…
    – Majd TL
    Commented Oct 14, 2021 at 10:55
  • @MajdTL this is not what I need as I don't have an ABI for this specific contract. I know that last 40 characters of this input data is of type address, therefore I want to find out how does Solidity contract decode this into actual address?
    – Marijus
    Commented Oct 14, 2021 at 11:11
  • medium.com/mycrypto/… maybe this will help understand how solidity do it. What I can say is: the contract knows which function it should be called using the id of that function (2293db57) and that function knows the data type of its Parameter so it knows how long it is and at which position it starts and end.
    – Majd TL
    Commented Oct 14, 2021 at 14:05

2 Answers 2


Solidity is a typed language, so it's aware of the types of function parameters. When you call a certain function on a contract, Solidity knows that the type of the first parameter is an address, and can decode it as such. ABI is automatically generated from the types specified in the Solidity source code.

For a simple case of just getting an address from this particular input data, you can just do something like this (in JS):

const input = '0x2293db5700000000000000000000000030823e060e8be429b34bd9192df9cad4b166a056';
const address = `0x${input.slice(-40)}`;

console.log(address); // 0x30823e060e8be429b34bd9192df9cad4b166a056

In other cases where you may want to decode other types of data, you can first slice of the first 4 bytes (8 hexadecimal characters), and use something like Ethers.js' ABI decoder:

import { defaultAbiCoder } from '@ethersproject/abi';

const input = '0x2293db5700000000000000000000000030823e060e8be429b34bd9192df9cad4b166a056';
const address = defaultAbiCoder.decode(['address'], input.slice(10));

console.log(address); // 0x30823e060e8be429b34bd9192df9cad4b166a056

You can replace address with the type of the parameter, and if your contract function has multiple input parameters, simply add them to the array.

  • The problem here is that the actual address is '0x8051325147ec6df28f8f8b7fa4248e84c5a2e486' since the contract for this function is not verified.
    – Marijus
    Commented Oct 17, 2021 at 16:35
  • Not sure what you mean by that. The input data you provided contains the address 0x30823e060e8be429b34bd9192df9cad4b166a056, not 0x8051325147ec6df28f8f8b7fa4248e84c5a2e486.
    – Morten
    Commented Oct 17, 2021 at 18:46
  • Take a look at this tx: bscscan.com/tx/… Input says it's 0x551eb7e6272297b4feee7e96c8ce343ba4282863 but the real token is actually 0xe5cdbbb16e451e6fc22a2cf04113706bd0ec6cb3
    – Marijus
    Commented Oct 17, 2021 at 19:56

If you go here: https://bscscan.com/address/0x890308ccaeb490a536ee70230f9183524b17f082#code You'll see a button to decompile the contract: enter image description here

It seems like you can work out the abi from the result: enter image description here

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.