The XATA-API module

The source code for this module can be found here on Github, inside the ./src/xata-api directory.

Each function within this module bundles the process of EIP712 signing, fee token calculation, and submitting meta transaction into a single workflow. The supported functions are the following:

  • addLiquidity()

  • swapExactTokensForTokens()

  • swapTokensForExactTokens()

  • removeLiquidity()

Using this module, developers no longer required to manually construct a transaction request that looks like this:

    "method": "POST",
        "Content-Type": "application/json"


To use XATA-API module, you must first install the XATA SDK package from NPM.

$ yarn add @xatadev/sdk

We recommend you use Yarn to run the installation. If you prefer to use NPM (as some of us do!), just run the installation using this command:

$ npm i @xatadev/sdk

⚠️ It's best not to mix up the use of package managers to avoid resolution inconsistencies. Talk to your team and ask which package manager they are using.

Getting Started

To use the module, simply do the following 3 steps:

  1. Declare an instance of the XATA module.

import { Xata } from '@xatadev/sdk';

const xataApi = new Xata();
  1. Initiate the instance

const feeToken = '<0xAddress>'
await xataApi.init(web3Provider, feeToken)

// use this method to change the fee token
const otherFeeToken = '<0xOtherAddress>'
await xataApi.setFeeToken(otherFeeToken)
  1. Interact with XATA

You may now interact with the XATA router using Uniswap-like functions. These functions return API responses like the one below:

// response example
    "jsonrpc": "2.0",
    "result": {
        "errorMessage": null,
        "success": true,
        "txnHash": "0x3a130c90692053f412a26f6d7914bb7637f0193c0a7054621d3e3c3a7d13c24a"
    "id": 1

We'll take a closer look at these functions in the following section.

Router Methods

Add Liquidity

Adds liquidity to the pool. If liquidity for the supplied pair does not exist in the pool then this router will initiate liquidity creation automatically.

await xataApi.addLiquidity(<params>)

Swap Exact Tokens For Tokens

Swaps an exact amount of input tokens for as many output tokens as possible.

await xataApi.swapExactTokensForTokens(<params>)

Swap Tokens For Exact Tokens

Receive an exact amount of output tokens for as few input tokens as possible.

await xataApi.swapTokensForExactTokens(<params>)

Remove Liquidity

Withdraws a pair of tokens by burning LP tokens. This method consists of a 2-steps flow; it requires the LP holders to first sign a permit message, allowing the router to burn LP tokens, then proceeds with the actual LP tokens removal.

First, sign the message by calling the permitLP function. (No gas required)

await xataApi.permitLP(<params>)

It will return a Signature object that is required for removing liquidity.

  "v": number,
  "r": string,
  "s": string

Once you receive the signature object from the permitLP then you can invoke the removeLiquidity function to withdraw tokens.

await xataApi.removeLiquidity(<params>)

Relay Config

When a transaction request is successfully sent to one of the API routers, the transaction is forwarded and processed by Geode – one of our technologies that can increase privacy and eliminate trading MEV. To do this, the XATA SDK stores the Geode relay configuration as part of the API module.

[ChainId.MATIC]: '',
[ChainId.BSC]: '',

Developers can freely customize these endpoints to meet their application needs. To customize it, set new endpoint value(s) for each chain that is supported by your app. You can find the config here.

Using a Test Relay on Development

XATA API works on production mode by default, and therefore the transaction request also gets forwarded to production-grade Geode. If you are under the development stage and want to test the transaction on a separate relay, you need to make a couple of changes.

Update the relay configuration as in the previous section. What makes it different from the previous one is that you have to set the endpoint value(s) under the Environment.STAGING object instead of Environment.PRODUCTION.

[Environment.PRODUCTION]: {
    [ChainId.MATIC]: '',
    [ChainId.BSC]: '',
[Environment.STAGING]: {
    [ChainId.MATIC]: 'https://your-test-relay.endpoint',
    [ChainId.BSC]: 'https://your-test-relay.endpoint',

Update the XATA initiation code on your app.

// Add new Environment enum import
import { Environment, XATA } from '@xatadev/sdk'

const xataApi = new Xata();
const feeToken = '<0xAddress>'

// Add 3rd param to override the SDK env mode
await xataApi.init(web3Provider, feeToken, Environment.STAGING)

Last updated