DecodeParameters function python web3

decodingpythonweb3.py

Is there a function like "decodeParameters" for web3 python?

enter image description here

Regards

Best Answer

You can use the eth-abi module that web3 py uses internally, here is an example with a hex string:

from eth_abi import abi

## Taken from tx : 0xfdc9939cb6bd71bdec1f86eccd44dc7faa79f98c82dac2ae1910e383971fbe8d
## transferFrom(address from, address to, uint256 tokenId)
## From : 0x000000000000000000000000502aef69ff64845cba427d99a29cbc05df494bc2
## To   : 0x0000000000000000000000005e3150f45f7cb0c0d424c5eee12d422c93bc0877
## TokenId : 0x00000000000000000000000000000000000000000000000000000000000002ca
DATA = bytes.fromhex("000000000000000000000000502aef69ff64845cba427d99a29cbc05df494bc20000000000000000000000005e3150f45f7cb0c0d424c5eee12d422c93bc087700000000000000000000000000000000000000000000000000000000000002ca")

## With array inputs
decodedABI = abi.decode(['address', 'address', 'uint256'], DATA)

## Tuple of result(s) : ('0x502aef69ff64845cba427d99a29cbc05df494bc2', '0x5e3150f45f7cb0c0d424c5eee12d422c93bc0877', 714)
print(decodedABI)