A real-time DAI token transaction indexer built with NestJS that monitors and tracks DAI transfers on the Ethereum mainnet.
DAI Indexer is a blockchain monitoring application that:
- Real-time Monitoring: Listens to DAI token transfer events on Ethereum mainnet using WebSocket connections
- Transaction Tracking: Accumulates statistics about DAI transfers including total volume and transaction count
- Transaction Validation: Provides an API to check if any given transaction hash involves DAI token operations
- Live Statistics: Offers real-time insights into DAI token activity since the application started
The DAI token (0x6B175474E89094C44Da98b954EedeAC495271d0F) is a popular stablecoin on Ethereum, and this indexer helps track its movement across the network.
- Real-time DAI transfer event monitoring
- Cumulative transaction statistics
- Transaction hash validation for DAI operations
- RESTful API endpoints
- Built with TypeScript and NestJS
- Uses Infura for reliable Ethereum node access
- Comprehensive error handling
- Framework: NestJS - A progressive Node.js framework
- Blockchain: Ethers.js - Ethereum library for blockchain interactions
- Provider: Infura - Ethereum node infrastructure
- Language: TypeScript
- Runtime: Node.js
Before you begin, ensure you have:
- Node.js (v14 or higher)
- Yarn package manager
- An Infura account and API key for Ethereum mainnet access
-
Clone the repository
git clone <repository-url> cd dai-indexer
-
Install dependencies
yarn install
-
Set up environment variables
cp .env.example .env
Edit the
.env
file and set your Infura API key:INFURA_KEY=your_infura_api_key_here
-
Start the application
yarn start
For development with auto-reload:
yarn start:dev
The application will start on http://localhost:3000
GET /transactions
Returns comprehensive statistics about DAI transfers since the application started.
Response:
{
"startTime": 1642684800000,
"currentTime": 1642688400000,
"totalTransactions": 1547,
"totalDAITransactions": "1234567.89 DAI"
}
Example:
curl http://localhost:3000/transactions
GET /transactions/:transactionHash
Checks if a given transaction hash involves DAI token operations.
Parameters:
transactionHash
- Ethereum transaction hash (with or without 0x prefix)
Response:
true // if transaction involves DAI
false // if transaction doesn't involve DAI or doesn't exist
Example:
curl http://localhost:3000/transactions/0x1234567890abcdef...
The application follows a modular architecture:
src/
├── transactions/ # Transaction monitoring module
│ ├── transactions.controller.ts # API endpoints
│ ├── transactions.service.ts # Core business logic
│ └── transactions.spec.ts # Unit tests
├── abi.json # DAI token ABI for contract interaction
├── types.ts # TypeScript type definitions
├── app.module.ts # Main application module
└── main.ts # Application bootstrap
- TransactionsService: Handles WebSocket connection to Ethereum, monitors Transfer events, and maintains statistics
- TransactionsController: Exposes REST API endpoints for accessing data
- Real-time Event Handler: Processes DAI transfer events as they occur on the blockchain
- Connection: The app establishes a WebSocket connection to Ethereum mainnet via Infura
- Event Listening: Subscribes to
Transfer
events from the DAI token contract - Data Accumulation: Each transfer event updates the running total and transaction count
- API Access: Provides real-time access to accumulated data and transaction validation
Run the test suite:
# Unit tests
yarn test
# End-to-end tests
yarn test:e2e
# Test coverage
yarn test:cov
yarn start
- Start the applicationyarn start:dev
- Start in development mode with auto-reloadyarn start:prod
- Start in production modeyarn build
- Build the applicationyarn test
- Run unit testsyarn test:e2e
- Run end-to-end testsyarn lint
- Lint the codebaseyarn format
- Format code with Prettier
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the UNLICENSED license.
@javierlinked
2022
Built with ❤️ for the Ethereum and DeFi community