# @aptos-labs/gas-station-client 中文文档

规范地址：https://npmcn.com/package/%40aptos-labs/gas-station-client/

版本：2\.0\.3
npm 元数据更新时间：2025-09-16T16:55:18.496Z
中文译文更新时间：2026-11-06T13:02:52.875Z
软件包许可：未声明

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40aptos-labs/gas-station-client
原文对照：https://npmcn.com/package/%40aptos-labs/gas-station-client/?lang=original

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：101 kB，47 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2025-04-03T16:09:11.155Z
- 最新版本发布：2025-09-16T16:55:18.343Z
- 近 30 天下载量：33639（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 0 个）

## 中文简介

Aptos 加油站 API 客户端

## 安装

```sh
npm install @aptos-labs/gas-station-client
```

也可以使用：`pnpm add @aptos-labs/gas-station-client`、`yarn add @aptos-labs/gas-station-client`、`bun add @aptos-labs/gas-station-client`

## README

# 加油站客户端

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

## 版本管理

此软件包使用 [变化](https://github.com/changesets/changesets) 用于版本管理。 要作出修改:

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的插件接口:

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

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

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

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

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

### 忽略插件

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

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

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

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

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

### 直接使用

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

```ts
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 是什么？

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 和提交记录判断。

