【发布时间】:2021-12-04 19:34:15
【问题描述】:
我是 web3 的新手。最近我正在尝试根据this article 解码以太坊上的一些日志。但是当我尝试使用像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”。老实说,我认为这行不通。如何解决这个问题?
【问题讨论】: