This project is designed for handling Ethereum smart contract interactions with the FeeCollector
contract, processing and storing blockchain events, and providing a REST API interface. Below are the steps to set up, build, and run the project.
- Node.js
- npm
- TypeScript
- Ethereum wallet with RPC access
- MongoDB
- Docker (for Docker-based setup)
- Install dependencies
npm install
- Set Environment Variables:
- Copy the .env.example file to a new file named .env.
- Fill in the environment variables in .env with your specific settings (e.g., Ethereum RPC URL, MongoDB connection string).
- Building the project
This will compile the TypeScript files and generate the corresponding JavaScript files in a dist directory.
npm run build
Start the MongoDB Database:
- Ensure MongoDB is running on your machine.
- Make sure the connection details match those specified in your
.env
file.
Run the Application:
You can start the applications individually or both at the same time. Ensure your MongoDB database and Ethereum RPC are configured and running as expected.
- Start the
queryRpc
Application: This application listens forFeeCollected
events from theFeeCollector
contract.npm run start:queryRpc
- Start the
restServer
Application: This application provides a REST API interface.npm run start:restServer
- Run both together:
To start both queryRpc and restServer simultaneously:
npm run start
Get FeeCollected Events:
- Endpoint:
GET /events/:integrator
- Description: Retrieves all collected events for a given integrator.
- Example:
curl http://localhost:3000/events/0xIntegratorAddress
- Build the Docker Containers:
This command will build the Docker images for the application and the MongoDB database.
docker-compose build
- Run the Docker Containers:
This command will start the containers based on the configuration in the docker-compose.yml file.
You can add -d to run the containers in detached mode.
docker-compose up
- Accessing the Application: The application will be accessible at http://localhost:3000, and MongoDB will be available on its default port 27017.
Contract Interactions:
- The
FeeCollectorABI.json
file in thecontracts
directory is used for interacting with the FeeCollector smart contract.
Event Processing:
- The
FeeCollectedEvent.ts
model in themodels
directory represents the structure of the collected events.
Querying the RPC:
- The
queryRpc.ts
file handles querying the Ethereum RPC.