【问题标题】:invoke web3.eth.get_transaction() but it shows "has no attribute 'get_transaction'"调用 web3.eth.get_transaction() 但它显示“没有属性'get_transaction'”
【发布时间】: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”。老实说,我认为这行不通。如何解决这个问题?

【问题讨论】:

    标签: ethereum web3py


    【解决方案1】:

    嗯,它适用于我的代码:

    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 或类似文件的文件。

    【讨论】:

      猜你喜欢
      • 2022-07-26
      • 2020-12-27
      • 2023-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-20
      • 1970-01-01
      相关资源
      最近更新 更多