2️⃣Set up SDK

After you have installed the SDK, you first need to set it up.

SDK Initiation

After installation, you will need to initialize the SDK.

Set up after CDN installation

const config = {
  rpcProviders: {
    BSC: {
      rpcList: ['https://bsc-dataseed.binance.org/', ...]
    },
    POLYGON: {
      rpcList: ['https://polygon-rpc.com', ...]
    },
    TRON: {
      rpcList: [
        {
          fullHost: '<tron-api>',
          headers: { "TRON-PRO-API-KEY": 'your api key' }
        }
      ]
    }
  }
};

const rubicSdk = await RubicSDK.SDK.createSDK(config);

Set up after npm installation

In case of npm installation, you have to import SDK from rubic-sdk package. Then you can initiate it:

Configuration providing

To create SDK instance you should provide config parameter, this is an object containing the rpc, wallets, http client settings, and your personal integrator wallet address.

Providing RPC options

RpcProviders is Rpc data to connect to blockchains you will use. You have to pass rpcProvider for each blockchain you will use with sdk, as presented in example below:

Providing wallet options

If at the time when you initiating SDK, users have already logged into your platform, you can provide walletProvider object, but it is no necessary, until you want to swap with SDK:

If user with address 0xB72DE277A5s577C945B0C52acD8fD2a7cFDaFD18 logged in with Ethereum network, right walletProvider object should be as follows:.

Your own client for HTTP requests

You can also pass your own http client as httpClient parameter (e.g. HttpClient in Angular) if you have it, to not duplicate http clients and decrease bundle size.

Your wallet address as integrator

This is one of the most important steps, please send to the Rubic team the providerAddress - the wallet address to which the fees will be credited. To make it work properly, you need to contact us so that we can whitelist you.

Update SDK configuration

When user finally connects the walet, you have to notify SDK about it.

You should do it on every address and network change events

SDK object

When SDK was initiated, you are able to refer it's fields and methods.

Last updated

Was this helpful?