This Python script is a simple blockchain explorer that connects to a public Ethereum node via Infura. It allows users to:
- Fetch the latest block number.
- Retrieve transactions from the latest block.
- Check the balance of a given Ethereum address.
Ensure you have the following installed on your system:
- Python 3.x: Install it from Python's official website.
- Web3.py: This library allows interaction with the Ethereum blockchain. Install it using:
pip install web3
- Infura Account: You need an Infura project ID to connect to the Ethereum network. Create a free account at Infura and generate a project ID.
- Clone or download this repository.
- Open the
ethereum_explorer.pyfile and replaceYOUR_INFURA_PROJECT_IDwith your actual Infura project ID. - Save the file.
To execute the script, follow these steps:
- Open a terminal or command prompt.
- Navigate to the directory where
ethereum_explorer.pyis located. - Run the script using:
python3 ethereum_explorer.py
When you run the script, you should see output similar to:
Latest Block Number: 21932407
Number of Transactions in Latest Block: 133
Transaction Summary:
{'hash': 'd88d259ffbc4f355366d2e555d9dfb5606f68374201a82cb2798b52899cab9ce', 'from': '0x7049a18279500a25864c509137d7de4ff0048957', 'to': '0x3B55732F6D3997A7D44A041b8496e1A60712A35F', 'value': 0}
{'hash': 'fa36bf69b0615d59c1ee250afdfda766f21d6d1d8fa9021cca50bef758777027', 'from': '0xb36ce3F521a1FF4B0CffB82DDd71F0a51fCf56ce', 'to': '0x51C72848c68a965f66FA7a88855F9f7784502a7F', 'value': 0}
{'hash': '0ab956cee51adf6e56443da4a48cfd5c02523cf4a9aefc9289082015588f67ba', 'from': '0x6f0A91Ef8Adeb54DB0E63BE507747aB9a31d3926', 'to': '0x51C72848c68a965f66FA7a88855F9f7784502a7F', 'value': 0}
.....
Balance of 0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe: 2.345 ETH
- Connection Issues: Ensure you have an active internet connection and that your Infura project ID is correctly set.
- Module Not Found: If you get an error related to
web3, reinstall it usingpip install web3. - Invalid Address: Ensure the Ethereum address you check is valid.
- Add support for querying transactions by hash.
- Display detailed transaction information.
- Support multiple Ethereum networks (Mainnet, Ropsten, Goerli, etc.).