Skip to content

Get started

Welcome to the Lanca SDK documentation! This page will guide you through the process of getting started with the Lanca SDK.

Installation

To install the Lanca SDK, run the following command in your terminal:

npm
npm i @lanca/sdk

Creating a Configuration

To use the Lanca SDK, you need to create a configuration object. Here is an example of a basic configuration:

import { LancaClient } from '@lanca/sdk'
import type { ILancaClientConfig, IChainWithProvider } from '@lanca/sdk'
import { createWalletClient } from 'viem'
import { polygon, base } from 'viem/chains'
 
const config: ILancaClientConfig = {
    integratorAddress: 'YOUR_INTEGRATOR_ADDRESS',
    feeBps: 1n,
    chains: {
        '137': {
            chain: polygon,
            provider: http(),
        },
        '8453': {
            chain: base,
            provider: http(),
        }
    } as Record<string, IChainWithProvider>,
};

Replace YOUR_INTEGRATOR_ADDRESS with the actual address of the integrator. Collected fees are accumulated in the Lanca Orchestrator contract and can only be withdrawn by the integrator.

Set feeBps as the desired fee rate in basis points (bps). This fee is applied in addition to the Lanca fee.

Creating a LancaClient

To use the Lanca SDK, you need to create a LancaClient object. Here is an example of a basic usage:

const lancaClient = new LancaClient(config)

Request a route

To request a route for token exchange, please provide the addresses of the two tokens, their network IDs, the amount of the first token, and the slippage percentage. For example, you can request a route by specifying the token addresses, network IDs, amount, and slippage, and our SDK will provide you with the optimal route for the exchange.

const route = await lancaClient.getRoute({
	fromChainId: '137', // polygon
	toChainId: '8453', //  base
	fromToken: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359', // USDC
	toToken: '0x4200000000000000000000000000000000000006', //WETH
	amount: '1000000', // 1 USDC in machine-readable format
	fromAddress: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',
	toAddress: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',
	slippageTolerance: '0.5',
})

Execute a route

To execute a route for token exchange, please provide the obtained route data and our SDK will handle the exchange process for you. Simply pass the route data to the LancaSDK object and it will execute the exchange according to the provided parameters.

const walletClient = createWalletClient({
	chain: polygon,
	transport: custom(window.ethereum!),
})
 
const executionConfig: IExecutionConfig = {
	switchChainHook: async (chainId: number) => {
		console.log(chainId);
	},
	updateRouteStatusHook: (route: IRouteType) => console.log(route),
};
 
const routeWithStatus = await lancaClient.executeRoute(route, walletClient, executionConfig)

Track route status

To track the status of a route for token exchange, you can use the getRouteStatus method of the LancaClient object. This method allows you to retrieve the current status of the route, including any updates or changes that have occurred during the exchange process.

const routeStatus = await lancaClient.getRouteStatus(
	'0x231b5f78e90bf71996fd65a05c93a0d0fdb562a2cd8eb6944a833c80bae39b3e',
)

This is just a basic example to get you started. For more information on the Lanca SDK and its features, please refer to the rest of the documentation.

Next Steps

  • Learn more about the Lanca SDK and its features
  • Explore the API reference for more information on the available methods and properties
  • Check out the examples section for more code snippets and tutorials