Skip to content

LancaSDK

The LancaClient class provides a set of methods for interacting with the Lanca API.

Methods

getRoute

Description

Retrieves a route for a given set of parameters. The route is an object that contains the necessary information for executing a swap.

Parameters

  • fromChainId : string. The ID of the source chain from which the tokens will be swapped. This identifies the blockchain network where the tokens currently reside.
  • toChainId : string. The ID of the destination chain to which the tokens will be swapped. This indicates the blockchain network where the tokens will be sent after the swap.
  • fromToken : Address. The address of the token that the user wishes to swap from. This should be the contract address of the token being exchanged.
  • toToken :Address. The address of the token that the user wishes to swap to. This should be the contract address of the token that the user wants to receive in exchange.
  • amount : string. The amount of tokens to be swapped. This value should represent the quantity of the fromToken that the user intends to exchange.
  • fromAddress: Address. The address of the user from whom the tokens will be taken. This is the wallet address that holds the fromToken and will initiate the swap.
  • toAddress: Address. The address where the swapped tokens will be sent. This is the wallet address that will receive the toToken after the swap is completed.
  • slippageTolerance : string . The maximum allowed slippage during the swap transaction, expressed as a percentage. This parameter is optional, with a default value of '0.5'. Slippage refers to the difference between the expected price of a trade and the actual price at which the trade is executed. Setting a slippage tolerance helps to ensure that the transaction will go through even if the market conditions change slightly during the swap process.

Return Type

  • Promise<IRouteType | undefined>

Error Types

  • UnsupportedTokenError - thrown when the specified token(s) is(are) not supported for swapping.
  • UnsupportedChainError - thrown when the specified chain(s) is(are) not supported for swapping.
  • WrongAmountError - thrown when the amount specified for the swap is incorrect.
  • TokensAreTheSameError - thrown when the fromToken and toToken are the same.
  • NoRouteError - thrown when no valid route is found for the swap.
  • TooHighAmountError - thrown when the specified amount exceeds the allowed limit.
  • TooLowAmountError - thrown when the specified amount is below the minimum required for the swap.
  • AmountBelowFeeError - thrown when the amount is less than the transaction fee.
  • WrongSlippageError - thrown when the specified slippage tolerance is invalid.
  • MissingParamsError - thrown when required parameters are missing.
  • HTTPError - thrown when there is an issue with the HTTP request during the swap process.
  • UserRejectedError - thrown when the user rejected to sing the transaction

Example

const lancaClient = new LancaClient(config)
const route = await lancaClient.getRoute({
	fromChainId: '137',
	toChainId: '8453',
	fromToken: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', //WETH
	toToken: '0x0555E30da8f98308EdB960aa94C0Db47230d2B9c', //WBTC
	fromAddress: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',
	toAddress: '0x0555E30da8f98308EdB960aa94C0Db47230d2B9c',
	amount: '100000',
	slippageTolerance: '0.5',
})

getSupportedTokens

Description

Retrieves a list of supported tokens for a given chain ID, name, symbol, and limit.

Parameters

  • chainId : string. The ID of the chain to retrieve tokens for
  • name? : string. The name of the token to retrieve
  • symbol? : string. The symbol of the token to retrieve
  • limit :string. The maximum number of tokens to retrieve (optional, default: '10000000')

Return Type

  • Promise<ILancaToken[] | undefined>

Example

const lancaClient = new LancaClient(config)
const supportedTokens = await lancaClient.getSupportedTokens({
    chainId: '137',
    name: 'Wrapped Ether',
    symbol: 'WETH' 
    limit: '10'
})

getSupportedChains

Description

Retrieves a list of supported chains.

Parameters

  • None

Return Type

  • Promise<ILancaChain[] | undefined>

Example

const lancaClient = new LancaClient(config)
const supportedChains = await lanca.getSupportedChains()

getRouteStatus

Description

Retrieves the status of a route for a given transaction hash.

Parameters

  • txHash : string. The transaction hash of the route

Return Type

  • Promise<ITxStep[] | undefined>

Example

const lancaClient = new LancaClient(config)
const routeStatus = await lanca.getRouteStatus('0x8de5ab492728a8c226b519d061c1b53dfc435aedb3ab2e1c5dfc388a4e9cfdef')

executeRoute

Description

Executes a previously retrieved route using the provided execution configurations.

Parameters

  • route : IRouteType. The route object retrieved from getRoute
  • executionConfigs : ExecutionConfigs. The execution configurations for the swap
    • switchChainHook?: SwitchChainHook. The hook to switch chain
    • updateRouteStatusHook? : UpdateRouteHook. The hook to update route status
    • txLink? : string. The transaction hash link

Return Type

  • Promise<IRouteType | undefined>

Example

const lanca = new LancaSDK(config)
const route = await lanca.getRoute({
    fromChainId: '137',
    toChainId: '8453',
    fromToken: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', //WETH
    toToken: '0x0555E30da8f98308EdB960aa94C0Db47230d2B9c' //WBTC
    amount: '100000'
})
const routeWithStatus = await lanca.executeRoute(route)