func_obj,func_params解码以太坊交易时没有响应
我正在尝试使用,但是每当我尝试运行最后一行时,我都会收到以下错误:
valueerror:无法找到匹配的选择器
的任何功能
from web3 import Web3
import json
import requests
web3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/46cb623357d54c54b86ae7aa0afa1245'))
# Get transaction object
tx = web3.eth.get_transaction(0xd37e09810d624a3149913e6a769be1cf200d0c511b36008044a0922108fa488a)
# Get ABI for smart contract NOTE: Use "to" address as smart contract 'interacted with'
abi_endpoint = f"https://api.etherscan.io/api?module=contract&action=getabi&address={tx['to']}&apikey={'MDVQWNWT1ZXW2MV5TWKYU9P57WFY3F3P6J'}"
abi = json.loads(requests.get(abi_endpoint).text)
# Create Web3 contract object
contract = web3.eth.contract(address=tx["to"], abi=abi["result"])
# Decode input data using Contract object's decode_function_input() method
func_obj, func_params = contract.decode_function_input(tx["input"])
print(func_params)
该如何被修复?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经测试了您的代码,在大多数情况下似乎还不错。
It seems to be a problem with the abi belonging to the contract you're interacting with, since the code works successfully on, example these hashes (randomly selected from ethscan):
0xb670ab16162f8e4b00cbd57175b0dfb0025690b79a31876d802af84bcc793246
0x4BB2E49BF8965B6ACDF5C1B7C18E88E811A0E4704A6C37775D743CD8304054ADEA9
我做了一些谷歌搜索,并在此线程中遇到了相同的问题:
-DECODE-INPUT-DATA-使用web3-py-using-the-decode-function-inp”> https://ethereum.stackexchange.com/questions/70340/how-exactly-do-do-you-decode-inpode-input-data-data-using-web3-py - 使用Decode-function-inp
对不起,我无法为您提供一个问题的解决方案,但我希望它将您指向正确的方向!
I have tested your code and it seems fine in most cases.
It seems to be a problem with the abi belonging to the contract you're interacting with, since the code works successfully on, example these hashes (randomly selected from ethscan):
0xb670ab16162f8e4b00cbd57175b0dfb0025690b79a31876d802af84bcc793246
0x4bb2e49bf8965b6acdf5c1b7c18e8811a0e4704a6c3775d743cd8304054adea9
i did some googling myself and came over this thread that states the same problem:
https://ethereum.stackexchange.com/questions/70340/how-exactly-do-you-decode-input-data-using-web3-py-using-the-decode-function-inp
Sorry i couldnt give you an exact solution to the problem but i hope it points you in the right direction!