This guide will walk you through on how you can interact with our protocol implementation using our RESTful APIs. The most common group of users that can benefit from this guide are developers who have minimal smart contract experience, traders and wallets.
There are some risks when utilising Kyber. To safeguard users, we kindly ask that you refer to the Slippage Rates Protection and Price Feed Security sections on what these risks are, and how to mitigate them.
Trading Tokens - This section will show the steps taken to execute a KNC -> DAI trade on Ropsten, as well as incorporating platform fees. The steps for performing token -> ether and ether -> token conversions are the same.
Reserve Routing - This advanced section covers the reserve routing feature to include / exclude reserves, or to split trades amongst multiple reserves.
Token Info & Price Data - This section covers how one can obtain token information and historical price data.
If the source token is not ETH (ie. an ERC20 token), the user is first required to call the /enabled_data endpoint to give an allowance to the smart contract executing the trade.
Refer to the API overview for the test and mainnet network URLs to use.
To prevent front running, the contract limits the gas price trade transactions can have. The transaction will be reverted if the limit is exceeded. To query for the maximum gas limit, check the public variable maxGasPrice.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit ourjavas// https://t.me/KyberDeveloper.let maxGasPrice =awaitKyberNetworkProxyContract.maxGasPrice();
Suppose we want to convert 100 KNC to DAI tokens on Ropsten, which is a token to token conversion. In addition, we want to charge a platform fee of 0.25%. Note that ETH is used as the base pair i.e. KNC -> ETH -> DAI.
The code example will also work for token -> ether and ether -> token conversions, by using 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee as the token address for ETH.
We use ethers for connecting to the Ethereum blockchain
The node-fetch module is used for making API queries
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.// Importing the relevant packagesconstethers=require('ethers');constfetch=require('node-fetch');
ethers provides a very simple method getDefaultProvider to easily connect to the Ethereum blockchain. While not necessary, it is recommended to provide an API key for the various providers offered (Eg. Alchemy, Infura and Etherscan).
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.// Connecting to a providerconstNETWORK='ropsten';constPROJECT_ID='INFURA_PROJECT_ID'; // Replace this with your own Project IDconstprovider=newethers.getDefaultProvider(NETWORK, { infura:PROJECT_ID });
Next, we will define the constants that we will be using for this guide. This includes the following:
NETWORK_URL: Kyber's API Base URL
PRIVATE_KEY: The private key which we will be sending transactions from
PLATFORM_WALLET: The wallet address for which we can get commission fees from. Read more about platform fees here
PLATFORM_FEE: Platform fee amount to be charged, in basis points. Read more about platform fees here
SRC_TOKEN_ADDRESS: Ropsten KNC address
DEST_TOKEN_ADDRESS: Ropsten DAI address
SRC_QTY: 100 KNC tokens
GAS_PRICE: The gas price to use (affects the tx speed)
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.// Base URL for API queries// Refer to API/ABI >> RESTFul API Overview >> Network URL sectionconstNETWORK_URL=`https://${NETWORK=='main'?'':NETWORK+'-'}api.kyber.network`;// User DetailsconstPRIVATE_KEY='PRIVATE_KEY'; // Eg. 0x40ddbce3c7df9ab8d507d6b4af3861d224711b35299470ab7a217f780fe696cdconstwallet=newethers.Wallet(PRIVATE_KEY, provider);constUSER_ADDRESS=wallet.address;// Wallet Address for platform feesconstPLATFORM_WALLET='PLATFORM_WALLET'; // Eg. 0x483C5100C3E544Aef546f72dF4022c8934a6945EconstPLATFORM_FEE=25; // 0.25%// Token AddressesconstSRC_TOKEN_ADDRESS='0x7b2810576aa1cce68f2b118cef1f36467c648f92'; // Ropsten KNC token addressconstDEST_TOKEN_ADDRESS='0xaD6D458402F60fD3Bd25163575031ACDce07538D'; // Ropsten DAI token address// Src Token QuantityconstSRC_QTY=100; // 100 KNC tokens to swap from// Gas amount affecting speed of txconstGAS_PRICE='medium';
We first have to check if the traded tokens are supported on Kyber. We make use of the /currencies endpoint, which returns basic information about all tokens supported on Kyber. Details about possible path parameters and output fields can be found here.
It is recommended to use the token contract address as the identifier instead of the token symbol, as multiple tokens may share the same symbol.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.asyncfunctionisTokenSupported(tokenAddress) {let tokensBasicInfoRequest =awaitfetch(`${NETWORK_URL}/currencies`);let tokensBasicInfo =awaittokensBasicInfoRequest.json();let tokenSupported =tokensBasicInfo.data.some((token) => {returncaseInsensitiveEquals(tokenAddress,token.id); });if (!tokenSupported) {console.log('Token is not supported'); }return tokenSupported;}functioncaseInsensitiveEquals(a, b) {returntypeof a ==='string'&&typeof b ==='string'?a.localeCompare(b,undefined, { sensitivity:'accent', }) ===0: a === b;}
We use the /users/<user_address>/currencies endpoint to check whether the proxy contract has been approved for selling source tokens on behalf of the user. This endpoints returns a JSON of enabled statuses of ERC20 tokens for the given walletAddress. Details about the path parameters and output fields can be found here.
If the source token is not enabled for trading, querying the users/<user_address>/currencies/<currency_id>/enable_data endpoint returns a transaction payload needed to be signed and broadcasted by the user to enable the KyberNetwork contract to trade source tokens on his behalf. Details about the path parameters and output fields can be found here.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.asyncfunctioncheckAndApproveTokenForTrade( tokenAddress, userAddress, gasPrice,) {let enabledStatusesRequest =awaitfetch(`${NETWORK_URL}/users/${userAddress}/currencies`, );let enabledStatuses =awaitenabledStatusesRequest.json();let txsRequired =0;for (let token ofenabledStatuses.data) {if (caseInsensitiveEquals(tokenAddress,token.id)) { txsRequired =token.txs_required;break; } }switch (txsRequired) {case1:console.log('Approving to max amount');// No allowance so approve to maximum amount (2^255)awaitenableTokenTransfer(tokenAddress, userAddress, gasPrice);break;case2:// Allowance has been given but is insufficient. // Have to approve to 0 first to avoid this issue https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
// Approve to 0console.log('Approving to 0');awaitenableTokenTransfer(tokenAddress, userAddress, gasPrice);// Approve to maximum amount (2^255)console.log('Approving to max amount');awaitenableTokenTransfer(tokenAddress, userAddress, gasPrice);break;default:// Shouldn't need to do anything else in other scenarios.break; }}asyncfunctionenableTokenTransfer(tokenAddress, userAddress, gasPrice) {let enableTokenDetailsRequest =awaitfetch(`${NETWORK_URL}/users/${userAddress}/currencies/${tokenAddress}/enable_data?gas_price=${gasPrice}`, );let enableTokenDetails =awaitenableTokenDetailsRequest.json();awaitwallet.sendTransaction(enableTokenDetails.data);}
Create a function to get an approximate of the destination token amount for the specified amount of source token. We will use the /quote_amount endpoint in this function. Details about the path parameters and output fields can be found here.
Note:
The rates via the API are cached, so the /quote_amountdoes not support reserve routing and platform fees. Those have to be accounted for separately.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.asyncfunctiongetQuoteAmount(srcToken, destToken, srcQty) {constBPS=10000;// account for platform fees: subtracted from srcQtylet srcQtyAfterPlatformFee = (srcQty * (BPS-PLATFORM_FEE)) /BPS;let quoteAmountRequest =awaitfetch(`${NETWORK_URL}/quote_amount?base=${srcToken}"e=${destToken}&base_amount=${srcQtyAfterPlatformFee}&type=sell`, );let quoteAmount =awaitquoteAmountRequest.json();returnquoteAmount.data;}
We now have all the required information to peform the trade transaction. Querying the /trade_data endpoint will return the transaction payload to be signed and broadcasted by the user to make the conversion. Details about the path parameters and output fields can be found here.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.asyncfunctionexecuteTrade( userAddress, srcToken, destToken, srcQty, minDstQty, gasPrice, platformWallet, platformFee,) {let tradeDetailsRequest =awaitfetch(`${NETWORK_URL}/trade_data?user_address=${userAddress}&src_id=${srcToken}`+`&dst_id=${destToken}&src_qty=${srcQty}&min_dst_qty=${minDstQty}`+`&gas_price=${gasPrice}&wallet_id=${platformWallet}&wallet_fee=${platformFee}`, );let tradeDetails =awaittradeDetailsRequest.json();awaitwallet.sendTransaction(tradeDetails.data[0]);}
The main function will combine the different functions together to obtain the conversion rate, check that conditions are met for the trade, and execute the trade.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.asyncfunctionmain() {// Step 1: If either token is not supported, quitif (!(awaitisTokenSupported(SRC_TOKEN_ADDRESS)) ||!(awaitisTokenSupported(DEST_TOKEN_ADDRESS)) ) {// Quit the programprocess.exit(0); }// Step 2: Check if KNC token is enabled. If not, enable.awaitcheckAndApproveTokenForTrade(SRC_TOKEN_ADDRESS,USER_ADDRESS,GAS_PRICE, );// Step 3: Get expected DAI qty from selling 100 KNC tokenslet minDstQty =awaitgetQuoteAmount(SRC_TOKEN_ADDRESS,DEST_TOKEN_ADDRESS,SRC_QTY, );// Step 4: Perform the KNC -> DAI tradeawaitexecuteTrade(USER_ADDRESS,SRC_TOKEN_ADDRESS,DEST_TOKEN_ADDRESS,SRC_QTY, minDstQty,GAS_PRICE,PLATFORM_WALLET,PLATFORM_FEE, );// Quit the programprocess.exit(0);}
Before running this code example, the following fields need to be modified:
Change INFURA_PROJECT_ID to your Infura Project ID.
Change PRIVATE_KEY to the private key (with 0x prefix) of the Ethereum wallet holding Ether.
Change PLATFORM_WALLET to a wallet address for platform fees.
constethers=require('ethers');constfetch=require('node-fetch');// Connecting to a providerconstNETWORK='ropsten';constPROJECT_ID='INFURA_PROJECT_ID'; // Replace this with your own Project IDconstprovider=newethers.getDefaultProvider(NETWORK, { infura:PROJECT_ID });// Base URL for API queries// Refer to API/ABI >> RESTFul API Overview >> Network URL sectionconstNETWORK_URL=`https://${NETWORK=='main'?'':NETWORK+'-'}api.kyber.network`;// User DetailsconstPRIVATE_KEY='PRIVATE_KEY'; // Eg. 0x40ddbce3c7df9ab8d507d6b4af3861d224711b35299470ab7a217f780fe696cdconstwallet=newethers.Wallet(PRIVATE_KEY, provider);constUSER_ADDRESS=wallet.address;// Wallet Address for platform feesconstPLATFORM_WALLET='PLATFORM_WALLET'; // Eg. 0x483C5100C3E544Aef546f72dF4022c8934a6945EconstPLATFORM_FEE=25; // 0.25%// Token Addresses: Use 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee for ETHconstSRC_TOKEN_ADDRESS='0x7b2810576aa1cce68f2b118cef1f36467c648f92'; // Ropsten KNC token addressconstDEST_TOKEN_ADDRESS='0xaD6D458402F60fD3Bd25163575031ACDce07538D'; // Ropsten DAI token address// Src Token QuantityconstSRC_QTY=100; // 100 KNC tokens to swap from// Gas amount affecting speed of txconstGAS_PRICE='medium';asyncfunctionmain() {// Step 1: If either token is not supported, quitif (!(awaitisTokenSupported(SRC_TOKEN_ADDRESS)) ||!(awaitisTokenSupported(DEST_TOKEN_ADDRESS)) ) {// Quit the programprocess.exit(0); }// Step 2: Check if KNC token is enabled. If not, enable.awaitcheckAndApproveTokenForTrade(SRC_TOKEN_ADDRESS,USER_ADDRESS,GAS_PRICE, );// Step 3: Get expected DAI qty from selling 100 KNC tokenslet minDstQty =awaitgetQuoteAmount(SRC_TOKEN_ADDRESS,DEST_TOKEN_ADDRESS,SRC_QTY, );// Step 4: Perform the KNC -> DAI tradeawaitexecuteTrade(USER_ADDRESS,SRC_TOKEN_ADDRESS,DEST_TOKEN_ADDRESS,SRC_QTY, minDstQty,GAS_PRICE,PLATFORM_WALLET,PLATFORM_FEE, );// Quit the programprocess.exit(0);}asyncfunctionisTokenSupported(tokenAddress) {let tokensBasicInfoRequest =awaitfetch(`${NETWORK_URL}/currencies`);let tokensBasicInfo =awaittokensBasicInfoRequest.json();let tokenSupported =tokensBasicInfo.data.some((token) => {returncaseInsensitiveEquals(tokenAddress,token.id); });if (!tokenSupported) {console.log('Token is not supported'); }return tokenSupported;}functioncaseInsensitiveEquals(a, b) {returntypeof a ==='string'&&typeof b ==='string'?a.localeCompare(b,undefined, { sensitivity:'accent', }) ===0: a === b;}asyncfunctioncheckAndApproveTokenForTrade( tokenAddress, userAddress, gasPrice,) {let enabledStatusesRequest =awaitfetch(`${NETWORK_URL}/users/${userAddress}/currencies`, );let enabledStatuses =awaitenabledStatusesRequest.json();let txsRequired =0;for (let token ofenabledStatuses.data) {if (caseInsensitiveEquals(tokenAddress,token.id)) { txsRequired =token.txs_required;break; } }switch (txsRequired) {case1:console.log('Approving to max amount');// No allowance so approve to maximum amount (2^255)awaitenableTokenTransfer(tokenAddress, userAddress, gasPrice);break;case2:// Allowance has been given but is insufficient. // Have to approve to 0 first to avoid this issue https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
// Approve to 0console.log('Approving to 0');awaitenableTokenTransfer(tokenAddress, userAddress, gasPrice);// Approve to maximum amount (2^255)console.log('Approving to max amount');awaitenableTokenTransfer(tokenAddress, userAddress, gasPrice);break;default:// Shouldn't need to do anything else in other scenarios.break; }}asyncfunctionenableTokenTransfer(tokenAddress, userAddress, gasPrice) {let enableTokenDetailsRequest =awaitfetch(`${NETWORK_URL}/users/${userAddress}/currencies/${tokenAddress}/enable_data?gas_price=${gasPrice}`, );let enableTokenDetails =awaitenableTokenDetailsRequest.json();awaitwallet.sendTransaction(enableTokenDetails.data);}asyncfunctiongetQuoteAmount(srcToken, destToken, srcQty) {constBPS=10000;// account for platform fees: subtracted from srcQtylet srcQtyAfterPlatformFee = (srcQty * (BPS-PLATFORM_FEE)) /BPS;let quoteAmountRequest =awaitfetch(`${NETWORK_URL}/quote_amount?base=${srcToken}"e=${destToken}&base_amount=${srcQtyAfterPlatformFee}&type=sell`, );let quoteAmount =awaitquoteAmountRequest.json();returnquoteAmount.data;}asyncfunctionexecuteTrade( userAddress, srcToken, destToken, srcQty, minDstQty, gasPrice, platformWallet, platformFee,) {let tradeDetailsRequest =awaitfetch(`${NETWORK_URL}/trade_data?user_address=${userAddress}&src_id=${srcToken}`+`&dst_id=${destToken}&src_qty=${srcQty}&min_dst_qty=${minDstQty}`+`&gas_price=${gasPrice}&wallet_id=${platformWallet}&wallet_fee=${platformFee}`, );let tradeDetails =awaittradeDetailsRequest.json();awaitwallet.sendTransaction(tradeDetails.data[0]);}main();
In previous network versions, the hint parameter was used to filter permissionless reserves. With Katalyst, we utilise this parameter for routing trades to specific reserves.
There are 4 optional routing rules:
BestOfAll - This is the default routing rule when no hint is provided, and is the classic reserve matching algorithm used by the Kyber smart contracts since the beginning.
MaskIn (Whitelist) - Specify a list of reserves to be included and perform the BestOfAll routing on them
MaskOut (Blacklist) - Specify a list of reserves to be excluded and perform the BestOfAll routing on the remaining reserves
Split - Specify a list of reserves and their respective percentages of the total srcQty that will be routed to each reserve.
For token -> token trades, you can specify a routing rule for each half. For example, a MaskIn route can be used for the token -> ether side, while a Split route can be used for the ether -> token side.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.constfetch=require('node-fetch');constNETWORK_URL='ropsten-api.kyber.network';asyncfunctionfetchReservesInformation() {let token ='0x3dff0dce5fc4b367ec91d31de3837cf3840c8284'; // Ropsten WBTC addresslet type ='sell'; // token -> etherlet reserveInfoRequest =awaitfetch(`${NETWORK_URL}/reserves?token=${token}&type=${type}`, );let reserveInfo = (awaitreserveInfoRequest.json()).data;}awaitfetchReservesInformation();
Get reserves information for a ETH -> KNC trade.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.constfetch=require('node-fetch');constNETWORK_URL='ropsten-api.kyber.network';asyncfunctionfetchReservesInformation() {let token ='0x7b2810576aa1cce68f2b118cef1f36467c648f92'; // Ropsten KNC addresslet type ='buy'; // ether -> tokenlet reserveInfoRequest =awaitfetch(`${NETWORK_URL}/reserves?token=${token}&type=${type}`, );let reserveInfo = (awaitreserveInfoRequest.json()).data;}awaitfetchReservesInformation();
Querying the /hint endpoint will return data needed for the hint input parameter for the /trade_data endpoint. Details about the path parameters and output fields can be found here.
Build a KNC -> ETH MaskIn hint selecting the first reserve.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.constfetch=require('node-fetch');constNETWORK_URL='ropsten-api.kyber.network';asyncfunctionbuildHint() {// Fetch reserves for KNC -> ETH trade, select the first reservelet srcToken ='0x7b2810576aa1cce68f2b118cef1f36467c648f92'; // Ropsten KNC addresslet type ='sell'; // token -> etherlet reserveInfoRequest =awaitfetch(`${NETWORK_URL}/reserves?token=${srcToken}&type=${type}`, );let reserveInfo =awaitreserveInfoRequest.json();// Choose first reservelet reserveId =reserveInfo.data[0].id;// Other /hint endpoint parameters type ='t2e'; // token -> etherlet tradeType ='maskin';let hintRequest =awaitfetch(`${NETWORK_URL}/hint?type=${type}&token_src=${srcToken}&trade_type=${tradeType}&reserve_id=${reserveId}`, );let hint = (awaithintRequest.json()).data;}awaitbuildHint();
Build a ETH -> WBTC MaskOut hint excluding the first reserve.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.constfetch=require('node-fetch');constNETWORK_URL='ropsten-api.kyber.network';asyncfunctionbuildHint() {// Fetch reserves for ETH -> WBTC trade, select the first reservelet destToken ='0x3dff0dce5fc4b367ec91d31de3837cf3840c8284'; // Ropsten WBTC addresslet type ='buy'; // ether -> tokenlet reserveInfoRequest =awaitfetch(`${NETWORK_URL}/reserves?token=${destToken}&type=${type}`, );let reserveInfo =awaitreserveInfoRequest.json();// Choose first reserve to be excludedlet reserveId =reserveInfo.data[0].id;// Other /hint endpoint parameters type ='e2t'; // ether -> tokenlet tradeType ='maskout';let hintRequest =awaitfetch(`${NETWORK_URL}/hint?type=${type}&token_dest=${destToken}&trade_type=${tradeType}&reserve_id=${reserveId}`, );let hint = (awaithintRequest.json()).data;}awaitbuildHint();
Build a KNC -> WBTC hint with the following routes:
KNC -> ETH: Split trade among 2 reserves:
1st reserve trades 70%, 2nd reserves trades 30%
ETH -> WBTC: BestOfAll trade
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.constfetch=require('node-fetch');constNETWORK_URL='ropsten-api.kyber.network';asyncfunctionbuildHint() {// Fetch reserves for KNC -> ETH trade, select 2 reserveslet srcToken ='0x7b2810576aa1cce68f2b118cef1f36467c648f92'; // Ropsten KNC addresslet type ='sell'; // token -> etherlet reserveInfoRequest =awaitfetch(`${NETWORK_URL}/reserves?token=${srcToken}&type=${type}`, );let reserveInfo =awaitreserveInfoRequest.json();let firstReserve =reserveInfo.data[0].id;let secondReserve =reserveInfo.data[1].id;// Other /hint endpoint parameters type ='t2t'; // token -> tokenlet firstTradeType ='split';let secondTradeType ='bestofall';let destToken ='0x3dff0dce5fc4b367ec91d31de3837cf3840c8284'; // Ropsten WBTC addresslet firstSplit ='7000';let secondSplit ='3000';let hintRequest =awaitfetch( `${NETWORK_URL}/hint?type=${type}&trade_type=${firstTradeType}&token_src=${srcToken}&reserve_id=${firstReserve},${secondReserve}&split_value=${firstSplit},${secondSplit}&trade_type=${secondTradeType}&token_dest=${destToken}`,
);let hint = (awaithintRequest.json()).data;}awaitbuildHint();
Get the parameters needed for a 100 KNC -> DAI trade with MaskIn reserve routing for KNC -> ETH.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.constfetch=require('node-fetch');constNETWORK_URL='ropsten-api.kyber.network';asyncfunctiongetTradeParams() {// Building hintlet type ='t2e';let srcToken ='0x7b2810576aa1cce68f2b118cef1f36467c648f92'; // Ropsten KNC token addresslet tradeType ='maskin';let reserveId ='0xff00004b79626572000000000000000000000000000000000000000000000000';let hintRequest =awaitfetch(`${NETWORK_URL}/hint?type=${type}&token_src=${srcToken}&trade_type=${tradeType}&reserve_id=${reserveId}`, );let hint = (awaithintRequest.json()).data;// Trade Parameterslet userAddress ='0x483C5100C3E544Aef546f72dF4022c8934a6945E';let destToken ='0xaD6D458402F60fD3Bd25163575031ACDce07538D'; // Ropsten DAI token addresslet srcQty =100;let minDstQty =1;let gasPrice ='medium';let platformWallet ='0x483C5100C3E544Aef546f72dF4022c8934a6945E';let platformFee =25; // 0.25%let tradeDetailsRequest =awaitfetch(`${NETWORK_URL}/trade_data?user_address=${userAddress}&src_id=${srcToken}`+`&dst_id=${destToken}&src_qty=${srcQty}&min_dst_qty=${minDstQty}`+`&gas_price=${gasPrice}&wallet_id=${platformWallet}&wallet_fee=${platformFee}`+`&hint=${hint}`, );let tradeDetails = (awaittradeDetailsRequest.json()).data;}
The /currencies endpoint returns basic information about all tokens supported on Kyber. Details about possible path parameters and output fields can be found here.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.constfetch=require('node-fetch');asyncfunctiongetSupportedTokens() {let tokensBasicInfoRequest =awaitfetch('https://api.kyber.network/currencies', );let tokensBasicInfo =awaittokensBasicInfoRequest.json();console.log(tokensBasicInfo);return tokensBasicInfo;}awaitgetSupportedTokens();
The /market endpoint returns price and volume information on token to ETH pairs supported on Kyber. Details about possible path parameters and output fields can be found here.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.constfetch=require('node-fetch');asyncfunctiongetMarketInformation() {let marketInfoRequest =awaitfetch('https://api.kyber.network/market');let marketInfo =awaitmarketInfoRequest.json();console.log(tokensBasicInfo);return marketInfo;}awaitgetMarketInformation();
The /change24h endpoint returns current token to ETH and USD rates and price percentage changes against the previous day. Details about possible path parameters and output fields can be found here.
// DISCLAIMER: Code snippets in this guide are just examples and you// should always do your own testing. If you have questions, visit our// https://t.me/KyberDeveloper.constfetch=require('node-fetch');asyncfunctiongetPast24HoursTokenInformation() {let past24HoursTokenInfoRequest =awaitfetch('https://api.kyber.network/change24h', );let past24HoursTokenInfo =awaitpast24HoursTokenInfoRequest.json();console.log(past24HoursTokenInfo);return past24HoursTokenInfo;}awaitgetPast24HoursTokenInformation();