How to get the BlockNumber property and object contents in Python

Question:

I’m trying to get the blockNumber connected to my URL Infura. But I get a property and cannot see what is in the object.

from web3 import Web3
import web3

infura_url = 'myUrl'

w = Web3(Web3.HTTPProvider(infura_url))

print(w.isConnected())
print(web3.eth.Eth.blockNumber)
Asked By: Srevinu

||

Answers:

This should work for you:

from web3 import Web3

infura_url = "https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID"
web3 = Web3(Web3.HTTPProvider(infura_url))

print(web3.isConnected())
print(web3.eth.blockNumber)
Answered By: Zulhilmi Zainudin
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.