A real-time monitoring system for tracking SPL token balances in Solana wallets.
- Real-time tracking of SPL token balances for Solana wallets
- Event-driven architecture using WebSocket connections
- Low resource usage and high stability
- Configurable monitoring parameters
- Automatic retry and reconnection mechanisms
- Hybrid subscription + polling approach for maximum reliability
The tracker uses a hybrid approach to ensure reliable and real-time token balance updates:
- WebSocket Subscriptions: Subscribes to the Solana Token Program for real-time updates.
- Periodic Polling: Performs regular polling as a fallback to ensure no updates are missed.
- State Management: Maintains an in-memory state of token balances and detects changes.
- Event Handlers: Provides an event-driven system to react to balance changes.
┌─────────────────┐ ┌─────────────────┐
│ │ │ │
│ Solana Chain │◄────►│ RPC/WebSocket │
│ │ │ Endpoints │
└─────────────────┘ └────────┬────────┘
│
│
┌────────▼────────┐
│ │
│ Solana Client │
│ │
└────────┬────────┘
│
│
┌────────▼────────┐
│ │
│ Wallet Monitor │
│ │
└────────┬────────┘
│
│
┌────────▼────────┐
│ │
│ Event Handlers │
│ │
└─────────────────┘
- Go 1.18+
- Solana RPC endpoint with WebSocket support
- Clone the repository
- Copy
config.example.jsontoconfig.jsonand set your configuration - Build the application with
go build -o tracker ./cmd/tracker - Run with
./tracker
rpc_endpoint: Solana RPC endpoint URLws_endpoint: Solana WebSocket endpoint URLwallets: Array of wallet addresses to monitortokens: Array of token mint addresses to track (leave empty to track all tokens)log_level: Logging level (debug, info, warn, error)
Build and run with Docker:
# Build the Docker image
docker build -t solana-wallet-tracker .
# Run the container with environment variables
docker run -d \
-e MONITOR_WALLETS=wallet1,wallet2 \
-e MONITOR_TOKENS=token1,token2 \
-e SOLANA_RPC_ENDPOINT=https://your-rpc-endpoint \
-e SOLANA_WS_ENDPOINT=wss://your-ws-endpoint \
solana-wallet-trackerTo add custom handlers for token balance changes, modify the RegisterHandler function call in cmd/tracker/main.go:
walletMonitor.RegisterHandler(func(accountInfo solana.TokenAccountInfo) {
// Your custom handling code here
// Examples:
// - Send to message queue
// - Update database
// - Call external API
// - Generate alerts
})