I am trying to decode the hex data of a transaction. For testing purposes I am using the transaction that can be found here https://kovan.etherscan.io/tx/0xad76a2d244b66d44415135dedd03a127bbfdf36bf0eee68a7c857f8dff7be7fa

It clearly states that the function is Function: addToCurrentNumber(uint256 _toAdd) hence the input type is uint256 and the original hex value is 0xa934861a0000000000000000000000000000000000000000000000000000000000000005

The decoded value can also be seen as 5.

Now in my code I have the following

use ethers::abi::decode;
use ethers::abi::ParamType;
use ethers::core::utils::hex::decode as hex_decode;
fn main() {
    let vec1 = hex_decode("a934861a0000000000000000000000000000000000000000000000000000000000000005").unwrap();
    let data: &[u8] = vec1.as_slice();
    let result = decode(
    println!("{:?}", result);

But when I run this, the output is [Uint(76533672992909578901694265460808195815504318440232336607848770502130973802496)] which is not what I was expecting. I was expecting 5.

Am I doing something wrong? Or this is working as expected and I am missing the API?


1 Answer 1


Markus Schick - was absolutely right: а function selector is the first 4 bytes of the call data for a function call that specifies the function to be called In your case selector is - 0xa934861a (addToCurrentNumber) the rest is a number: 0000000000000000000000000000000000000000000000000000000000000005

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.