Ensure you are instantiating a Web3
object as mentioned in the quickstart docs before calling into web3.eth.getBlock
to setup the eth
module functions.
from web3 import Web3, TestRPCProvider
w3 = Web3(TestRPCProvider())
A look at the code for web3.eth shows us that class Eth(Module):
contains def getBlock
. If you also look at the definition of Module
, you see see that the attach
function is used to actually redefine web3.eth
with the behavior you want.
The attach
function is normally called in the web3/main.py
:
for module_name, module_class in modules.items():
module_class.attach(self, module_name)
Note in one of the loops above the module_class
is Eth
and module_name
is "eth"
.
You are likely missing this logic, so ensure you are instantiating a Web3
object before calling into web3.eth.getBlock
.