This project provides an Express-based server to interact with the Uniswap Smart Order Router, allowing users to get token swap quotes. The API is protected with an API key to restrict unauthorized access.
- Secure API with Key Validation: Ensures only authorized clients can access the API.
- Uniswap Integration: Leverages the Uniswap Smart Order Router for token swap quotes.
- Dynamic Routing: Automatically calculates optimal trading routes.
- Customizable Settings: Allows specification of chain ID, wallet addresses, and token details.
- Node.js >= 14.x
- Yarn or npm
- A valid API key (set as an environment variable)
- Access to Ethereum RPC endpoints for the desired chains
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Install dependencies:
yarn install # or npm install
-
Create a
.env
file in the root directory with the following content:API_KEY=your-secure-api-key
-
Start the server:
yarn start # or npm start
Get a token swap quote for a specific trade.
Content-Type: application/json
x-api-key
: Your API key (required)
{
"chainId": 1,
"walletAddress": "0xYourWalletAddress",
"tokenIn": {
"address": "0xTokenInAddress",
"decimals": 18,
"symbol": "TOKEN_IN",
"name": "Token In"
},
"tokenOut": {
"address": "0xTokenOutAddress",
"decimals": 18,
"symbol": "TOKEN_OUT",
"name": "Token Out"
},
"amountIn": 100
}
- 200 OK: Returns the swap quote details.
- 400 Bad Request: Missing or invalid parameters.
- 403 Forbidden: Invalid or missing API key.
- 500 Internal Server Error: Unable to process the request.
{
"numerator": "1000000000000000000",
"decimals": 18,
"readableAmount": "1.0"
}
index.ts
: Entry point of the application.utils.ts
: Helper functions for provider and token utilities.
API_KEY
: Your secure API key for the server.
- Make a POST request to
/quote
with the required headers and body. - Ensure the
x-api-key
header matches the value set in your.env
file.
Example using fetch
:
fetch("http://localhost:8000/quote", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": "your-secure-api-key"
},
body: JSON.stringify({
chainId: 1,
walletAddress: "0xYourWalletAddress",
tokenIn: { ... },
tokenOut: { ... },
amountIn: 100
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Error:", error));
- To run the server in development mode:
yarn serve # or npm run serve
This project is licensed under the MIT License.
Let me know if you need additional sections or customizations!