2⃣
Set up the SDK
After you have installed the SDK, you first need to set it up.
To get started, you have to instantiate and configure the LI.FI SDK:
import { LiFi } from '@lifi/sdk'
const lifi = new LiFi({
integrator: 'Your dApp/company name'
})
// or
const { LiFi } = require("@lifi/sdk")
const lifi = new LiFi({
integrator: 'Your dApp/company name'
})
The optional
config
parameter can be used to pass custom configuration to the SDK:type ConfigUpdate = {
apiUrl?: string
rpcs?: Record<number, string[]>
multicallAddresses?: Record<number, string | undefined>
defaultExecutionSettings?: ExecutionSettings
defaultRouteOptions?: RouteOptions
}
The
apiUrl
defines which backend should be called. This only has to be edited when accessing a dedicated API endpoint. rpcs
or multicallAddresses
can be passed if custom endpoints/addresses should be used, for example to prevent rate limiting.SDK uses native Fetch API and in Node.js 16 and lower versions
fetch
is not natively included, so it needs to be added manually. To provide access to Fetch API you need to patch global
object using node-fetch or cross-fetch. import fetch, { Headers, Request, Response } from 'cross-fetch'
if (!globalThis.fetch) {
const globalThisAny: any = globalThis
globalThisAny.fetch = fetch
globalThisAny.Headers = Headers
globalThisAny.Request = Request
globalThisAny.Response = Response
}