@aptos-labs/wallet-standard

中文文档
2.0.0发布于 2026/05/29Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 12.6万

Aptos wallet standard

原始使用文档
文档目录17 节
  1. Installation
  2. Peer Dependencies
  3. For Dapp Developers
  4. Detecting Wallets
  5. Checking for Optional Features
  6. For Wallet Developers
  7. 1. Implement the Wallet Interface
  8. 2. Register the Wallet
  9. API Reference
  10. Interfaces
  11. Required Features
  12. Optional Features
  13. Chains
  14. Error Handling
  15. User Responses
  16. Development
  17. License

Aptos Wallet Standard

npm version npm downloads CI codecov License

The Aptos Wallet Standard defines TypeScript interfaces and utilities for wallet and dapp interactions in the Aptos ecosystem. It implements AIP-62, providing a consistent way for wallets to integrate with applications.

Built on top of the chain-agnostic Wallet Standard, this library extends it with Aptos-specific features like transaction signing, network management, and account handling.

Installation

# npm
npm install @aptos-labs/wallet-standard

# pnpm
pnpm add @aptos-labs/wallet-standard

Peer Dependencies

This package requires the following peer dependencies:

For Dapp Developers

Detecting Wallets

Use getAptosWallets() to discover all registered Aptos-compatible wallets. This function filters for wallets that implement the required feature set.

import { getAptosWallets } from "@aptos-labs/wallet-standard";

const { aptosWallets, on } = getAptosWallets();

// Use currently registered wallets
console.log("Available wallets:", aptosWallets);

// Listen for new wallets that register after page load
const removeListener = on("register", (wallet) => {
  console.log("New wallet registered:", wallet);
});

Checking for Optional Features

Use isWalletWithRequiredFeatureSet() to check if a wallet supports additional features beyond the required set:

import { isWalletWithRequiredFeatureSet } from "@aptos-labs/wallet-standard";
import type { AptosSignAndSubmitTransactionFeature } from "@aptos-labs/wallet-standard";

if (
  isWalletWithRequiredFeatureSet<AptosSignAndSubmitTransactionFeature>(wallet, [
    "aptos:signAndSubmitTransaction",
  ])
) {
  // Wallet supports sign-and-submit
}

For Wallet Developers

To make your wallet compatible with the Aptos Wallet Standard, implement the AptosWallet interface and register it using registerWallet from @wallet-standard/core.

1. Implement the Wallet Interface

import { APTOS_CHAINS } from "@aptos-labs/wallet-standard";
import type { AptosWallet, AptosFeatures } from "@aptos-labs/wallet-standard";

class MyWallet implements AptosWallet {
  readonly name = "My Wallet";
  readonly url = "https://mywallet.com";
  readonly version = "1.0.0";
  readonly icon = "data:image/png;base64,...";
  readonly chains = APTOS_CHAINS;
  accounts = [];

  get features(): AptosFeatures {
    return {
      "aptos:connect": { version: "1.0.0", connect: this.connect },
      "aptos:disconnect": { version: "1.0.0", disconnect: this.disconnect },
      "aptos:account": { version: "1.0.0", account: this.account },
      "aptos:network": { version: "1.0.0", network: this.network },
      "aptos:signTransaction": {
        version: "1.0.0",
        signTransaction: this.signTransaction,
      },
      "aptos:signMessage": {
        version: "1.0.0",
        signMessage: this.signMessage,
      },
      "aptos:onAccountChange": {
        version: "1.0.0",
        onAccountChange: this.onAccountChange,
      },
      "aptos:onNetworkChange": {
        version: "1.0.0",
        onNetworkChange: this.onNetworkChange,
      },
    };
  }

  // ... implement each feature method
}

2. Register the Wallet

For browser extension wallets, call registerWallet when the page loads:

import { registerWallet } from "@aptos-labs/wallet-standard";

const myWallet = new MyWallet();
registerWallet(myWallet);

See the full example wallet implementation for a complete template with detailed guidance.

API Reference

Interfaces

