1

I'm decoding the raw input data of an eth transaction. I have the function signature to decode the input with.

I'm using the eth_abi library for python.

res = eth_abi.decode(['address', 'address'], eth_utils.decode_hex(input))

eth_utils.decode_hex() converts hex to bytes.

this throws:

Padding bytes were not empty: b'\x1c\xffy\xcd\x00\x00\x00\x00\x00\x00\x00\x00'

Some examples:

paramList= ['address', 'bool']
input= "0xa9059cbb000000000000000000000000b25cd920f3cb29e9de2a1f55577a3fe539d187a70000000000000000000000000000000000000000000000000000000159b4fa00"
paramList= ['uint256']
input= "0x2e1a7d4d0000000000000000000000000000000000000000000000000214e8348c4f0000"

Can anyone help me out??

2
  • looks like some thing wrong with the input, can you give the sample input value that cause the error ?
    – minhhn2910
    Jan 1, 2023 at 5:50
  • I've added some examples. Thanks. Jan 1, 2023 at 12:13

2 Answers 2

2

There are two problems:

  1. You must skip the 4-byte function signature in your input data before calling eth_abi.decode
  2. You used the wrong paramList in one of your example.

To decode it, you can use:

eth_abi.decode(paramList, eth_utils.decode_hex(input)[4:])

The first example you gave should be decoded as transfer(address,uint256) because the second argument is not "bool" encoded, See the function signature here

paramList = ['address', 'uint256']
input= "0xa9059cbb000000000000000000000000b25cd920f3cb29e9de2a1f55577a3fe539d187a70000000000000000000000000000000000000000000000000000000159b4fa00"
eth_abi.decode(paramList, eth_utils.decode_hex(input)[4:])

Output: ('0xb25cd920f3cb29e9de2a1f55577a3fe539d187a7', 5800000000)

The second example is ok to be decoded using the above:

eth_abi.decode(['uint256'], eth_utils.decode_hex("0x2e1a7d4d0000000000000000000000000000000000000000000000000214e8348c4f0000")[4:])

Output : 150000000000000000

Read more on ABI encoding and why paramList is wrong and you should skip the first 4-byte: Solidity Documentation on ABI encoding

0

'padding bytes were not empty' means the hex value you are passing has more than one value in it.

log out the input you are feeding eth_utils.decode_hex(), and slice the signature (or other value) from the front of the hex literal. Append 0x to the front of the resulting hex, if necessary, and try again.

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.