quontral
v1.0.26
Published
Dex API endpoints and Token Swap library for Web3 applications
Downloads
29
Maintainers
Readme
Features:
- Dex API endpoints for Web3 transactions
- Web3 wallet configurations/authentications (login/sign)
- Token allowances for web3 wallets and sending transactions
- Handling big numbers and floating points
- utility functions to help you build your dex
... and much more. Check the official Quontral docs for more details.
🚀 Quick start
If you're new to Quontral, check the quickstart guide in the official docs on how to get started.
1. Install Quontral
The easiest way to integrate the Quontral SDK into your JavaScript project is through the npm module.
Install the package via npm
:
npm install quontral
Adding Quontral to the frontend project is by the following
import Quontral from 'quontral';
2. Initialize Quontral
After your dependency is added, you simply need to initialize quontral with class initialization:
⚠️ Warning: Make sure to keep your api key private
const service = new Quontral({ 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
});
5. Sending transaction using api data
// ...
const { data } = await service.getQuote({
buyTokenAddress: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56',
sellTokenAddress: '0x3019bf2a2ef8040c242c9a4c5c4bd4c81678b2a1',
sellTokenAmount: '1000000000000000000',
});
// Send the transaction request on the current web3 wallet provider with the given api data of quontral
const receipt = await service.sendTransaction(data);
Or you can use the web3 library itself
import Web3 from 'web3';
// Initialize new web3 instance with the given provider
const web3 = new Web3(Web3.givenProvider);
// Our endpoint data for the transaction
const { data } = await service.getQuote({
buyTokenAddress: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56',
sellTokenAddress: '0x3019bf2a2ef8040c242c9a4c5c4bd4c81678b2a1',
sellTokenAmount: '1000000000000000000',
});
// Finally do the transaction on current wallet
const receipt = await web3.eth.sendTransaction(res.data);
6. Signin current Web3 wallet
// ...
// You can use these data pieces to save the users wallet credentials when signed
const { message, signature } = await service.sign({ address: '0x66E5869be1309a543A752aA24CfA251E86234fcc', domain: 'quontral.com', uri: 'https://app.quontral.com' });