Across
Across is an interoperability protocol powered by intents, enabling a fast and low-cost way to transfer value between chains.
The process for intent-based bridging with Across:
Users deposit tokens on the origin chain
Relayer views this deposit and fulfills the order on the destination chain
Relay submits a proof of the relay and deposit to optimisitc oracle and claims reimbursement
Across bridging can be accessed via Mainnet Bridge UI, Testnet Bridge UI, or onchain transactions constructed via Across SDK or Across API.
Across SDK
The Across SDK enables developers to interact with the protocol in JavaScript applications. This guide will walkthrough exeucting an example bridge transaction. More details on available SDK methods can be found on GitHub.
Initialize AcrossClient and configure the chains you want to support.
import { chains } from "@lens-chain/sdk/viem";import { createAcrossClient } from "@across-protocol/app-sdk";import { sepolia } from "viem/chains";
const client = createAcrossClient({ integratorId: "0xdead", // 2-byte hex string chains: [chains.testnet, sepolia], useTestnet: true,});
Get available routes based on network and/or token address parameters.
// available params: originToken, destinationToken, destinationChainId, originChainId, originTokenSymbol, destinationTokenSymbolconst options = { originChainId: 37111 };const routes = await client.getAvailableRoutes(options);
Get price and fee estimate for requested route.
import { parseEther } from "viem";
// Bridge 1 WGRASS from Lens Sepolia to ETH Sepoliaconst route = { originChainId: chains.testnet.id, destinationChainId: sepolia.id, inputToken: "0xeee5a340Cdc9c179Db25dea45AcfD5FE8d4d3eB8", // WGRASS Lens Sepolia Testnet outputToken: "0x2Be68B15c693D3b5747F9F0D49D30A2E81BAA2Df", // WGRASS Ethereum Sepolia Testnet};
const quote = await client.getQuote({ route, inputAmount: parseEther("1"),});
Execute deposit transaction for generated quote. To generate transaction manually (for simulations, debugging, etc.), see here.
import { parseEther, http, createWalletClient } from "viem";import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount("PRIVATE_KEY");
const walletClient = createWalletClient({ account, chain: chains.testnet, transport: http(),});
await client.executeQuote({ walletClient, deposit: quote.deposit, onProgress: (progress) => { if (progress.step === "approve" && progress.status === "txSuccess") { // if approving an ERC20, you have access to the approval receipt const {txReceipt} = progress; } if (progress.step === "deposit" && progress.status === "txSuccess") { // once deposit is successful you have access to depositId and the receipt const {depositId, txReceipt} = progress; } if (progress.step === "fill" && progress.status === "txSuccess") { // if the fill is successful, you have access the following data const {fillTxTimestamp, txReceipt, actionSuccess} = progress; // actionSuccess is a boolean flag, telling us if your cross chain messages were successful } },});
Simulate Deposit Transaction Data
import { parseEther, http, createWalletClient } from "viem";import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount("PRIVATE_KEY");
const walletClient = createWalletClient({ account, chain: chains.testnet, transport: http(),});
const {request} = await client.simulateDepositTx({ walletClient, deposit: quote.deposit,});
// `request` is viem Transaction which can be simulated with tools such as Tenderly or executed onchain with `walletClient.writeContract(request)`, though it is recommended to execute using "Execute Quote" method above for monitoring callbacks
Across API
The Across API enables developers to query data for Across bridge interactions. Available methods are listed below:
Available Routes
A complete list of routes can be queried using the SDK or API. Common routes are listed below: