@aptos-labs/gas-station-client

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

Client for the Aptos Gas Station API

原始使用文档
文档目录6 节
  1. Version Management
  2. Installation
  3. Usage
  4. Recommended Usage
  5. Ignoring the Plugin
  6. Direct Usage

Gas Station Client

The Aptos Build gas station client lets you submit transactions to be sponsored by the gas station.

Version Management

This package uses changesets for version management. To make changes:

  1. Make your code changes
  2. Run pnpm changeset in the root directory
  3. Follow the prompts to describe your changes
  4. Commit the generated changeset file along with your changes
  5. When ready to release, run pnpm version-packages to update versions
  6. Run pnpm release to publish the new version

Installation

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

This package contains a client for the Gas Station Admin API. It is primarily intended for use by Aptos Build. That's why we publish this to our private registry.

Usage

The easiest way to use the gas station client is with the TS SDK's plugin interface:

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

From this point you can use the client like normal and it will submit transactions via the gas station instead of the default submitter:

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

To provide a recaptcha token or other plugin parameters:

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

Ignoring the Plugin

You can temporarily bypass the plugin for a single transaction if needed:

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

You can also totally disable / re-enable the plugin like this:

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

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

Direct Usage

If you wish, you can use the client directly:

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

Client for the Aptos Gas Station 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 和提交记录判断。