invoke web3.eth.get_transaction() but it shows "has no attribute 'get_transaction'"

Viewed 576

I'm new on web3. Recently I'm trying to decode some logs on Ethereum according to this article. But when I try to use code like receipt=web3.eth.get_transaction(transaction_hash). It keeps showing me that module 'web3.eth' has no attribute 'get_transaction'. But apparently, my computer has this file. And, doesn't this kind of statement mean "I'm trying to call a function in web3.eth"? Why is it regarded as "calling an attribute"?

Here are my codes:

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

And if I directly put my API key of Etherscan at the end of line 10, pycharm will mark an error in there. So I enclose the API key in double quotes and assign it to the variable "mykey". Honestly, I don't think this will work. How to solve this problem?

1 Answers

enter image description here

Well, it's working for my code :

from web3 import Web3

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

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

print(result)

Make Sure Below Things

1: The web3 library is up to date 2: You don't have any file in your system named web3.py or Web3.py or something like this.

Related