@across-protocol/app-sdk

中文文档
0.6.1发布于 2026/06/10MITTypeScriptES Module近 30 天下载 2.5万

The official SDK for integrating Across bridge into your dapp.

原始使用文档
文档目录23 节
  1. Installation
  2. Quick Start
  3. 1. Set up the AcrossClient
  4. 2. Retrieve a quote
  5. 3. Execute a quote
  6. Cross-chain message handling
  7. Example: Stake Native ETH on Destination Chain
  8. Authentication
  9. Client-level API key
  10. Per-request API key
  11. Deposit details
  12. Error handling and debugging
  13. Route, chain and token details
  14. AcrossClient
  15. Set Up
  16. Chains and Routes
  17. Quotes, Fees and Limits
  18. Transaction Simulations and Executions
  19. Deposit and Fill Status
  20. Debugging via Tenderly
  21. Utilities
  22. Integrator tag
  23. Cross-chain message

across logo

TypeScript package for building on top of the Across Protocol

Version MIT License


Getting Started

The @across-protocol/app-sdk provides useful abstractions on top of Across' Smart Contracts and Quotes API.

To learn more visit our docs.

Installation

To get started, install the app sdk and its peer dependency viem.

pnpm i @across-protocol/app-sdk viem

Quick Start

1. Set up the AcrossClient

Firstly, you need to set up the AcrossClient and configure the chains you want to support.

import { createAcrossClient } from "@across-protocol/app-sdk";
import { mainnet, optimism, arbitrum } from "viem/chains";

const client = createAcrossClient({
  integratorId: "0xdead", // 2-byte hex string
  chains: [mainnet, optimism, arbitrum],
});

2. Retrieve a quote

Now, you can retrieve a quote for a given route with an arbitrary token pair.

import { parseEther } from "viem";

// USDC from Arbitrum -> ETH on Optimism
const route = {
  originChainId: arbitrum.id,
  destinationChainId: optimism.id,
  inputToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC
  outputToken: "0x0000000000000000000000000000000000000000", // Native ETH
};

const swapQuote = await client.getSwapQuote({
  route,
  amount: parseUnit("10", 6), // USDC decimals
});

Note that we provide additional utilities for retrieving available routes, chain details, and token infos. See here.

3. Execute a quote

After retrieving a quote, you are ready to execute it.

import { useWalletClient } from "wagmi";

const wallet = useWalletClient();

await client.executeSwapQuote({
  walletClient: wallet,
  swapQuote, // returned by `client.getSwapQuote`
  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
    }
  },
});

The method will execute a quote by:

  1. Approving the SpokePool or SpokePoolPeriphery contract if necessary
  2. Depositing the input token on the origin chain (also facilitating an origin swap if necessary)
  3. Waiting for the deposit to be filled on the destination chain

You can use the onProgress callback to act on different stages of the execution. Have a look at our example app for a more detailed usage of this method.

Cross-chain message handling

Across enables users to seamlessly interact with your dApp or chain using assets from other chains.

Example: Stake Native ETH on Destination Chain

This example shows you how to use the app-sdk to swap, bridge and stake native ETH across chains. You only need to specify the destination chain actions.

import { createAcrossClient } from "@across-protocol/app-sdk";
import { mainnet, optimism, arbitrum } from "viem/chains";
import { useWalletClient } from "wagmi";

const wallet = useWalletClient();

// Example Staking contract on OP
const stakingAddress = "0x733Debf51574c70CfCdb7918F032E16F686bd9f8";

// 1. Create client
const client = createAcrossClient({
  integratorId: "0xdead", // 2-byte hex string
  chains: [mainnet, optimism, arbitrum],
});

// 2. Retrieve quote for USDC from Arbitrum -> ETH on Optimism
const route = {
  originChainId: arbitrum.id,
  destinationChainId: optimism.id,
  inputToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC
  outputToken: "0x0000000000000000000000000000000000000000", // Native ETH
};
const swapQuote = await client.getSwapQuote({
  route,
  amount: parseUnit("10", 6), // USDC decimals
  actions: [
    {
      // Target contract of destination chain actions
      target: stakingAddress,
      // Human-readable ABI format of method to call
      functionSignature: "function stake(address stakerAddress)",
      // Args to above
      args: [{ value: wallet.address }],
      // Allows to set call value to available balance AFTER bridge
      populateCallValueDynamically: true,
    },
  ],
});

// 3. Execute quote
await client.executeSwapQuote({
  walletClient: wallet,
  swapQuote,
  onProgress: (progress) => {
    // handle progress
  },
});

Authentication

Some Across API features require authentication via an API key. You can provide the key at the client level or per-request.

Client-level API key

const client = createAcrossClient({
  integratorId: "0xdead",
  chains: [mainnet, optimism, arbitrum],
  apiKey: "your-api-key",
});

// All authenticated requests will use this key automatically
const quote = await client.getSwapQuote({ route, amount });

Per-request API key

// Override or provide the key for a single request
const quote = await client.getSwapQuote({
  route,
  amount,
  apiKey: "per-request-key",
});

The key is sent as a Bearer token in the Authorization header.

Deposit details

TODO

Error handling and debugging

TODO

Route, chain and token details

TODO

@across-protocol/app-sdk Reference

For the full detailed reference see here.

AcrossClient

Set Up

Chains and Routes

Quotes, Fees and Limits

Transaction Simulations and Executions

Deposit and Fill Status

Debugging via Tenderly

Utilities

Integrator tag

Cross-chain message

版本与发布记录

@across-protocol/app-sdk 共发布 18 个版本,首次发布于 2024/10/04;过去 12 个月发布了 4 个版本。

版本发布日期距今
0.6.1latest2026/06/104 个月前
0.6.02026/04/276 个月前
0.5.02026/02/268 个月前
0.4.42025/11/1111 个月前
0.4.32025/10/211 年前
0.4.22025/09/271.1 年前

关于 @across-protocol/app-sdk 的常见问题

@across-protocol/app-sdk 是什么?

The official SDK for integrating Across bridge into your dapp.

如何安装 @across-protocol/app-sdk?

在项目目录运行 npm install @across-protocol/app-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:viem(^2.31.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@across-protocol/app-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@across-protocol/app-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@across-protocol/app-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@across-protocol/app-sdk 可以商用吗?

@across-protocol/app-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@across-protocol/app-sdk 的下载量有多少?

根据 npm 官方下载统计,@across-protocol/app-sdk 在 2026/10/05 – 2026/11/03 这 30 天内被下载 25,066 次,日均约 836 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@across-protocol/app-sdk 还在维护吗?

最新版本 0.6.1 发布于 2026/06/10(4 个月前);至今共发布 18 个版本,其中过去 12 个月发布了 4 个;首次发布于 2024/10/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。