> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rubic.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration

# Configuration

## SDK.create()

```typescript theme={null}
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

| Field                          | Type     | Required | Default        | Description                                                                                        |
| ------------------------------ | -------- | -------- | -------------- | -------------------------------------------------------------------------------------------------- |
| `referrer`                     | `string` | ✅        | —              | Identifies your integration. Sent as `referer` in every request body                               |
| `apiKey`                       | `string` |          | `''`           | API key for the Rubic API. Get one at [here](https://t.me/RubicPartnership)                        |
| `integratorAddress`            | `object` |          | See below      | Wallet addresses that collect integrator fees (text our [BD](https://t.me/RubicPartnership) first) |
| `integratorAddress.crossChain` | `string` |          | `0x3fFF...DbE` | Fee recipient for cross-chain swaps                                                                |
| `integratorAddress.onChain`    | `string` |          | `0x3b9C...0d4` | Fee recipient for on-chain swaps                                                                   |
| `timeout`                      | `number` |          | `10000`        | Request timeout in ms (default HTTP client only)                                                   |

### Example — full configuration

```typescript theme={null}
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)

```typescript theme={null}
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

```typescript theme={null}
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

```typescript theme={null}
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.)

```typescript theme={null}
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.
