# Build Ethereum Balance Checker in 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](https://web3py.readthedocs.io/en/stable/) by executing the following command:
    

```python
pip install web3
```

* **Ethereum Node API Endpoint**  
    Though there are many Ethereum node service providers available online, we'll use [Pocket Network](https://www.pokt.network/) for our project as it is free.
    
    1. Signup for an account at [Pokt.network](https://mainnet.portal.pokt.network/#/signup) and verify your email address to get access to the endpoints.
        
    2. Select *Apps* from the side menu and click *Create*.
        
    3. Enter desired *App Name* and click *Launch Application*.
        
    4. 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!

1. Import required modules
    

```python
from web3 import Web3, HTTPProvider
```

1. Save the endpoint URL in a variable
    

```python
endpoint = 'YOUR_ENDPOINT_URL_HERE'
```

1. Make a connection to Ethereum blockchain through the endpoint
    

```python
connection = Web3(HTTPProvider(endpoint))
```

1. Get the wallet address input from the user
    

```python
address = input("Enter ETH wallet address: ")
```

1. Fetch the latest ETH balance from the blockchain and convert it to *ether* denomination.
    

```python
balance = connection.fromWei(connection.eth.getBalance(address, 'latest'), 'ether')
```

1. Display the balance
    

```python
print(f"Balance: {balance} ether")
```

%[https://gist.github.com/a26nine/b0f905e7f1aeae6fa4a7ecfaefcb9042] 

Save the file; run it; enter ETH address and get your balance right in the terminal. That simple!

![Result](https://cdn.hashnode.com/res/hashnode/image/upload/v1647420336980/DUphd0nwM.png align="left")

So, what's your balance? 😁
