Ethereum transaction tracking and balance monitoring are essential for developers and crypto enthusiasts. This guide demonstrates how to use Python with the Etherscan API to fetch wallet balances, analyze transactions, and visualize data over time.
Prerequisites
- Intermediate Python knowledge
- Installed libraries:
requests,pandas,matplotlib - Free Etherscan API key (sign up here)
Step 1: Setting Up the Etherscan API
Obtain an API Key
- Register on Etherscan.
- Generate a free API key under "API Keys" in your account dashboard.
Configure Python Environment
pip install requests pandas matplotlibStep 2: Fetching Ethereum Wallet Balance
Code Example
import requests
api_key = "YOUR_API_KEY"
address = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e" # Example address
url = f"https://api.etherscan.io/api?module=account&action=balance&address={address}&tag=latest&apikey={api_key}"
response = requests.get(url)
balance_wei = int(response.json()["result"])
balance_eth = balance_wei / 10**18 # Convert wei to ETH
print(f"Balance: {balance_eth:.6f} ETH") Key Parameters
module=account: Specifies wallet-related queries.action=balance: Retrieves the current balance.tag=latest: Fetches the most recent data.
Step 3: Tracking Transactions
Fetch Transaction History
tx_url = f"https://api.etherscan.io/api?module=account&action=txlist&address={address}&startblock=0&endblock=99999999&sort=asc&apikey={api_key}"
tx_response = requests.get(tx_url)
transactions = tx_response.json()["result"] Analyze Transaction Data
- Fields:
blockNumber,timeStamp,value,gasUsed,hash. Use
pandasto structure data:import pandas as pd df = pd.DataFrame(transactions) df['value_eth'] = df['value'].astype(float) / 10**18
Step 4: Visualizing Wallet Activity
Plot Balance Over Time
import matplotlib.pyplot as plt
df['date'] = pd.to_datetime(df['timeStamp'], unit='s')
df.plot(x='date', y='value_eth', kind='line')
plt.title("Ethereum Wallet Balance Timeline")
plt.ylabel("Balance (ETH)")
plt.show() ๐ Explore advanced Ethereum analytics tools for deeper insights.
FAQ
How often does the Etherscan API update?
Data refreshes every 1โ2 minutes, depending on Ethereum network activity.
Is there a rate limit for the free API?
Yes: 5 calls/sec and 100,000 calls/day. Upgrade to a paid plan for higher limits.
Can I track ERC-20 token balances?
Yes. Use action=tokentx instead of txlist in the API request.
๐ Learn how to optimize your crypto portfolio with real-time tracking.
Key Takeaways
- Core Keywords: Ethereum, Python, Etherscan API, transaction tracking, wallet balance, data visualization.
- SEO Tip: Integrate keywords naturally (e.g., "monitor Ethereum transactions programmatically").
- Always secure your API keys and avoid exposing them in public repositories.
By following this guide, you can build a robust Ethereum tracker tailored to your needs. For more complex analytics, consider leveraging blockchain SDKs like Web3.py.