Smart contract analytics engine with real-time Telegram alerts, multi-source data (Etherscan + The Graph + Web3.py), ABI decoding, and anomaly detection.
| File | Description |
|---|---|
contract_analytics.py |
Core engine — usage patterns, anomaly detection, trend analysis |
analytics_bot.py |
Telegram bot with interactive commands |
graph_client.py |
The Graph / GraphQL client (Uniswap, Aave, Compound) |
abi_decoder.py |
Decode raw TX input data & event logs |
config.py |
Centralized API key & settings management |
- 📊 Usage Pattern Analysis — track which functions are called most, daily TX volume, unique callers
- 🚨 Anomaly Detection — auto-detect activity spikes using 2σ statistical rule
- 📈 Trend Comparison — compare 24h activity vs 7-day average
- 👤 Top Caller Ranking — see who interacts with a contract most
- 🤖 Telegram Bot — real-time alerts & interactive commands
- 🔍 ABI Decoder — decode ERC20, Uniswap V2 function calls & events
- 🌐 Multi-Source — Etherscan V2 API + The Graph + Web3.py RPC
pip install web3 requests gql[requests] eth-abi eth-utils# Windows PowerShell
$env:ETHERSCAN_API_KEY = "your_etherscan_api_key"
$env:INFURA_URL = "https://mainnet.infura.io/v3/your_infura_key"
$env:TELEGRAM_TOKEN = "your_telegram_bot_token"
$env:TELEGRAM_CHAT_ID = "your_chat_id"# Linux / Mac
export ETHERSCAN_API_KEY="your_etherscan_api_key"
export INFURA_URL="https://mainnet.infura.io/v3/your_infura_key"
export TELEGRAM_TOKEN="your_telegram_bot_token"
export TELEGRAM_CHAT_ID="your_chat_id"python config.py
# Output: ✅ Semua config OK!from contract_analytics import ContractAnalytics
analytics = ContractAnalytics("0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D")
report = analytics.full_report(days_back=7)
print(report)python analytics_bot.py| Command | Description |
|---|---|
/help |
Show all commands |
/analyze <address> |
Analyze any contract address |
/preset |
List available preset contracts |
/use <name> |
Use a preset (uniswap_v2, uniswap_v3, aave_v3, compound) |
/report [days] |
Full analytics report (default: 7 days) |
/top [n] |
Top N callers (default: 10) |
/trend |
Compare 24h vs 7d trend |
/alert on/off |
Toggle real-time anomaly alerts |
/status |
Show current monitoring status |
/use uniswap_v2
/report 3
/top 5
/alert on
📊 CONTRACT ANALYTICS REPORT
━━━━━━━━━━━━━━━━━━━━━━
🏷️ UniswapV2Router02
📍 0x7a250d5630...
📈 Activity (7d)
• Total TXs : 10,000
• Unique Callers : 2,145
• Success Rate : 96.54%
• Avg Gas Used : 154,037
⚡ Trend (24h vs 7d avg)
• Last 24h : 10,000 TXs
• 7d Average : 1,428 TXs/day
• Change : +600% 📈 UP
🔝 Top Functions
• swapExactETHForTokensSupportingFeeOnTransferTokens → 3,066
• swapExactTokensForETHSupportingFeeOnTransferTokens → 2,153
• swapExactETHForTokens → 1,642
| Name | Contract | Network |
|---|---|---|
uniswap_v2 |
Uniswap V2 Router | Ethereum |
uniswap_v3 |
Uniswap V3 Router | Ethereum |
aave_v3 |
Aave V3 Pool | Ethereum |
compound |
Compound V2 | Ethereum |
| Service | Get Key | Free Tier |
|---|---|---|
| Etherscan | etherscan.io/apis | 5 req/sec |
| Infura | infura.io | 100K req/day |
| Telegram Bot | @BotFather | Free |
web3-python-toolkit/
├── on-chain-analytics/
│ ├── contract_analytics.py # Core engine
│ ├── analytics_bot.py # Telegram bot
│ ├── graph_client.py # The Graph client
│ ├── abi_decoder.py # ABI decoder
│ └── config.py # Configuration
├── wallet_tracker.py
├── multi_wallet_tracker.py
├── etherscan_tracker.py
├── token_tracker.py
├── gas_tracker.py
├── nft_tracker.py
├── whale_alert.py
├── defi_tracker.py
├── price_alert.py
├── contract_reader.py
└── README.md
- Web3.py — Ethereum interaction
- Etherscan API V2 — On-chain data
- The Graph — Protocol subgraphs
- python-telegram-bot — Telegram integration
- eth-abi — ABI encoding/decoding
Rizal — @rizalcodes
Building Web3 tools with Python 🐍⛓️
MIT License — free to use, modify, and distribute.