πQuick Start
GET API Key
Swapper API works with API Key. This API key is unique and private. You should use this API key for requests you send from your server or frontend. Undesirable results may occur if this API key is started to be used by 3rd parties. So do not share your API Key with anyone. Swapper is currently developing a Dashboard to generate API Key. Until then you can use this API Key:
API Key: Ru31BKdr99rGlsyN69
1. Install Swapper
The easiest way to integrate the Swapper SDK into your JavaScript project is through the npm module.
Install the package via npm
:
npm install swapper
Adding Swapper to the frontend project is by the following
import Swapper from 'swapper';
2. Initialize Swapper
After your dependency is added, you simply need to initialize swapper with class initialization:
const service = new Swapper({ apiKey: 'YOUR_API_KEY' });
3. Using Dex API endpoints
After that we can use service functions to interact with the Dex API and Web3 wallet.
// ...
const priceResponse = await service.getPrice({
buyTokenAddress: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56',
sellTokenAddress: '0x3019bf2a2ef8040c242c9a4c5c4bd4c81678b2a1',
sellTokenAmount: '1000000000000000000',
});
const quoteResponse = await service.getQuote({
buyTokenAddress: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56',
sellTokenAddress: '0x3019bf2a2ef8040c242c9a4c5c4bd4c81678b2a1',
sellTokenAmount: '1000000000000000000',
});
4. Using services and utils
There are some utility functions which can help you build your dex even more quicker,
// ...
// This will initialize and configure the current Web3 wallet.
service.utils.connectWallet({ chainId: 56 });
// This will create an allowance based on your params on your web3 wallet for the desired token.
service.setAllowance({
ownerAddress: '0x123', // your web3 wallet address
sellTokenAddress: '0x3019bf2a2ef8040c242c9a4c5c4bd4c81678b2a1', // token address to create allowance for
});
Last updated