@aptos-labs/gas-station-client

中文文档
2.0.3发布于 2025/09/17TypeScriptCommonJS近 30 天下载 3.4万

Aptos 加油站 API 客户端

中文使用文档
文档目录6 节
  1. 版本管理
  2. 安装
  3. 使用量
  4. 建议使用
  5. 忽略插件
  6. 直接使用

加油站客户端

Aptos Build加油站客户端允许您提交交易由加油站担保.

版本管理

此软件包使用 变化 用于版本管理。 要作出修改:

  1. 更改代码
  2. 运行 pnpm changeset 在根目录中
  3. 遵循提示来描述您的更改
  4. 随您的更改一起提交生成的更改et文件
  5. 准备释放时,快跑 pnpm version-packages 以更新版本
  6. 运行 pnpm release 以发布新版本

安装

pnpm install @aptos-labs/gas-station-client

这个软件包包含了一个加油站管理员API的客户端. 它主要供Aptos Build使用。 这就是为什么我们公布 这到我们的私人注册.

使用量

使用加油站客户端的最简单方法是使用TS SDK的插件接口:

const network = Network.MAINNET;
const gasStationClient = new GasStationTransactionSubmitter({
  network,
  apiKey: "aptoslabs_21edbqbxyPrS_6fu9i83mYmjid4MVs3Z3XmCeATQ8tkSdd",
});
const config = new AptosConfig({
  network,
  pluginSettings: {
    TRANSACTION_SUBMITTER: gasStationClient,
  },
});
const aptos = new Aptos(config);

从此您可以像正常一样使用客户端, 它会通过加油站而不是默认的提交者提交交易 :

const transaction = await aptos.transaction.build.simple({
  sender: senderAccount.accountAddress,
  // IMPORTANT: Must set withFeePayer: true for gas station transactions.
  withFeePayer: true,
  data: {
    function: "0x1::aptos_account::transfer",
    functionArguments: [receiverAccount.accountAddress.toString(), 100],
  },
});

const response = await aptos.signAndSubmitTransaction({
  signer: senderAccount,
  transaction,
});

要提供复刻符号或其他插件参数:

const response = await aptos.signAndSubmitTransaction({
  signer: senderAccount,
  transaction,
  pluginParams: {
    recaptchaToken: "your-recaptcha-token",
  },
});

忽略插件

如果需要,您可以暂时绕过插件进行单一交易:

const response = await aptos.signAndSubmitTransaction({
  signer: senderAccount,
  transaction,
  // Set this to null to ignore the plugin.
  transactionSubmitter: null,
});

您也可以完全禁用/ 重新启用这样的插件 :

aptos.setIgnoreTransactionSubmitter(true);
// Transactions will now go through normal submission (not gas station)

aptos.setIgnoreTransactionSubmitter(false);
// Re-enable the plugin

直接使用

如果您愿意, 您可以直接使用客户端 :

const network = Network.MAINNET;
const config = new AptosConfig({network});
const aptos = new Aptos(config);

// Create the client.
const client = new GasStationClient({
  network,
  apiKey: "aptoslabs_21edbqbxyPrS_6fu9i83mYmjid4MVs3Z3XmCeATQ8tkSdd",
});

// Build the transaction.
const transaction = await aptos.transaction.build.simple({
  sender: alice.accountAddress,
  // Make sure that this is set to true.
  withFeePayer: true,
  data: {
    function: "0x1::aptos_account::transfer",
    functionArguments: [bob.accountAddress.toString(), 100],
  },
});

// Sign it and get an authenticator.
const senderAuthenticator = aptos.transaction.sign({ signer: alice, transaction });

// Submit it to the gas station.
const { transactionHash } = await client.signAndSubmitTransaction({
  transaction,
  senderAuthenticator,
});

// Wait for the transaction to be executed.
const executedTransaction = await aptos.waitForTransaction({
  transactionHash,
  options: { checkSuccess: true },
});
console.log("Transaction executed successfully", executedTransaction.hash);

版本与发布记录

@aptos-labs/gas-station-client 共发布 7 个版本,首次发布于 2025/04/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.3latest2025/09/171.1 年前
2.0.22025/07/041.3 年前
2.0.12025/07/021.3 年前
2.0.02025/07/021.3 年前
1.1.12025/06/291.4 年前
1.1.02025/06/271.4 年前

关于 @aptos-labs/gas-station-client 的常见问题

@aptos-labs/gas-station-client 是什么?

Aptos 加油站 API 客户端

如何安装 @aptos-labs/gas-station-client?

在项目目录运行 npm install @aptos-labs/gas-station-client,或使用 pnpm add / yarn add / bun add。

@aptos-labs/gas-station-client 支持 TypeScript 吗?

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

@aptos-labs/gas-station-client 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@aptos-labs/gas-station-client 可以商用吗?

@aptos-labs/gas-station-client 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@aptos-labs/gas-station-client 的下载量有多少?

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

@aptos-labs/gas-station-client 还在维护吗?

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