A Golang application that indexes ERC-20 contract events and stores them in a database.
- Watches for new events from an ERC-20 contract
- Stores event data in a PostgreSQL database
- Provides structured logging and error handling
- Go 1.16+
- Ethereum Node (RPC URL)
This project uses the following tools and libraries:
- Logrus: A structured logger for Go, used for logging application events.
- Viper: A complete configuration solution for Go applications.
- Go-Ethereum: Official Go implementation of the Ethereum protocol, used for interacting with the Ethereum blockchain.
- Testify: A toolkit with common assertions and mocks for unit tests in Go.
- GolangCI-Lint: A fast Go linters runner for ensuring code quality.
Update config.yaml
file in the project root:
RPC_URL: 'your_rpc_url'
CONTRACT_ADDRESS: 'your_contract_address'
DB_CONN_STR: 'your_db_connection_string'
This project uses Docker to containerize the application and Docker Compose to manage multi-container environments.
- Docker installed on your local machine. Docker Installation Guide
- Docker Compose installed on your local machine. Docker Compose Installation Guide
- Build the Docker images and start the containers:
docker-compose up --build
This command builds the Docker images defined in the docker-compose.yml file and starts the containers.
- Verify the Containers are Running:
After running the above command, you should see logs from your application container indicating that it has successfully connected to the PostgreSQL database and is running.
- Stopping the Containers:
To stop the running containers, use:
docker-compose down
Ensure your docker-compose.yml file includes the volume for config.yml and sets up the services correctly. This file defines the services required to run the application.
- Fetch Historical Events: Fetch and index historical events from the contract.
- Start Block Configuration: Provide configuration to specify the start block for fetching historical events.
- Additional Event Types: Extend support to parse and handle other ERC-20 events or events from other types of smart contracts.
- Batch Inserts: Implement batch inserts for handling a high volume of events more efficiently.
- Database Indexing: Add indexing to the database tables to improve query performance.
- Migration and Schema Version Management: Use tools like
golang-migrate
to manage database schema changes and versioning.
- Structured Logging: Implement structured logging with log levels for better traceability and debugging.
- Monitoring and Alerting: Integrate with monitoring tools like Prometheus and Grafana to visualize metrics and set up alerts.
- Unit Tests: Increase the coverage of unit tests across all components.
- Integration Tests: Implement comprehensive integration tests to ensure all components work together as expected.
- Provide RESTful API endpoints for accessing event data and application status.
- Docker and CI/CD: Update CI/CD pipelines to push Docker images to a container registry.
This project is licensed under the MIT License - see the LICENSE file for details.