Design a site like this with
Get started

Inspecting Ethereum’s Blocks: The Web3py Way

Ethereum is a public blockchain used worldwide. It has rich features to implement “Smart Contracts”. A smart contract is basically a program that contains the business-logic and transaction related conditions that has to be deployed on a specific peer.

Web3py: It is a Python library that eases the interaction between the client and the Ethereum blockchain.
Infura: This is a node provider that lets us use remote nodes without prior setup.

The following program connects to the Ethereum blockchain and inspects block-specific details:

Importing Web3 library:

from web3 import Web3

Place your infura API key:

Infura_Connection = “”

Producing the connection to the blockchain:

web3 = Web3(Web3.HTTPProvider(Infura_Connection))

Checking protocol version:


Fetching the latest block:


Displaying coinbase:


Prints the current hashrate that is to be mined to add a block:


Checking if nodes are sycing properly or dead:


fetching ChainID:


Displaying block number:


Input account key to get balance in Wei unit:

myBalance = web3.eth.getBalance(“YOUR_ACCOUNT”)

Current gas price in Wei unit:


For any queries, official documentation can be consulted.


Published by Farial Mahmod Tishan

Life-long learner. Developing Flutter apps on Parrot Linux OS .

One thought on “Inspecting Ethereum’s Blocks: The Web3py Way

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: