SDK API

Api module, method through HTTP interface query data

Go to the detailed interface documentation

https://docs.0xgen.io/api/api

// Base code block
import { GenSdk } from '@gen-io/gen-sdk';
const genSdk = new GenSdk({
  apiUrl: "https://api.0xgen.io",
});
const { api } = genSdk

getGasPrice

let data = await api.getGasPrice({
   chain: 'bsc'
})

getTokenPrice

let data = api.getTokenPrice({
       ids: 'bitcoin',
       vs_currencies: 'usd'
})
       

getTokenList

let data=awit api.getTokenList({
    chain: 'BSC',
})

quote

let gasPrice = await api.getGasPrice({
  chain: 'bsc',
})
let quoteData = await api.quote({
  chain: 'bsc',
  inTokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
  outTokenAddress: '0x55d398326f99059ff775485246999027b3197955',
  amount: '5',
  gasPrice: gasPrice.data.gasPrice,
  slippage: 3,
})

swapQuote

dex: 1inch,matcha、openocean、jupiter

slippage: 3=3%

let gasPrice = await api.getGasPrice({
  chain: 'bsc',
})
let swapData = await swapSdk.swapQuote({
  chain: 'bsc',
  dex: 'openOcean',
  inTokenAddress: '0x55d398326f99059ff775485246999027b3197955',
  outTokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
  amount: '0.1',
  gasPrice: gasPrice.data.gasPrice,
  slippage: 3,
  account: 'The address of your wallet',
})

Last updated