# @cardano-foundation/cardano-connect-with-wallet-core 中文文档

规范地址：https://npmcn.com/package/%40cardano-foundation/cardano-connect-with-wallet-core/

版本：0\.2\.12
npm 元数据更新时间：2026-05-16T12:44:24.729Z
中文译文更新时间：2026-11-09T07:30:51.090Z
软件包许可：Apache-2\.0

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

原始 npm 页面：https://www.npmjs.com/package/%40cardano-foundation/cardano-connect-with-wallet-core
原文对照：https://npmcn.com/package/%40cardano-foundation/cardano-connect-with-wallet-core/?lang=original
项目主页：https://github.com/cardano-foundation/cardano-connect-with-wallet#readme
源码仓库：https://github.com/cardano-foundation/cardano-connect-with-wallet

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

- 包体积（解压后）：692 kB，33 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：3 个
- 首次发布：2023-07-06T22:08:10.139Z
- 最新版本发布：2026-05-16T12:44:24.449Z
- 近 30 天下载量：4051（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：14（近 12 个月 4 个）

## 中文简介

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

## 安装

```sh
npm install @cardano-foundation/cardano-connect-with-wallet-core
```

也可以使用：`pnpm add @cardano-foundation/cardano-connect-with-wallet-core`、`yarn add @cardano-foundation/cardano-connect-with-wallet-core`、`bun add @cardano-foundation/cardano-connect-with-wallet-core`

## README

# 卡多诺与钱包核心连接

![Release](https://img.shields.io/github/actions/workflow/status/cardano-foundation/cardano-connect-with-wallet/release.yml?label=Release&style=for-the-badge) [![conventionalcommits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&style=for-the-badge)](https://conventionalcommits.org/) [![Discord](https://img.shields.io/discord/1022471509173882950?style=for-the-badge)](https://discord.gg/4WVNHgQ7bP)

该寄存器旨在为Cardano分散化应用程序(dApps)和钱包(钱包)之间的无缝互动提供框架独立的帮助和包装功能[CIP 8 (中文(简体) )](https://cips.cardano.org/cip/CIP-0008) 财务报告和审定财务报表 [CIP 30 (简体中文)](https://cips.cardano.org/cip/CIP-0030)) (中文(简体) ). 如果您正在寻找 React.js 组件,请继续 [此寄存器](https://github.com/cardano-foundation/cardano-connect-with-wallet/tree/main/react)。 。 。 .

玩得开心点

## 开始

### 国家防范机制一揽子计划

```zsh
npm i @cardano-foundation/cardano-connect-with-wallet-core
```

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

### 浏览器导入

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

### 示例使用

这个 `Wallet` 类包含静态帮助函数来简化 dApp 开发. 请检查一下反应钩 [使用卡尔德诺](https://npmcn.com/package/%40cardano-foundation/react/src/hooks/useCardano.ts) 以实例说明如何利用 `Wallet` 在基于模块的工程中。 从我们这里得到一个静态html、javascript、cs上下文中的用法 [基于 html 的钱包按钮](https://npmcn.com/package/%40cardano-foundation/html/cardano-connect.js)。 。 。 .

### 钱包模块

```ts
/*
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>;
```

### 移动钱包支持

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

```ts
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 深层链接

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

```ts
// 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 组件自动提供此流后再返回应用商店重定向.

### 钱包供应设施

```ts
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` 分类被打入并可以单独捕获:

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

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

## 捐款

请看看我们 [提供信息](https://npmcn.com/package/%40cardano-foundation/CONTRIBUTING.md) 熟悉我们的准则.

## 常见问题

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

