Track Ethereum Transactions and Balance Using Python

ยท

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


Step 1: Setting Up the Etherscan API

Obtain an API Key

  1. Register on Etherscan.
  2. Generate a free API key under "API Keys" in your account dashboard.

Configure Python Environment

pip install requests pandas matplotlib

Step 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


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


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

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.