Lens Crosschain Swap Guide
This is a comprehensive walkthrough for developers looking to implement crosschain token swaps using the Across /swap/approval API on the Lens chain.
Across /swap/approval API provides a streamlined interface for developers to build crosschain swapping applications that easily fit in any development environment and tech stacks.
The ideal Across Crosschain Swap API approach involves setting an allowance and executing the transaction directly via the signer. This is a gasful flow.
The Cross-swap API is currently in beta. We appreciate your participation and kindly request you to report any unexpected behaviors or API response anomalies.
Let's get started!
Understanding the /swap/approval Endpoint
/swap/approval EndpointIn the /swap/approval endpoint crosschain swap flow, consumers of the API need to make sure that the depositor has granted sufficient allowance to the respective contract of the Across Protocol.
The API returns data that can be used to:
check current and expected allowance
check current and expected balance
executable approval transaction(s)
executable swap transaction
swap quote
API Endpoint
GET https://app.across.to/api/swap/approval
Basic Execution
Returns data required to execute a cross-chain swap.
If the input token requires approval, approvalTxns will be included in the response.
Type of trade. Use minOutput, exactInput or exactOutput.
exactInputPossible values: Required amount of output token in smallest unit.
1000000Address of the input token on the origin chain.
0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85Address of the output token on the destination chain.
0x82aF49447D8a07e3bd95BD0d56f35241523fBab1Chain ID of the origin chain.
1Chain ID of the destination chain.
232Address of the depositor initiating the swap.
0xDEPOSITOR_ADDRESSAddress of the account receiving the output token.
0xRECIPIENT_ADDRESS2-byte hex-string that identifies the integrator. E.g., "0xdead".
0xdeadAddress to receive refunds. Defaults to depositor if not provided.
0xDEPOSITOR_ADDRESSSpecifies whether refund should be sent on the origin chain. Defaults to true.
trueSlippage tolerance percentage (e.g., 1 for 1%, 0.5 for 0.5%).
1Swap approval data returned successfully.
Bad request due to invalid input parameter.
Quickstart Code Snippets
Important fields to note here are:
tradeType: Defines the type of trade for eg -minOutput.amount: Specifies amount ofinputTokenin the smallest unit (wei for ETH or 6 decimals for USDC).inputToken: Address of the token being swapped.originChainId: Chain ID of the source/origin chain (232 for Lens Chain mainnet).outputToken: Address of the token to be received after the swap.destinationChainId: Chain ID of the destination chain where the output token will be delivered.depositor: The address of the sender (usually the wallet initiating the swap).
Upon successful execution of the /swap/approval endpoint, the return data should be something like this:
With the above response from the /swap/approval endpoint, you can proceed to sign transaction on the wallet client.
Lens Use Cases using /swap/approval Endpoint
/swap/approval Endpoint1. Bridge ETH on Ethereum Mainnet to ETH on Lens Chain
Key Parameters:
tradeType: Defines the type of trade for eg -minOutput.amount: Specifies amount ofinputTokenin the smalled unit (wei for ETH or 6 decimals for USDC).inputToken: Address of the token being swapped.originChainId: Chain ID of the source/origin chain (232 for lens chain mainnet).outputToken: Address of the token to be received after the swap.destinationChainId: Chain ID of the destination chain where the output token will be delivered.depositor: The address of the sender (usually the wallet initiating the swap).
2. Bridge GHO from Ethereum Mainnet to GHO on Lens Chain
Key Parameters:
tradeType: Use"minOutput"to ensure a minimum amount after the swap.inputToken: Address of ETH or USDC on the origin chain. (Note: USDC contains 6 decimal places)originChainId: Chain ID of the origin chain.outputToken: Corresponding token address on Lens.destinationChainId: Chain ID of Lens.
3. Swap USDC on Ethereum Mainnet to GHO on Lens Chain
Key Parameters:
inputToken: Address of USDC on Ethereum Mainnet.outputToken: Address of GHO on Lens.
With this, you have now completely understood the core principles of using the /swap/approval endpoint and walked through certain examples that enable you to swap and bridge tokens to build custom use cases on Lens Chain.
If you have any doubts, please feel free to reach out to us here.
Last updated