InterfaceDescription
AptosWalletMain wallet interface extending WalletWithAptosFeatures with a url property
AptosWalletAccountAccount interface extending WalletAccount with a signingScheme field
AccountInfoSerializable account info class with address, publicKey, and optional ansName
NetworkInfoNetwork details including name, chainId, and optional url

Required Features

All Aptos wallets must implement these features:

FeatureDescription
aptos:connectConnect a user's account to the dapp
aptos:disconnectDisconnect the account from the dapp
aptos:accountGet the currently connected account info
aptos:networkGet the current network the wallet is connected to
aptos:signTransactionSign a transaction without submitting
aptos:signMessageSign an arbitrary message
aptos:onAccountChangeListen for account change events
aptos:onNetworkChangeListen for network change events

Optional Features

FeatureDescription
aptos:signAndSubmitTransactionSign and submit a transaction in one step
aptos:changeNetworkRequest the wallet to switch networks
aptos:openInMobileAppOpen the wallet's mobile app
aptos:signInSign in with the wallet

Chains

Pre-defined chain identifiers:

import {
  APTOS_MAINNET_CHAIN, // "aptos:mainnet"
  APTOS_TESTNET_CHAIN, // "aptos:testnet"
  APTOS_DEVNET_CHAIN, // "aptos:devnet"
  APTOS_LOCALNET_CHAIN, // "aptos:localnet"
  APTOS_CHAINS, // All of the above
} from "@aptos-labs/wallet-standard";

Error Handling

The library provides structured errors via AptosWalletError:

import {
  AptosWalletError,
  AptosWalletErrorCode,
} from "@aptos-labs/wallet-standard";

// Error codes:
// 4100 - Unauthorized: method/account not authorized by the user
// 4200 - Unsupported: requested feature is not supported
// -30001 - InternalError: something went wrong within the wallet

User Responses

Methods that prompt the user for approval return a UserResponse<T>, a discriminated union that lets the wallet signal either approval (with a result) or rejection. The following features use this shape:

  • aptos:connect
  • aptos:signTransaction
  • aptos:signAndSubmitTransaction
  • aptos:signMessage
  • aptos:signIn
  • aptos:changeNetwork

Other required features return their value directly (still asynchronously): aptos:account returns Promise<AccountInfo>, aptos:network returns Promise<NetworkInfo>, aptos:disconnect returns Promise<void>, and the onAccountChange / onNetworkChange features register subscriptions.

import { UserResponseStatus } from "@aptos-labs/wallet-standard";

const response = await wallet.features["aptos:connect"].connect();

if (response.status === UserResponseStatus.APPROVED) {
  console.log("Connected:", response.args); // AccountInfo
} else {
  console.log("User rejected the connection");
}

Development

# Install dependencies
pnpm install

# Build
pnpm build

# Lint
pnpm lint

# Format
pnpm format

License

Apache-2.0

版本与发布记录

@aptos-labs/wallet-standard 共发布 24 个版本,首次发布于 2024/02/06;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.0latest2026/05/295 个月前
1.0.02026/03/137 个月前
0.5.22025/09/161.1 年前
0.5.12025/07/221.3 年前
0.5.02025/05/281.4 年前
0.4.02025/05/071.5 年前

其他发布通道:multisig → 0.1.0-ms.1。

关于 @aptos-labs/wallet-standard 的常见问题

@aptos-labs/wallet-standard 是什么?

Aptos wallet standard

如何安装 @aptos-labs/wallet-standard?

在项目目录运行 npm install @aptos-labs/wallet-standard,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@aptos-labs/ts-sdk(^7.1.0)、@wallet-standard/core(^1.0.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aptos-labs/wallet-standard 支持 TypeScript 吗?

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

@aptos-labs/wallet-standard 支持 ESM 还是 CommonJS?

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

@aptos-labs/wallet-standard 需要什么版本的 Node.js?

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

@aptos-labs/wallet-standard 可以商用吗?

@aptos-labs/wallet-standard 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aptos-labs/wallet-standard 的下载量有多少?

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

@aptos-labs/wallet-standard 还在维护吗?

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