Ethereum Balance Checker using Python
There are ample blockchain explorers online to query Ethereum wallet balance. But have you ever thought of checking the ETH balance directly from your command-line in a couple of steps? Let's create a tool for that with only 6 lines of code! 😎
Requirements
-
Python Web3 Library
Install Python 'Web3.py' Library by executing the following command:pip install web3 -
Ethereum Node API Endpoint
Though there are many Ethereum node service providers available online, we'll use Pocket Network for our project as it is free.-
Signup for an account at Pokt.network and verify your email address to get access to the endpoints.
-
Select Apps from the side menu and click Create.
-
Enter desired App Name and click Launch Application.

-
Copy the Endpoint provided. (Ensure that Ethereum Mainnet is selected as the Endpoint network!

-
The web3 library will allow us to interact with the Ethereum blockchain through the API endpoint.
Let's Code!
-
Import required modules
from web3 import Web3, HTTPProvider -
Save the endpoint URL in a variable
endpoint = 'YOUR_ENDPOINT_URL_HERE' -
Make a connection to Ethereum blockchain through the endpoint
connection = Web3(HTTPProvider(endpoint)) -
Get the wallet address input from the user
address = input("Enter ETH wallet address: ") -
Fetch the latest ETH balance from the blockchain and convert it to ether denomination.
balance = connection.fromWei(connection.eth.getBalance(address, 'latest'), 'ether') -
Display the balance
print(f"Balance: {balance} ether")
Save the file; run it; enter ETH address and get your balance right in the terminal. That simple!

So, what's your balance? 😁
更多推荐

所有评论(0)