This project is a backend service for interacting with Ethereum blockchain data. It fetches block data and stores it in a MongoDB database for further analysis.
- Fetches the latest block from the Ethereum blockchain.
- Provides details of the last ‘n’ blocks.
- Retrieves account details of a particular address, including ETH balance and last ‘n’ transactions.
- Fetches details of different ERC20 tokens provided their addresses.
- All data is fetched from the Ethereum mainnet.
- On server startup, it fetches the last 100 blocks and stores them in MongoDB. New blocks are added automatically to the database.
- If the value of ‘n’ in the second requirement doesn’t exceed the number of blocks stored already in the database, data is fetched from the database itself.
- Dockerized for easy deployment using
docker-compose up.
- Node.js (version 14 or later)
- npm (Node package manager)
- MongoDB (for local development)
- Docker (for containerized deployment)
- Clone the repository
- Install dependencies:
npm install - Create a
.envfile in the root directory with the following content:
-
ETHERSCAN_API_KEY=YOUR_API_KEY_HERE
-
MONGODB_URI=mongodb://localhost:27017/etherscan
-
INFURA_URL=https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID
- Start the application:
npm run dev - Access the application at
http://localhost:3000.
- Ensure Docker is installed and running on your machine.
- Build and start the containers:
docker-compose up --build - Access the application at
http://localhost:3000. - Connect to MongoDB using Compass at
mongodb://localhost:27017/etherscan.
You can test the following endpoints using Postman:
- Get Latest Block
- Endpoint:
GET /api/latest-block - Description: Retrieves the latest block information.
- Get Last n Blocks
- Endpoint:
GET /api/blocks/n - Description: Retrieves details of the last 'n' blocks.
- Get Account Details
- Endpoint:
GET /api/account/:address - Description: Retrieves account details including ETH balance and last 'n' transactions.
- Get ERC20 Token Details
- Endpoint:
GET /api/token/:address - Description: Retrieves details of a specific ERC20 token by its address.
- Application Running Locally:
- MongoDB Compass:
- Docker Logs:
- Docker Setup:
- Postman Testing: