# API

## Trade with the CEXISWAP API

```typescript
// Buy one WBTC with USDT
const params = {
    toAddr: MY_WALLET_ADDR,
    chain: 'ETH',
    buyToken: 'WBTC',
    sellToken: 'USDT',
    buyAmount: '100000000',
}

const unsignedTx = await fetch(
    `https://api.cexiswap.io/swap/v1/quote?${qs.stringify(params)}`
)

const signer = new ethers.Wallet(YOUR_PRIVATE_KEY_STRING, provider)
await signer.sendTransaction({
  to: unsignedTx.to,
  chainId: unsignedTx.chainId,
  value: unsignedTx.value === '0' ? '0x0' : unsignedTx.value,
  data: unsignedTx.data,
})
```

<table><thead><tr><th>Endpoint</th><th width="248.66666666666669">Request</th><th>Response</th></tr></thead><tbody><tr><td><strong>swap/v1/price</strong></td><td><code>chain</code>: 'ETH', 'POLYGON', 'BSC', 'THUNDERCORE', 'AVAX'<br><br><code>buyToken</code>: 'ETH', 'WBTC', 'USDT'<br><code>sellToken</code>: (same as buyToken)<br><br><code>buyAmount</code> or <code>sellAmount</code>: amount in the on-chain units of the token, e.g. <code>1000000</code> is 1 USDT<br></td><td><code>price</code>: the price of buyToken in sellToken or vice versa </td></tr><tr><td><strong>swap/v1/quote</strong></td><td><code>chain</code>: 'ETH', 'POLYGON', 'BSC', 'THUNDERCORE', 'AVAX'<br><br><code>buyToken</code>: 'ETH', 'WBTC', 'USDT'<br><code>sellToken</code>: (same as buyToken)<br><br><code>buyAmount</code> or <code>sellAmount</code>: amount in the on-chain units of the token, e.g. <code>1000000</code> is 1 USDT<br><br>(same as <strong>swap/v1/price</strong>)</td><td><code>to</code> : the address of the contract to send the blockchain transaction to<br><br><code>data</code>: the call data for the blockchain transaction<br> <br><code>allowanceTarget</code>: the target contract address for setting ERC20 sell token allowance<br><br><code>price</code>: the price of buyToken in sellToken or vice versa</td></tr><tr><td><strong>swap/v1/tokens</strong></td><td><code>chain</code>: 'ETH', 'POLYGON', 'BSC', 'THUNDERCORE', 'AVAX'</td><td>List of { "symbol", "chain", "address", "decimals", "disabled" }</td></tr></tbody></table>

### Allowance Targets

When your `sellToken` is an ERC-20 token, you will need to give CEXISWAP contracts permission to use that token by setting a [token allowance](https://tokenallowance.io/). The `allowanceTarget` in the response is the contract address that you should set the allowance for.\
\
For example:  `inputToken.approve(response.allowanceTarget)`
