Skip to main content

Configuration

SDK.create()

const sdk = await SDK.create(params: SdkParams, httpClient?: HttpClient): Promise<SDK>
The factory method is async because it dynamically imports axios when no custom HTTP client is provided.

SdkParams

FieldTypeRequiredDefaultDescription
referrerstringIdentifies your integration. Sent as referer in every request body
apiKeystring''API key for the Rubic API. Get one at here
integratorAddressobjectSee belowWallet addresses that collect integrator fees (text our BD first)
integratorAddress.crossChainstring0x3fFF...DbEFee recipient for cross-chain swaps
integratorAddress.onChainstring0x3b9C...0d4Fee recipient for on-chain swaps
timeoutnumber10000Request timeout in ms (default HTTP client only)

Example — full configuration

import { SDK } from '@cryptorubic/sdk-lite';

const sdk = await SDK.create({
    referrer: 'my-dapp',
    apiKey: 'YOUR_API_KEY',
    integratorAddress: {
        crossChain: '0xYourFeeReceiverForCrossChain',
        onChain: '0xYourFeeReceiverForOnChain',
    },
    timeout: 15_000,
});

Example — minimal configuration (no API key)

const sdk = await SDK.create({ referrer: 'my-dapp' });

Custom HTTP client

By default, SDK ships with an axios-based HTTP client. You can swap it out for any client that implements the HttpClient interface — useful for environments without Node.js (e.g. Cloudflare Workers, Deno, React Native).

HttpClient interface

interface HttpClient {
    get<T>(url: string, options?: {
        headers?: Record<string, string>;
        params?: Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
    }): Promise<T>;

    post<T>(url: string, body: object, options?: {
        headers?: Record<string, string>;
    }): Promise<T>;
}

Example — using native fetch

import { SDK, HttpClient } from '@cryptorubic/sdk-lite';

const fetchClient: HttpClient = {
    async get(url, options = {}) {
        const searchParams = new URLSearchParams(
            Object.entries(options.params ?? {}).map(([k, v]) => [k, String(v)])
        );
        const fullUrl = searchParams.size ? `${url}?${searchParams}` : url;
        const res = await fetch(fullUrl, { headers: options.headers });
        if (!res.ok) throw new Error(`HTTP ${res.status}`);
        return res.json();
    },
    async post(url, body, options = {}) {
        const res = await fetch(url, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json', ...options.headers },
            body: JSON.stringify(body),
        });
        if (!res.ok) throw new Error(`HTTP ${res.status}`);
        return res.json();
    },
};

const sdk = await SDK.create({ referrer: 'my-app' }, fetchClient);

Example — custom axios instance (with interceptors, retries, etc.)

import axios from 'axios';
import { SDK } from '@cryptorubic/sdk-lite';

const axiosInstance = axios.create({ timeout: 20_000 });

axiosInstance.interceptors.response.use(
    res => res.data,
    err => Promise.reject(err)
);

const sdk = await SDK.create({ referrer: 'my-app' }, axiosInstance);
Note: When using a custom axios instance, make sure the response interceptor unwraps res.data — otherwise the SDK will receive the full axios response object instead of the API response body.