@aptos-labs/wallet-adapter-core

中文文档
8.5.1发布于 2026/03/28Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 5.7万

Aptos Wallet Adapter Core

原始使用文档
文档目录14 节
  1. Overview
  2. Installation
  3. Usage
  4. Basic Setup
  5. Connecting to a Wallet
  6. Signing Messages
  7. Signing and Submitting Transactions
  8. Listening to Events
  9. Disconnecting
  10. API Reference
  11. WalletCore
  12. DappConfig
  13. Related Packages
  14. License

@aptos-labs/wallet-adapter-core

Core functionality for the Aptos Wallet Adapter. This package provides the foundation for wallet management, state handling, and interaction with AIP-62 compatible wallets on the Aptos blockchain.

Overview

The wallet-adapter-core package handles:

  • Wallet Detection: Automatically detects AIP-62 standard compatible wallets installed in the browser
  • Connection Management: Connect, disconnect, and manage wallet sessions
  • Transaction Signing: Sign messages, transactions, and submit transactions to the network
  • Network Management: Handle network changes and multi-network support
  • Event System: Subscribe to wallet, account, and network change events
  • State Management: Centralized state for connected wallet, account, and network information

Installation

npm install @aptos-labs/wallet-adapter-core
# or
pnpm add @aptos-labs/wallet-adapter-core
# or
yarn add @aptos-labs/wallet-adapter-core

Peer Dependencies:

npm install @aptos-labs/ts-sdk

Usage

Basic Setup

import { WalletCore } from "@aptos-labs/wallet-adapter-core";
import { Network } from "@aptos-labs/ts-sdk";

// Create wallet core instance
const walletCore = new WalletCore(
  [], // Optional: array of wallet names to opt-in (empty = all wallets)
  { network: Network.MAINNET }, // Optional: dapp configuration
  false, // Optional: disable telemetry (default: false)
  ["Petra Web"] // Optional: wallets to hide from display
);

// Get available wallets
const wallets = walletCore.wallets;
const notDetectedWallets = walletCore.notDetectedWallets;

Connecting to a Wallet

// Connect to a wallet by name
await walletCore.connect("Petra");

// Check connection status
if (walletCore.isConnected()) {
  console.log("Connected account:", walletCore.account);
  console.log("Connected network:", walletCore.network);
}

Signing Messages

const signedMessage = await walletCore.signMessage({
  message: "Hello, Aptos!",
  nonce: "random-nonce-123",
});

console.log("Signature:", signedMessage.signature);
console.log("Full message:", signedMessage.fullMessage);

Signing and Submitting Transactions

const result = await walletCore.signAndSubmitTransaction({
  data: {
    function: "0x1::aptos_account::transfer",
    typeArguments: [],
    functionArguments: [recipientAddress, amount],
  },
});

console.log("Transaction hash:", result.hash);

Listening to Events

// Account change event
walletCore.on("accountChange", (account) => {
  console.log("Account changed:", account);
});

// Network change event
walletCore.on("networkChange", (network) => {
  console.log("Network changed:", network);
});

// Disconnect event
walletCore.on("disconnect", () => {
  console.log("Wallet disconnected");
});

Disconnecting

await walletCore.disconnect();

API Reference

WalletCore

The main class that manages wallet state and interactions.

Constructor

new WalletCore(
  optInWallets?: ReadonlyArray<AvailableWallets>,
  dappConfig?: DappConfig,
  disableTelemetry?: boolean,
  hideWallets?: ReadonlyArray<AvailableWallets>
)

Properties

PropertyTypeDescription
walletAptosWallet | nullCurrently connected wallet
accountAccountInfo | nullCurrently connected account
networkNetworkInfo | nullCurrently connected network
walletsReadonlyArray<AptosWallet>List of detected wallets
hiddenWalletsReadonlyArray<AdapterWallet>List of hidden wallets
notDetectedWalletsReadonlyArray<AdapterNotDetectedWallet>List of not-detected wallets

Methods

MethodDescription
connect(walletName)Connect to a wallet
disconnect()Disconnect from current wallet
signMessage(input)Sign a message
signTransaction(args)Sign a transaction
signAndSubmitTransaction(input)Sign and submit a transaction
changeNetwork(network)Request network change
signIn(args)Sign in with SIWA (Sign In With Aptos)
isConnected()Check if wallet is connected

Events

EventPayloadDescription
connectAccountInfoEmitted when wallet connects
disconnect-Emitted when wallet disconnects
accountChangeAccountInfoEmitted when account changes
networkChangeNetworkInfoEmitted when network changes

DappConfig

Configuration options for the wallet adapter:

interface DappConfig {
  network: Network;
  transactionSubmitter?: TransactionSubmitter;
  aptosApiKeys?: Partial<Record<Network, string>>;
  aptosConnectDappId?: string;
  aptosConnect?: AptosConnectWalletConfig;
  crossChainWallets?: boolean;
}

License

Apache-2.0

版本与发布记录

@aptos-labs/wallet-adapter-core 共发布 164 个版本,首次发布于 2022/12/07;过去 12 个月发布了 28 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.5.1latest2026/03/287 个月前
8.5.02026/03/107 个月前
8.4.02026/02/198 个月前
8.3.02026/02/148 个月前
8.2.02026/01/279 个月前
8.2.0-alpha.42026/01/239 个月前

其他发布通道:aip-62 → 0.0.0-aip-62-20240327155833,ga → 0.0.0-ga-20240405173226,xchaininit → 8.0.0-xchaininit.0,xchaininit2 → 8.0.0-xchaininit2.0,xchaininit3 → 7.10.3-xchaininit3.3,xchaininit4 → 7.10.3-xchaininit4.2。

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

@aptos-labs/wallet-adapter-core 是什么?

Aptos Wallet Adapter Core

如何安装 @aptos-labs/wallet-adapter-core?

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

@aptos-labs/wallet-adapter-core 支持 TypeScript 吗?

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

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

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

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

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

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

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

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

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