Open Source Blockchain Transaction Tracker - Real-time monitoring and tracking of Solana blockchain transactions for staking, unstaking, and reward claims.
- π Transaction Tracker Server
Transaction Tracker Server is an open source backend service designed to monitor and track blockchain transactions on the Solana network. It provides real-time event listening for key blockchain programs, processes transaction data, and stores it in a PostgreSQL database for analysis and reporting.
The server actively monitors two main Solana programs:
- Depin Program: Tracks staking, unstaking, NFT initialization, and node initialization events
- Reward System Program: Monitors reward claim transactions and processes reward distributions
This server handles the complex task of parsing blockchain logs, extracting transaction data, and maintaining a comprehensive record of all relevant network activities.
This project is now open source and community-maintained. WAYRU Network no longer exists and does not provide support, maintenance, or updates for this repository. The code is provided as-is for the community to use, modify, and improve.
- Depin Program Listener: Monitors staking, unstaking, NFT initialization, and node initialization events
- Reward System Listener: Tracks reward claim transactions with optional memo parsing
- Event Callbacks: Flexible callback system for processing different event types
- Automatic Reconnection: Robust connection management with automatic reconnection handling
- Error Resilience: Graceful error handling and recovery mechanisms
- Transaction Database: Comprehensive PostgreSQL storage for all tracked transactions
- Transaction Status Tracking: Monitor transaction states from initiation to completion
- Reward Tracking: Track reward claims and payment status
- Historical Data: Maintain complete transaction history for analysis
- Database Indices: Optimized queries with strategic database indexing
- Solana Blockchain: Full integration with Solana Web3.js for blockchain interactions
- Anchor Framework: Uses Coral XYZ Anchor for program interaction
- Smart Contract Integration: Direct interaction with Solana smart contracts
- Connection Management: Singleton pattern for efficient connection reuse
- Multi-RPC Support: Configurable RPC endpoints with API key support
- Heartbeat Service: Automatically updates service health status in the database every 15 seconds
- Database-Backed Health Checks: Frontend can verify service availability by querying the shared database
- Comprehensive Health Status: Monitors database, Solana RPC, Depin Program, and Reward System connections
- Service Status Tracking: Real-time status tracking stored in
heartbeatstable for cross-service communication - Automatic Document Creation: Creates heartbeat records automatically if they don't exist
- Runtime: Node.js 22+
- Framework: Koa.js - Lightweight web framework
- Language: TypeScript 5.4 - Type-safe JavaScript
- Database: PostgreSQL 8.14+ - Robust relational database
- Blockchain:
- Solana Web3.js 1.98 - Solana blockchain integration
- Coral XYZ Anchor 0.30.1 - Solana program framework
- Task Scheduling: node-cron - Automated task execution
- Development:
Before you begin, ensure you have the following installed:
- Node.js (v22 or higher) - Download
- npm or yarn package manager
- PostgreSQL (v14 or higher) - Download
- Git - Download
- Clone the repository
git clone https://github.com/Wayru-Network/tx-tracker-server.git
cd tx-tracker-server- Install dependencies
npm install
# or
yarn install- Set up environment variables
Create a .env file in the root directory (see Configuration section below for details):
cp .env.example .env # If .env.example exists
# Or create .env manually-
Configure your database
- Create a PostgreSQL database
- Run any required migrations or schema setup
- Update the
.envfile with your database credentials
-
Build the project (for production)
npm run buildCreate a .env file in the root directory with the following variables:
# Server Configuration
PORT=1335
NODE_ENV=development
# Database Configuration
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=your_database_name
DATABASE_USERNAME=your_username
DATABASE_PASSWORD=your_password
DATABASE_SSL=false
# Explorers Database Configuration (optional)
EXPLORERS_DATABASE_HOST=localhost
EXPLORERS_DATABASE_PORT=5432
EXPLORERS_DATABASE_NAME=explorers_db
EXPLORERS_DATABASE_USERNAME=explorer_user
EXPLORERS_DATABASE_PASSWORD=explorer_password
EXPLORERS_DATABASE_SSL=false
# Web3 Configuration
DB_ADMIN_PUBLIC_KEY=your_admin_public_key
SOLANA_WALLET_PRIVATE_KEY=your_solana_wallet_private_key
SOLANA_API_URL=https://api.devnet.solana.com
SOLANA_API_KEY=your_solana_api_key # Optional, for rate-limited RPC endpoints
# Program IDs (Solana Program Addresses)
DEFAULT_DEPIN_PROGRAM_ID=D1sMCRu3tRwCviHUDj69WrRQzDoVKd2m2YKydRyauYmJ
DEFAULT_REWARD_SYSTEM_PROGRAM_ID=Ey6f9uyT1s3UrCGpc586aeHmEupYdfR2xo8Nh7TpqLhXDevelopment mode (with hot-reload):
npm run devProduction mode:
npm run build
npm startThe server will start on http://localhost:1335 (or the port specified in your .env file).
tx-tracker-server/
βββ src/
β βββ api/ # API routes and handlers
β β βββ hotspots-stakes/ # Hotspots and stakes API endpoints
β β βββ keys/ # Keys API endpoints
β β βββ nfnodes/ # NFNodes API endpoints
β β βββ others/ # Other API endpoints
β β βββ api.routes.ts # Main API router configuration
β βββ bootstrap/ # Application initialization
β β βββ bootstrap.ts # Bootstrap sequence (listeners, services)
β β βββ shutdown.ts # Graceful shutdown handlers
β βββ config/ # Configuration files
β β βββ env/
β β β βββ env.ts # Environment variables loader
β β βββ db.ts # PostgreSQL connection pools
β βββ constants/ # Application constants
β β βββ router.ts # Route path constants
β β βββ web3.ts # Web3-related constants
β βββ crons/ # Scheduled tasks
β β βββ index.ts # Cron job definitions
β βββ database/ # Database scripts
β β βββ indices.sql # Database index definitions
β βββ helpers/ # Utility helper functions
β βββ interfaces/ # TypeScript type definitions
β βββ middlewares/ # Koa middleware
β β βββ auth-validator.ts # Authentication middleware
β β βββ db-error-handler.ts # Database error handling
β βββ services/ # Business logic services
β β βββ health/ # Health check service
β β β βββ health-check.service.ts
β β βββ heartbeat/ # Heartbeat service
β β β βββ heartbeat.service.ts
β β β βββ heartbeat.queries.ts
β β βββ web3/ # Web3-related services
β β βββ events/ # Blockchain event listeners
β β β βββ depin-program/
β β β βββ reward-system/
β β β βββ token-2022-transfer-listener.service.ts
β β βββ program/ # Program interaction services
β β βββ solana/ # Solana connection management
β β βββ wallet/ # Wallet services
β βββ utils/ # Utility functions
β βββ server.ts # Main server entry point
βββ dist/ # Compiled JavaScript (generated)
βββ kubernetes/ # Kubernetes deployment files
βββ .gitignore
βββ Dockerfile # Docker container definition
βββ eslint.config.mjs # ESLint configuration
βββ nodemon.json # Nodemon configuration
βββ package.json # Project dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ tsconfig-paths-bootstrap.js # Path alias bootstrap
βββ README.md # This file
| Command | Description |
|---|---|
npm run dev |
Start development server with hot-reload using nodemon |
npm run build |
Compile TypeScript to JavaScript, run type checking, and copy SQL files |
npm start |
Start production server (requires build first) |
npm run lint |
Run ESLint to check code quality |
npm run lint:fix |
Run ESLint and automatically fix issues |
All API endpoints (except health checks) require authentication. The authentication middleware validates requests based on the configured DB_ADMIN_PUBLIC_KEY environment variable.
GET /api/health
Returns the health status of the server and its dependencies.
Response:
{
"status": "ok" | "degraded" | "down",
"timestamp": "2024-01-15T10:30:00.000Z",
"services": {
"database": "connected" | "disconnected" | "unknown",
"solana": "connected" | "disconnected" | "unknown",
"depin": "connected" | "disconnected" | "unknown",
"rewardSystem": "connected" | "disconnected" | "unknown"
}
}All endpoints under /api/* (except /api/health ) require authentication. See the source code in src/api/ for specific endpoint documentation.
The Transaction Tracker Server includes a heartbeat system that allows other services (like frontends) to verify its health status by querying a shared database table. This approach avoids exposing HTTP endpoints and IP addresses while providing reliable health status information.
- Automatic Updates: The heartbeat service runs automatically and updates the
heartbeatstable every 15 seconds - Service Identification: Uses
service_name = 'tx_tracker_service'to identify this service - Health Status Storage: Stores comprehensive health information in the
extra_infoJSON field - Database-Backed: Frontend and other services can query the database directly to check service status
The heartbeats table contains the following fields:
service_name(VARCHAR): Service identifier ('tx_tracker_service')last_seen_at(TIMESTAMP): Last heartbeat update timestampextra_info(JSON): Complete health status informationcreated_at(TIMESTAMP): Record creation timestamppublished_at(TIMESTAMP): Record publication timestamp
The extra_info field contains a JSON object with the following structure:
{
"status": "ok" | "degraded" | "down",
"timestamp": "2024-01-15T10:30:00.000Z",
"services": {
"database": "connected" | "disconnected" | "unknown",
"solana": "connected" | "disconnected" | "unknown",
"depin": "connected" | "disconnected" | "unknown",
"rewardSystem": "connected" | "disconnected" | "unknown"
}
}To check if the service is healthy before performing transactions, query the database:
SELECT service_name, last_seen_at, extra_info
FROM heartbeats
WHERE service_name = 'tx_tracker_service';Health Check Logic:
- If
last_seen_atis older than 30-60 seconds β Service may be down - If
extra_info.statusis"down"β Do not proceed with transactions - If
extra_info.statusis"degraded"β Show warning but allow transactions - If
extra_info.statusis"ok"β Proceed normally
- Automatic Document Creation: If no heartbeat record exists, one is created automatically with default status
- Table Existence Check: Gracefully handles cases where the table doesn't exist yet
- Error Resilience: Heartbeat failures don't crash the service
- Update Strategy: Uses UPDATE-first approach (no UNIQUE constraint required)
- Follow TypeScript best practices
- Use async/await for asynchronous operations
- Implement proper error handling
- Add JSDoc comments for public functions
- Use ESLint for code quality checks
- Follow the existing code structure and patterns
- Create the database:
CREATE DATABASE your_database_name;- Run database migrations (if applicable):
# Migration commands will depend on your setup
npm run migrate- Create required indices:
The project includes an indices.sql file that creates performance-optimized indices. Run it against your database:
psql -d your_database_name -f src/database/indices.sqlSee the Configuration section for all available environment variables. Make sure to set up all required variables before running the server.
The project includes a Dockerfile for containerized deployment. To build and run:
# Build the Docker image
docker build -t tx-tracker-server .
# Run the container
docker run -p 1335:1335 --env-file .env tx-tracker-serverFor Kubernetes deployment, see the kubernetes/ directory for deployment configurations.
Contributions are welcome! Since this project is now community-maintained, your contributions help keep it alive and improve it for everyone.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Make your changes
- Run linting and ensure code quality (
npm run lint) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Write clear commit messages
- Follow the existing code style
- Add tests for new features (when test infrastructure is available)
- Update documentation as needed
- Be respectful and constructive in discussions
This project is licensed under the ISC License - see the LICENSE file for details.
This project is open source and available for use, modification, and distribution by the community.
With gratitude and love, we say goodbye.
WAYRU is closing its doors, but we are leaving these repositories open and free for the community.
May they continue to inspire builders, dreamers, and innovators.
With love, WAYRU
Note: This project is open source. Wayru, Inc and The Wayru Foundation are no longer operating entities, and will not provide any kind of support. The community is welcome to use, modify, and improve this codebase.