Guide

About Relayer API

The Relayer API connects you with Native's deep liquidity and competitive quotes, powered by our network of market makers.

1. Get an API key

To start, fill out the form, and Native will provide you with an API key.

2. Read the orderbook

The latest prices for each pair we quote on a specified chain are published in an orderbook.

Our orderbook is updated every second with the latest prices quoted by our partners

Here's how to retrieve the orderbook:

var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://newapi.native.org/swap/v1/orderbook?chain=ethereum',
  'headers': {
    'apikey': 'your-api-key'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

Refer to GET Orderbook for the full reference.

Sample response

[
    {
        "base_symbol": "WETH",
        "base_address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        "quote_symbol": "USDT",
        "quote_address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
        "levels": [
            [
                0.0001,
                2741.71
            ],
            [
                10,
                2741.72
            ],
            [
                40.75786733219471,
                2741.54
            ]
        ],
        "side": "bid",
        "minimum_in_base": 0.0001
    },
}

3. Get a firm quote

Next, obtain a quote with a price that Native is committed to. If the quote is favorable, you can execute it by submitting the associated call data to the Native Router on-chain.

var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://newapi.native.org/swap/v1/firm-quote?chain=ethereum&address=0x46b2deae6eff3011008ea27ea36b7c27255ddfa9&amount=1&token_in=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2&token_out=0xdac17f958d2ee523a2206206994597c13d831ec7',
  'headers': {
    'apikey': 'your-api-key'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

Sample response

{
    "router_version": "1",
    "success": true,
    "source": "p1.1",
    "functionCall": "tradeRFQT",
    "orders": [
        {
            "pool": "0x28cacd5e26a719f139e2105ca1efc3d9dc892826",
            "signer": "0xff8ba4d1fc3762f6154cc942ccf30049a2a0cec6",
            "recipient": "0x46b2deae6eff3011008ea27ea36b7c27255ddfa9",
            "sellerToken": "0x0000000000000000000000000000000000000000",
            "buyerToken": "0xdac17f958d2ee523a2206206994597c13d831ec7",
            "effectiveSellerTokenAmount": "1000000000000000000",
            "sellerTokenAmount": "1000000000000000000",
            "buyerTokenAmount": "2740580786",
            "deadlineTimestamp": 1724642218,
            "nonce": 3291440531122899,
            "quoteId": "0xb46b8131a5144a5bb2214fc35a3403db",
            "multiHop": false,
            "signature": "0x4512df300b8c8de9b3e58c29d7a32868c0e9f45d81c9414899849eaa646ead085e432eb9c7bc4c55f96f0f959ca76690f3be9932a0de7950a2152360094d00a91b",
            "externalSwapCalldata": "0x",
            "amountOutMinimum": "2740580786",
            "widgetFee": {
                "signer": "0x67297ee4eb097e072b4ab6f1620268061ae80464",
                "feeRate": "0",
                "feeRecipient": "0x60CBA82DdBf4b5dDcd4398cDd05354C6A790C309"
            },
            "widgetFeeSignature": "0xc760273902ddad1e1af436281f2887e1186a1ae319ad9ffae760d3db9ecd59ca76bf4d3b7761c68582ffdb8e91b4d3238494a3e36a5a8b5be7b016e8f014d8fd1b"
        }
    ],
    "calldata": "0x000000000000000000000000000000000000000000000000000bb18c37a82ad3ff8ba4d1fc3762f6154cc942ccf30049a2a0cec628cacd5e26a719f139e2105ca1efc3d9dc89282646b2deae6eff3011008ea27ea36b7c27255ddfa9dac17f958d2ee523a2206206994597c13d831ec7c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000a359f1b20000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000066cbf3aa46b2deae6eff3011008ea27ea36b7c27255ddfa9b46b8131a5144a5bb2214fc35a3403db4512df300b8c8de9b3e58c29d7a32868c0e9f45d81c9414899849eaa646ead085e432eb9c7bc4c55f96f0f959ca76690f3be9932a0de7950a2152360094d00a91b",
    "amountIn": "1000000000000000000",
    "amountOut": "2740580786",
    "toWrap": false,
    "toUnwrap": false,
    "fallbackSwapDataArray": [],
    "txRequest": {
        "target": "0xEAd050515E10fDB3540ccD6f8236C46790508A76",
        "calldata": "0xe525b10b000000000000000000000000000000000000000000000000000000000000002000000000000000000000000028cacd5e26a719f139e2105ca1efc3d9dc892826000000000000000000000000ff8ba4d1fc3762f6154cc942ccf30049a2a0cec600000000000000000000000046b2deae6eff3011008ea27ea36b7c27255ddfa90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000a359f1b20000000000000000000000000000000000000000000000000000000066cbf3aa000000000000000000000000000000000000000000000000000bb18c37a82ad3b46b8131a5144a5bb2214fc35a3403db000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000026000000000000000000000000067297ee4eb097e072b4ab6f1620268061ae8046400000000000000000000000060cba82ddbf4b5ddcd4398cdd05354c6a790c309000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e0000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000a359f1b200000000000000000000000000000000000000000000000000000000000000414512df300b8c8de9b3e58c29d7a32868c0e9f45d81c9414899849eaa646ead085e432eb9c7bc4c55f96f0f959ca76690f3be9932a0de7950a2152360094d00a91b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041c760273902ddad1e1af436281f2887e1186a1ae319ad9ffae760d3db9ecd59ca76bf4d3b7761c68582ffdb8e91b4d3238494a3e36a5a8b5be7b016e8f014d8fd1b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "value": "1000000000000000000"
    },
    "amountInOffset": 196,
    "amountOutMinimumOffset": 0
}

4. Submit call data to Native Router

To execute a firm quote, submit a transaction on-chain to call the Native Router with the returned call data.

You can find the contract ABI and addresses here.

Here’s an example of how to submit call data to the Native Router:

import axios from 'axios';
import {ethers} from "ethers";
// import routerAbi from './nativeRouter.json'

const apiKey = 'your-api-key'
const baseUrl = 'https://newapi.native.org/v1/';

const provider = 'https://eth.llamarpc.com';
const routerAddress = '0xEAd050515E10fDB3540ccD6f8236C46790508A76'; // Refer to Contract Address section -> NativeRouter (Proxy) for the address

const walletAddress = ''; // Your address
const privateKey = ''; // Your private key for the address above

// Swap input
const chain = 'ethereum'; // 1, 56
const tokenIn = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'; // ETH
const tokenOut = '0xdAC17F958D2ee523a2206206994597C13D831ec7'; // USDT
const amount = 1; // in ether, not in wei

type FirmQuoteResult = {
  orders: any[],
  widgetFee: {
    signer: string,
    feeRecipient: string,
    feeRate: number
  },
  widgetFeeSignature: string,
  calldata: string,
  amountIn: string,
  amountOut: string,
  fallbackData: string
}

async function callFirmQuote(): Promise<FirmQuoteResult> {
  const endpoint = 'firm-quote?';
  const headers: any = {
    api_key: apiKey,
  };

  const response = await axios
    .get(
      `${baseUrl}${endpoint}chain=${chain}&token_in=${tokenIn}&token_out=${tokenOut}&amount=${amount}&address=${walletAddress}`,
      {
        headers,
      }
    )
  console.log('Firm quote result', response.data)
  return response.data;
}

async function callRouterToSwap(firmQuoteResult: FirmQuoteResult) {
  const jsonRpcProvider = new ethers.JsonRpcProvider(provider);
  const signer = new ethers.Wallet(privateKey, jsonRpcProvider);
  const tx = await signer.sendTransaction({to: routerAddress, data: firmQuoteResult.calldata});
  await tx.wait()
}

async function main() {
  const firmQuoteResult = await callFirmQuote();
  await callRouterToSwap(firmQuoteResult)
}

main();

Last updated