首页 > 解决方案 > 调用 web3.eth.get_transaction() 但它显示“没有属性'get_transaction'”

问题描述

我是 web3 的新手。最近我正在尝试根据这篇文章解码以太坊上的一些日志。但是当我尝试使用类似receipt=web3.eth.get_transaction(transaction_hash). 它一直在向我展示module 'web3.eth' has no attribute 'get_transaction'。但显然,我的电脑有这个文件。而且,这种说法不是意味着“我正在尝试调用 web3.eth 中的函数”吗?为什么将其视为“调用属性”?

这是我的代码:

import json
import requests
from web3 import Web3

w3=Web3(Web3.HTTPProvider(infura_project))
receipt=web3.eth.get_transcation(transaction Hash) //always show error "web3.eth has no attribute get_transaction"
log=receipt["logs"][2]
smart_contract=log["address"]
mykey="MY API Key of Etherscan" 
adi_endpoint=f"https://api.etherscan.io/api?module=contract&action=getabi&address={smart_contract} & apikey={mykey}" //problem (2)
abi=json.load(requests.get(adi_endpoint).text)
//decode info

如果我直接将我的 Etherscan API 密钥放在第 10 行的末尾,pycharm 会在其中标记一个错误。因此,我将 API 密钥用双引号括起来,并将其分配给变量“mykey”。老实说,我认为这行不通。如何解决这个问题呢?

标签: ethereumweb3py

解决方案


在此处输入图像描述

好吧,它适用于我的代码:

from web3 import Web3

web3 = Web3(Web3.HTTPProvider('https://bsc-dataseed.binance.org/'))

result = web3.eth.get_transaction('0x690ffe41506456a3936aa2d4dd05de6601f1fbe7eb3fe23c2bcc4d17714ea617')

print(result)

确保下面的东西

1:web3 库是最新的 2:您的系统中没有任何名为 web3.py 或 Web3.py 或类似的文件。


推荐阅读