@across-protocol/app-sdk

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

官方的SDK将"跨桥"并入了你的DAP.

中文使用文档
文档目录23 节
  1. 安装
  2. 快速启动
  3. 1. 设立 AcrossClient
  4. 2. 获取引文
  5. 3. 执行引文
  6. 跨链条处理
  7. 示例:在目标链上取取原生ETH
  8. 认证
  9. 客户端级 API 密钥
  10. 按请求 API 密钥
  11. 交存详情
  12. 处理和调试出错
  13. 路线、链条和标志细节
  14. AcrossClient
  15. 设置
  16. 链和路线
  17. 引用、收费和限制
  18. 交易模拟和执行
  19. 交存和填充状况
  20. 通过招标调试
  21. 公用事业
  22. 集成器标签
  23. 跨链条消息

across logo

建在顶部的脚本软件包 整个协议

Version MIT License


开始

这个 @across-protocol/app-sdk cross' Smart Contracts 和 Quotes API 上提供了有用的抽象.

学习更多参观我们 文档。 。 。 .

安装

要启动, 请安装 app sdk 及其对等依赖 维姆。 。 。 .

pnpm i @across-protocol/app-sdk viem

快速启动

1. 设立 AcrossClient

首先,你需要设置 AcrossClient 并配置要支持的链条.

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. 获取引文

现在,你可以用任意的一对符号来检索给定路线的引文.

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
});

请注意,我们提供额外的公用设施,以检索现有的路线、链条细节和信使信息. 见 这里。 。 。 .

3. 执行引文

检索到引文后,你准备执行.

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
    }
  },
});

该方法将执行引文来源:

  1. 核准 SpokePool 或者说 SpokePoolPeriphery 如有必要,合同
  2. 在原产地链上交存输入令牌(必要时还便利原产地互换)
  3. 等待在目的地链上填充押金

你可以用这个 onProgress 调回执行的不同阶段. 看看我们 示例应用程序 更详细地使用这种方法.

跨链条处理

交叉使用户能够利用来自其他链条的资产与您的 dApp 或链条进行无缝互动.

示例:在目标链上取取原生ETH

这个例子说明如何使用应用软件sdk 交换,搭桥和置入 本地的ETH 跨越链条. 您只需要指定目的地链动作 .

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
  },
});

认证

一些横跨API的特性需要通过API密钥进行认证. 你可以提供 键.

客户端级 API 密钥

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 });

按请求 API 密钥

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

密钥作为 Bearer 符号在 Authorization 头曰.

交存详情

开始

处理和调试出错

开始

路线、链条和标志细节

开始

@across-protocol/app-sdk 参考文献

详细情况见 这里。 。 。 .

AcrossClient

设置

链和路线

引用、收费和限制

交易模拟和执行

交存和填充状况

通过招标调试

公用事业

集成器标签

跨链条消息

版本与发布记录

@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 是什么?

官方的SDK将"跨桥"并入了你的DAP.

如何安装 @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 和提交记录判断。