Web3 python: how can I decode Input Data
Asked Answered
V

1

8

using web3 (python3) I am trying to decode InputData of the BSC transaction as seen on BscScan enter image description here

In some solutions I've found code below is being used:

import web3
from web3.contract import Contract
...
contract = web3.eth.contract(address=Web3.toChecksumAddress(tokenAddress), abi=abi)
contract.functions.decode_function_input(transaction.input)

However, the abi's doesn't seem to have this function "decode_function_input" defined, as I am getting an error:

"web3.exceptions.ABIFunctionNotFound: ("The function 'decode_function_input' was not found in this contract's abi. ", 'Are you sure you provided the correct contract abi?')"

I am 100% that the abi is correct. Also, on BscScan contract raw view, the function 'decode_function_input' indeed is not present.

Any other solutions, how to decode the Input Data?

Violist answered 11/11, 2021 at 21:32 Comment(0)
M
1

It's not contract.functions.decode_function_input, it is contract.decode_function_input()

Mastersinger answered 17/1, 2022 at 6:45 Comment(2)
It seems that I've forgotten the include the correct syntax and error due to so many tries. I have the code as you specified, however, I am getting this error: "ValueError: Could not find any function with matching selector"Violist
I've figured it out!!! I thought I need to use tokenAddress and ABI for the token in question, while it was the pancakeswap V2 router address that was actually required!Violist

© 2022 - 2024 — McMap. All rights reserved.