A simple python implementation useful for checking a crypto wallet's ether balance on the mainnet. This tutorial leverages the Web3.py library.
Ensure your development environment is running Python3. For best results I recommend running a python virtual machine (see instructions below).
Clone the toythereum git repo:
# for https:
git clone https://github.com/anthonyrka/toythereum.git
cd toythereum
Set up your virtual environment:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements
There are many ways to access the Ethereum mainnet. One way would be to install geth to run as a local ethereum node on your local development machine. However, if you choose this option you should consider the time it will take to download the full blockchain, not to mention the IO, disk space and bandwidth requirements. See https://geth.ethereum.org/docs/install-and-build/installing-geth.
This tutorial wastes no time and leverages an API provider called Infura.io. Visit infura.io to setup a free account. Once signed up (it currently takes 30 seconds), Infura will provide you Endpoints and a ProjectID.
Once you have your PROJECTID and ENDPOINT, set these as local environment variables:
export INFURA_PROJECT_ID=<YOUR-PROJECT-ID>
export INFURA_MAINNET_URI=https://mainnet.infura.io/v3
โ be sure not to add the trailing /
to this URL
Note: at the time of this writing, the Infura mainnet can be accessed over HTTP with the above URI. However, you'll want to double-check this is what is provided in your project's account.
export CRYPTO_WALLET=0x7829e7bDc86dEc3f00403f7E6b58aa8d42d86cF7
python get_address_balance.py $INFURA_PROJECT_ID $CRYPTO_WALLET $INFURA_MAINNET_URI
Crypto Address: 0x7829e7bDc86dEc3f00403f7E6b58aa8d42d86cF7
Balance: 0.01179221 ether
If you expect to find a balance in your wallet and you find a 0 result. There are at least 2 issues to consider:
- If your wallet is on an exchange such as Coinbase, you will likely not find it on the blockchain. Validate this by searching for your wallet on etherscan.io.
- If you have decided to implement your own geth client locally, the local client is likely still syncing the blockchain. This will take a significant amount of time (maybe multiple days). An informative read.
https://ethereum.stackexchange.com/questions/32940/how-can-i-generate-a-wallet-in-python/33123