@cardano-foundation/cardano-connect-with-wallet-core

中文文档
0.2.12发布于 2026/05/16Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 4051

框架独立的 CIP- 0030 包件功能,可以平稳地构建钱包交互组件

中文使用文档
文档目录10 节
  1. 开始
  2. 国家防范机制一揽子计划
  3. 浏览器导入
  4. 示例使用
  5. 钱包模块
  6. 移动钱包支持
  7. 钱包供应设施
  8. 错误分类
  9. 类型( E)
  10. 捐款

卡多诺与钱包核心连接

Release conventionalcommits Discord

该寄存器旨在为Cardano分散化应用程序(dApps)和钱包(钱包)之间的无缝互动提供框架独立的帮助和包装功能CIP 8 (中文(简体) ) 财务报告和审定财务报表 CIP 30 (简体中文)) (中文(简体) ). 如果您正在寻找 React.js 组件,请继续 此寄存器。 。 。 .

玩得开心点

开始

国家防范机制一揽子计划

npm i @cardano-foundation/cardano-connect-with-wallet-core
import { Wallet } from '@cardano-foundation/cardano-connect-with-wallet-core';

浏览器导入

<script src="https://cardano-foundation.github.io/cardano-connect-with-wallet/bundle-latest/index.js"></script>
<script>
  const wallet = CardanoConnectWithWalletCore.Wallet;
  ...
</script>

示例使用

这个 Wallet 类包含静态帮助函数来简化 dApp 开发. 请检查一下反应钩 使用卡尔德诺 以实例说明如何利用 Wallet 在基于模块的工程中。 从我们这里得到一个静态html、javascript、cs上下文中的用法 基于 html 的钱包按钮。 。 。 .

钱包模块

/*
Register a function to those events:

'enabled',
'connecting',
'enabledWallet',
'stakeAddress',
'usedAddresses',
'unusedAddresses',
'accountBalance',
'connected',
'lastConnectedWallet',
'meerkatAddress',
'installedWalletExtensions'
*/
Wallet.addEventListener: void;
Wallet.removeEventListener: void;

// Starts a background thread to listen for new wallets in the window.cardano object
Wallet.startInjectWalletListener(): void;
Wallet.stopInjectWalletListener(): void;

// Connect or disconnect a wallet by name e.g. 'yoroi', 'eternl', 'flint', etc.
Wallet.connectToWallet(walletName: string, networkType: NetworkType, retries?: number, retryIntervalInMs?: number): Promise<void>;
Wallet.connect(walletName: string, network: NetworkType, onConnect?: () => void | undefined, onError?: (code: Error) => void): Promise<void>;
Wallet.disconnect(): void;

Wallet.checkEnabled(network: NetworkType): Promise<void>;
Wallet.getInstalledWalletExtensions(supportedWallets?: Array<string>): Array<string>;

Wallet.getRewardAddresses(): Promise<any>;

// sign a message
Wallet.signMessage(message: string, onSignMessage?: (signature: string, key: string | undefined) => void, onSignError?: (error: Error) => void, limitNetwork?: NetworkType): Promise<void>;

移动钱包支持

核心包会导出帮助工具,用于移动钱包检测和深层连接.

import {
  checkIsMobile,
  mobileWallets,
  nativeWallets,
  generateCip158DeepLink,
} from '@cardano-foundation/cardano-connect-with-wallet-core';

// true when running on a mobile device (Android / iOS)
const isMobile = checkIsMobile();

// list of wallet names that have a native mobile app
// ['flint', 'eternl', 'vespr', 'begin', 'yoroi']
console.log(mobileWallets);

// per-wallet metadata including app store URLs and CIP-158 support flag
// {
//   eternl: { playStoreUrl, appStoreUrl, walletName, hasCIP158Support: true },
//   vespr:  { playStoreUrl, appStoreUrl, walletName, hasCIP158Support: true },
//   begin:  { playStoreUrl, appStoreUrl, walletName, hasCIP158Support: false },
//   yoroi:  { playStoreUrl, appStoreUrl, walletName, hasCIP158Support: false },
// }
console.log(nativeWallets);

CIP-158 (中文(简体) ) 定义 a web+cardano://browse/v1?uri=<encoded_url> 深链接打开钱包内应用浏览器内的当前dApp页面,让钱包的CIP-30 API直接访问页面.

