This project is an Express.js API built with TypeScript, designed to interact with the Ethereum blockchain using ethers.js. It includes features like logging, error handling, and a structured project layout.
- src/: Contains the main source code for the API.
- controllers/: Handles requests and responses.
- services/: Business logic and interaction with external services like Ethereum.
- routes/: Defines the API endpoints and maps them to controllers.
- middleware/: Custom middleware for logging, error handling, etc.
- utils/: Utility functions and configurations.
- Node.js (version 14 or higher)
- npm
-
Clone the repository:
git clone <repository-url> cd NodeEtherJsApiBoilerPlate
-
Install dependencies:
npm install
-
Set up environment variables in a
.envfile:NODE_ENV=development PORT=3000 ETH_NETWORK=mainnet INFURA_PROJECT_ID=your-infura-project-id
To start the application in development mode:
npm run devTo build and start the application in production mode:
npm run build
npm start- Create a new controller in
src/controllers/. - Define the business logic in
src/services/if needed. - Add a new route in
src/routes/and map it to the new controller.
- Create a new middleware function in
src/middleware/. - Register the middleware in
src/index.ts.
This project uses Jest for testing.
-
Install Jest and related dependencies:
npm install --save-dev jest @types/jest ts-jest supertest @types/supertest
-
Create test files in the
src/__tests__/directory. -
Write your test cases using Jest syntax.
-
Run tests with:
npm test
Feel free to fork this repository and submit pull requests. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.