ETH Transaction Processor is a FastAPI-based project for processing Ethereum blockchain transactions. It includes features for fetching, storing, and analyzing Ethereum transactions using SQLAlchemy for database interaction, Celery for task queue management, and Redis for caching.
- Features
- Requirements
- Installation
- Configuration
- Running the Application
- Running Tests
- API Documentation
- Troubleshooting
ETH Transaction Processor provides several key features:
- Fetch Ethereum Transactions: Retrieve Ethereum transactions from the blockchain using Infura.
- Store Transactions in Database: Save transactions in a PostgreSQL database for persistence and later analysis.
- Analyze Transaction Data: Perform analysis on stored transactions, such as calculating the average gas price.
- Cache Results: Use Redis to cache responses, reducing load times and improving performance.
- Asynchronous Task Processing: Utilize Celery for handling asynchronous tasks such as fetching and saving transactions.
Before setting up the ETH Transaction Processor, ensure you have the following software installed:
- Docker: For containerization and environment consistency.
- Docker Compose: To manage multi-container Docker applications.
- Python 3.10+: The project uses Python 3.10 or higher for development.
- Poetry: For dependency management and virtual environment setup.
- PostgreSQL: The application uses PostgreSQL as its database.
- Redis: For caching and Celery message broker.
These tools will allow you to set up and run the application in a consistent environment.
To get started with the ETH Transaction Processor, follow these steps:
- Clone the repository:
git clone https://github.com/your-username/ETHTransactionProcessor.git
cd ETHTransactionProcessor
Next, create a .env
file from the provided .envexample
file:
cp .envexample .env
In this file, you'll need to fill in the necessary environment variables:
POSTGRES_DB=your_database_name
POSTGRES_USER=your_database_user
POSTGRES_PASSWORD=your_database_password
DATABASE_URL=postgresql+asyncpg://your_database_user:your_database_password@your_database_host:your_database_port/your_database_name
REDIS_HOST=your_redis_host
REDIS_PORT=your_redis_port
REDIS_DB=your_redis_db
REDIS_URL=redis://your_redis_host:your_redis_port/your_redis_db
INFURA_API_KEY=your_api_key
Once your environment variables are configured, build and start the Docker containers:
docker-compose up --build
This command will build the Docker images and start the services defined in the docker-compose.yml file.
After the containers are running, initialize the database by applying migrations:
docker-compose exec web alembic upgrade head
This command applies the necessary database migrations to ensure your database is ready to store transactions.
Configuration is managed through environment variables set in the .env
file. Key variables include:
- POSTGRES_DB: The name of the PostgreSQL database.
- POSTGRES_USER: The username for the PostgreSQL database.
- POSTGRES_PASSWORD: The password for the PostgreSQL user.
- DATABASE_URL: The full database URL used by SQLAlchemy to connect to PostgreSQL.
- REDIS_HOST: The hostname of the Redis server.
- REDIS_PORT: The port on which Redis is running.
- REDIS_DB: The Redis database number.
- REDIS_URL: The full Redis connection URL.
- INFURA_API_KEY: Your Infura project ID used to connect to the Ethereum blockchain.
The API documentation is automatically generated by FastAPI and can be accessed via the following endpoints:
Swagger UI: http://localhost:8000/docs — Provides an interactive interface to test the API endpoints.
ReDoc: http://localhost:8000/redoc — Offers a more detailed, text-based API documentation. For more detailed API usage and examples, please refer to the ETHTransactionProcessor/API_DOC.md file.
-
Database Connection Error: Ensure the database URL in the .env file is correct and the database container is running.
-
Redis Connection Error: Check the Redis URL in the .env file and verify that the Redis container is up and running.
-
Unable to Connect to Infura: Confirm that your Infura API key is valid and correctly set in the .env file.
-
ModuleNotFoundError: Make sure all dependencies are installed correctly. If using Docker, try rebuilding the containers.