// Generates the CIP-158 deep link for the given URL (defaults to window.location.href)
const deepLink = generateCip158DeepLink('https://my-dapp.io/swap');
// → 'web+cardano://browse/v1?uri=https%3A%2F%2Fmy-dapp.io%2Fswap'

window.location.href = deepLink;

钱包 hasCIP158Support 旗帜是 true (目前为 永远 财务报告和审定财务报表 维斯普) 由 React 组件自动提供此流后再返回应用商店重定向.

钱包供应设施

import {
  estimateAvailableWallets,
  UnavailableWalletVisibility,
  getWalletIcon,
  isWalletInstalled,
  formatSupportedWallets,
} from '@cardano-foundation/cardano-connect-with-wallet-core';

// Returns the filtered list of wallets to display
const wallets = estimateAvailableWallets(
  ['Eternl', 'Nami', 'Yoroi'],
  UnavailableWalletVisibility.SHOW_UNAVAILABLE_ON_MOBILE, // default
  [], // alwaysVisibleWallets
  installedExtensions,
);

// UnavailableWalletVisibility options:
// HIDE_UNAVAILABLE             – show only installed wallets
// SHOW_UNAVAILABLE             – show all wallets regardless of device
// SHOW_UNAVAILABLE_ON_MOBILE   – show all on mobile, only installed on desktop

// Returns a base64 data-URI icon for the given wallet name
const icon = getWalletIcon('eternl');

// Returns true when window.cardano[walletName] exists
const installed = isWalletInstalled('eternl');

// Returns a human-readable comma-separated list e.g. "Eternl, Nami, Yoroi"
const label = formatSupportedWallets(['Eternl', 'Nami', 'Yoroi']);

错误分类

所有错误都由 Wallet 分类被打入并可以单独捕获:

import {
  WalletConnectError,
  WrongNetworkTypeError,
  WalletNotCip30CompatibleError,
  WalletNotInstalledError,
  WalletExtensionNotFoundError,
  ExtensionNotInjectedError,
  EnablementFailedError,
} from '@cardano-foundation/cardano-connect-with-wallet-core';

try {
  await Wallet.connectToWallet('eternl', NetworkType.MAINNET);
} catch (e) {
  if (e instanceof WrongNetworkTypeError) {
    // wallet is on a different network (e.g. testnet vs mainnet)
  } else if (e instanceof WalletExtensionNotFoundError) {
    // wallet extension / app not available in the browser
  }
}

类型( E)

import {
  NetworkType,           // MAINNET | TESTNET
  UnavailableWalletVisibility,
  Extension,             // { cip: number }
  Cip95Api,             // governance extension (CIP-95)
  Cip103Api,            // bulk transaction signing (CIP-103)
} from '@cardano-foundation/cardano-connect-with-wallet-core';

捐款

请看看我们 提供信息 熟悉我们的准则.

版本与发布记录

@cardano-foundation/cardano-connect-with-wallet-core 共发布 14 个版本,首次发布于 2023/07/07;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.12latest2026/05/165 个月前
0.2.112026/05/066 个月前
0.2.102026/03/257 个月前
0.2.92026/02/278 个月前
0.2.82025/04/251.5 年前
0.2.72025/04/251.5 年前

关于 @cardano-foundation/cardano-connect-with-wallet-core 的常见问题

@cardano-foundation/cardano-connect-with-wallet-core 是什么?

框架独立的 CIP- 0030 包件功能,可以平稳地构建钱包交互组件

如何安装 @cardano-foundation/cardano-connect-with-wallet-core?

在项目目录运行 npm install @cardano-foundation/cardano-connect-with-wallet-core,或使用 pnpm add / yarn add / bun add。

@cardano-foundation/cardano-connect-with-wallet-core 支持 TypeScript 吗?

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

@cardano-foundation/cardano-connect-with-wallet-core 支持 ESM 还是 CommonJS?

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

@cardano-foundation/cardano-connect-with-wallet-core 可以商用吗?

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

@cardano-foundation/cardano-connect-with-wallet-core 的下载量有多少?

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

@cardano-foundation/cardano-connect-with-wallet-core 还在维护吗?

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