func_obj,func_params解码以太坊交易时没有响应

发布于 2025-02-10 01:32:51 字数 1180 浏览 1 评论 0 原文

我正在尝试使用,但是每当我尝试运行最后一行时,我都会收到以下错误:

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)

该如何被修复?

I am trying to decode a transaction using the steps from https://medium.com/coinmonks/discovering-the-secrets-of-an-ethereum-transaction-64febb00935c, but whenever I try to run the last line I get the following error:

ValueError: Could not find any function with matching selector

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)

How can this be fixed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转身以后 2025-02-17 01:32:51

我已经测试了您的代码,在大多数情况下似乎还不错。

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文