A high-performance blockchain indexer for VanarChain that tracks ERC20, ERC721, and ERC1155 token transfers and contract deployments.
- Token Transfer Tracking: Indexes all ERC20, ERC721, and ERC1155 transfer events
- Contract Deployment Detection: Automatically detects and indexes token contract deployments
- Real-time Monitoring: Live watcher for new events as they happen
- Historical Scanning: Batch processing of historical blocks
- REST API: Query endpoints for transfers and deployments
- Performance Optimized: Batch database operations and parallel processing
- Node.js 18+
- PostgreSQL 14+
- Clone and install dependencies:
git clone <repository-url>
cd vanar-indexer
npm install- Environment setup:
cp .env.example .env
# Edit .env with your configuration- Database setup:
npm run prisma:generate
npm run prisma:migrate- Start development server:
npm run devCreate a .env file with the following variables:
# Required
VANAR_RPC=https://your-vanar-rpc-endpoint
POSTGRES_URL=postgresql://username:password@localhost:5432/database_name
START_BLOCK=12345678
END_BLOCK=12345679
# Optional
PORT=3000
LOG_LEVEL=info
NODE_ENV=developmentnpm run dev- Start development server with hot reloadnpm run build- Build TypeScript to JavaScriptnpm start- Run production buildnpm run prisma:generate- Generate Prisma clientnpm run prisma:migrate- Run database migrationsnpm run prisma:deploy- Deploy migrations to production
src/server.ts- Main application entry point, starts HTTP server and indexers
env.ts- Environment variable validation and configurationlogger.ts- Pino logger setup with pretty printing for developmentclient.ts- Viem blockchain client configuration
client.ts- Prisma database client singleton
httpServer.ts- Express REST API server with endpoints for querying datablockScanner.ts- Historical block scanning service with batch processingliveWatcher.ts- Real-time event monitoring via blockchain subscription
erc20.ts- ERC20 transfer event indexing logicerc721.ts- ERC721 transfer event indexing logicerc1155.ts- ERC1155 transfer event indexing logicdeployment.ts- Contract deployment detection and indexing with token standard detection
erc20.json- ERC20 contract ABI for event decodingerc721.json- ERC721 contract ABI for event decodingerc1155.json- ERC1155 contract ABI for event decoding
GET /erc20/:address- Get ERC20 transfers for an address (from/to)GET /erc721/:contract- Get ERC721 transfers for a contractGET /erc1155/:contract- Get ERC1155 transfers for a contract
GET /deployments/type/:type- Get deployments by token standard (ERC20|ERC721|ERC1155)GET /deployments/:address- Get deployment info for a specific contract address
- Scans blocks from
START_BLOCKtoEND_BLOCK - Fetches blocks in parallel for performance
- Detects contract deployments by checking for creation transactions
- Indexes transfer events using contract ABIs
- Uses batch database operations for efficiency
- Subscribes to new blocks via polling
- Processes new events in real-time
- Maintains same indexing logic as historical scanner
- Uses ERC165
supportsInterfacefor ERC721/ERC1155 detection - Uses
totalSupply()call for ERC20 detection - Only indexes contracts that are confirmed token contracts
- Batch database inserts using
createMany() - Parallel block fetching
- Parallel token standard detection
- Efficient log filtering by event signatures
ERC20Transfer- ERC20 transfer eventsERC721Transfer- ERC721 transfer eventsERC1155Transfer- ERC1155 transfer eventsContractDeployment- Token contract deployments with standard detection
All tables have indexes on commonly queried fields:
- Transaction hash
- Block number
- Address fields (from/to/contract)
- Token standard (for deployments)
npx prisma studioOpens database browser at http://localhost:5555
npx prisma migrate resetnpm run build
npm run prisma:deploy
npm startThe indexer provides detailed logging:
- Block processing progress
- Event counts per batch
- Error handling with context
- Performance metrics
Check logs for:
Token deployments processed: count: XLogs fetched: count: X- Any error messages with full context
- "Event not found on ABI" - Ensure ABI files are properly imported
- "Table does not exist" - Run
npm run prisma:migrate - Slow performance - Check database indexes and batch sizes
- Missing deployments - Verify token detection logic and RPC connectivity
- Adjust
batchSizeinscanBlocks()for memory vs speed tradeoff - Monitor database connection pool size
- Consider using connection pooling for high-volume indexing