# @cheqd/sdk 中文文档

规范地址：https://npmcn.com/package/%40cheqd/sdk/

版本：5\.5\.1
npm 元数据更新时间：2026-06-17T23:13:58.064Z
中文译文更新时间：2026-11-09T12:28:39.678Z
软件包许可：Apache-2\.0

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

原始 npm 页面：https://www.npmjs.com/package/%40cheqd/sdk
原文对照：https://npmcn.com/package/%40cheqd/sdk/?lang=original
项目主页：https://github.com/cheqd/sdk#readme
源码仓库：https://github.com/cheqd/sdk

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

- 包体积（解压后）：1.5 MB，127 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=22\.0\.0
- 运行依赖：41 个
- 首次发布：2022-07-28T12:29:17.067Z
- 最新版本发布：2026-06-17T23:13:57.887Z
- 近 30 天下载量：2850（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：238（近 12 个月 29 个）

## 中文简介

使用 CosmJS 构建的 SDK 类型Script 与 cheqd 网络分类账交互

## 安装

```sh
npm install @cheqd/sdk
```

也可以使用：`pnpm add @cheqd/sdk`、`yarn add @cheqd/sdk`、`bun add @cheqd/sdk`

## README

# Cheqd 的脚本 SDK 类型

[![GitHub release (latest by date)](https://img.shields.io/github/v/release/cheqd/sdk?color=green&label=stable%20release&style=flat-square)](https://github.com/cheqd/sdk/releases/latest) ![GitHub Release Date](https://img.shields.io/github/release-date/cheqd/sdk?color=green&style=flat-square) [![GitHub license](https://img.shields.io/github/license/cheqd/sdk?color=blue&style=flat-square)](https://github.com/cheqd/sdk/blob/main/LICENSE)

[![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/cheqd/sdk?include_prereleases&label=dev%20release&style=flat-square)](https://github.com/cheqd/sdk/releases/) ![GitHub commits since latest release (by date)](https://img.shields.io/github/commits-since/cheqd/sdk/latest?style=flat-square) [![GitHub contributors](https://img.shields.io/github/contributors/cheqd/sdk?label=contributors%20%E2%9D%A4%EF%B8%8F&style=flat-square)](https://github.com/cheqd/sdk/graphs/contributors)

[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/cheqd/sdk/dispatch.yml?label=workflows&style=flat-square)](https://github.com/cheqd/sdk/actions/workflows/dispatch.yml) [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/cheqd/sdk/codeql.yml?label=CodeQL&style=flat-square)](https://github.com/cheqd/sdk/actions/workflows/codeql.yml) ![GitHub repo size](https://img.shields.io/github/repo-size/cheqd/sdk?style=flat-square)

## i️ 概览

其目的 [`@cheqd/sdk` 国家防范机制一揽子计划](https://www.npmjs.com/package/@cheqd/sdk) 提供与cheqd网络互动的基础功能。 它结合了 [分散标识符( DID)](https://docs.cheqd.io/product/architecture/adr-list/adr-001-cheqd-did-method) 财务报告和审定财务报表 [已链接资源](https://docs.cheqd.io/product/studio/did-linked-resources) 模块,将其放入使用 Cosmos 交易包 [科斯姆杰斯](https://github.com/cosmos/cosmjs)。 。 。 .

此套件被其他 SDKs/ librarys 所消耗, 例如 : [Cheqd 的维拉莫 SDK](https://docs.cheqd.io/product/sdk/veramo) 财务报告和审定财务报表 [克里多语](https://github.com/openwallet-foundation/credo-ts) 添加 cheqd 网络支持.

该套件包括:

-   [TypeScript Protobuf 定义](https://github.com/cheqd/ts-proto) 用于自定义 cheqd Cosmos SDK 模块
-   [科斯姆杰斯](https://github.com/cosmos/cosmjs),用于基础 Cosmos SDK 模块功能

## \* 特性

我们的身份证件网站提供 [用于使用身份特性的教程](https://docs.cheqd.io/product) 在契克德网络.

通过这个SDK,开发者能够:

-   创建一个 `did:cheqd` 方法 [没有](https://docs.cheqd.io/product/architecture/adr-list/adr-001-cheqd-did-method)
-   \* 更新a `did:cheqd` 方法 [没有](https://docs.cheqd.io/product/architecture/adr-list/adr-001-cheqd-did-method)
-   禁用 a `did:cheqd` 方法 [没有](https://docs.cheqd.io/product/architecture/adr-list/adr-001-cheqd-did-method)
-   QQ 创建或更新 [a 已连接的资源](https://docs.cheqd.io/product/studio/did-linked-resources)

### \* 工具

-   ✅ **原始有效载荷创建者**: 使用户能够根据使用情况,生成一个有效的原始的DD有效载荷。 譬如说, `did-provider-cheqd` 在 CLI 应用程序中调用此帮助 .
-   ✅ **身份密钥转换器**: 使用户能够从不同种类的SDK转换出特定的密钥格式,方法是将输入密钥转换为一个cheqd特定DD交易(例如. `createDidDocTx`, (中文(简体) ), `updateDidDocTx`) (中文(简体) ). 例如,Cheqd的Veramo SDK使用这个帮助器,使用户能够用Veramo SDK特定格式将一个密钥传递到cheqd标志输入密钥接口.

## • 收费摘要

Cheqd SDK提供了全面的收费抽象功能,允许用户使用来自其他链条的IBC符来支付交易费,而不是本地的CHEQ符. 这个功能通过允许用户在不持有原生代号的情况下进行切换来实现跨链互操作并改进用户体验.

### 概览

Cheqd上的收费抽象化使:

-   **跨链收费**: 使用其他Cosmos连锁公司的代号支付交易费
-   **东道区管理**: 添加和配置支持的链条以进行收费抽象
-   **自动令牌互换**: 将中型散货箱代币转换为CHEQ, 用于幕后付费
-   **模块账户供资**: 为收费抽取业务提供流动性

### QQ 模块文件

付费抽象功能在以下文件中实现:

**CJS (CommonJS) (中文(简体) )**数字 :

-   主要模块: [`cjs/src/modules/feeabstraction.ts`](https://npmcn.com/package/%40cheqd/sdk/cjs/src/modules/feeabstraction.ts)
-   类型定义 : [`cjs/src/types.ts`](https://npmcn.com/package/%40cheqd/sdk/cjs/src/types.ts)

**无害环境管理(ECMAScript模块)**数字 :

-   主要模块: [`esm/src/modules/feeabstraction.ts`](https://npmcn.com/package/%40cheqd/sdk/esm/src/modules/feeabstraction.ts)
-   类型定义 : [`esm/src/types.ts`](https://npmcn.com/package/%40cheqd/sdk/esm/src/types.ts)

### 基本用途

#### 设置收费摘要

```typescript
import { createCheqdSDK, CheqdNetwork } from '@cheqd/sdk';

// Create wallet instance (e.g., using DirectSecp256k1HdWallet from CosmJS)
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
const wallet = await DirectSecp256k1HdWallet.fromMnemonic('your mnemonic here', { prefix: 'cheqd' }); // replace with your mnemonic, remember to keep it secure

// Set up the SDK options with fee abstraction capabilities
const sdkOptions = {
    modules: [
        FeeabstractionModule as unknown as AbstractCheqdSDKModule,
        // other modules can be added here
    ],
    // other SDK options can be configured here
    rpcUrl: 'https://rpc.cheqd.network', // or your preferred RPC endpoint
    network: CheqdNetwork.Testnet, // or CheqdNetwork.Mainnet
    wallet,
};

// Initialize SDK with fee abstraction support
const sdk = await createCheqdSDK(sdkOptions);
```

### 中型散货箱资产要求

在使用收费抽象功能之前, 请确保您的账户拥有从 Osmosis 等支持的链条连接起来的必要 中型散货箱资产 :

#### 骨质疏导资产

要使用收费抽象,你需要在你的Cheqd账户中存有从Osmosis中取出的国际散货箱代币:

```typescript
// Example IBC denominations that might be supported
const supportedIBCDenoms = [
  'ibc/1480B8FD20AD5FCAE81EA87584D269547DD4D436843C1D20F15E00EB64743EF4', // ATOM from Osmosis
  'ibc/14F9BC3E44B8A9C1BE1FB08980FAB87034C9905EF17CF2442BE1FA40E2E5F16', // OSMO from Osmosis
  // Add other supported IBC denominations
];

// Your account should have these IBC tokens available
async function checkIBCBalances(accountAddress: string) {
  const balances = await sdk.querier.bank.allBalances({ address: accountAddress });

  const ibcBalances = balances.balances.filter(balance =>
    balance.denom.startsWith('ibc/')
  );

  console.log('Available IBC tokens:', ibcBalances);
  return ibcBalances;
}
```

**说明**:为了将资产从奥斯默斯通到契克德,可以使用:

-   [前端 Osmosis 缩写](https://app.osmosis.zone/) 人工转移
-   [IBC 传输工具](https://ibc.fun/) 跨链转让
-   通过 CLI 直接的 IBC 传输命令

### QQ 查询收费摘要数据

#### 主机链配置

```typescript
async function queryHostChainConfig() {
  const configResponse = await sdk.querier[defaultFeeabstractionExtensionKey].hostChainConfig({
    // Query parameters can be added here if needed
  });

  console.log('Host chain configuration:', configResponse);
}
```

#### 模块余额

```typescript
async function queryModuleBalances() {
  const balancesResponse = await sdk.querier[defaultFeeabstractionExtensionKey].feeabsModuleBalances({
    // Query parameters can be added here if needed
  });

  console.log('Fee abstraction module balances:', balancesResponse);
}
```

#### 奥斯默斯TWAP数据

```typescript
async function queryOsmosisTWAP() {
  const twapResponse = await sdk.querier[defaultFeeabstractionExtensionKey].osmosisArithmeticTwap({
    poolId: '1', // Pool ID on Osmosis
    baseAsset: 'uosmo',
    quoteAsset: 'ibc/ABC123...',
    startTime: new Date(Date.now() - 24 * 60 * 60 * 1000), // 24 hours ago
    endTime: new Date()
  });

  console.log('TWAP data:', twapResponse);
}
```

### 治理业务

收费抽象支持配置变化的治理建议:

#### 添加主机区

```typescript
import { MsgAddHostZone } from '@cheqd/ts-proto/feeabstraction/feeabs/v1beta1/index';

async function proposeAddHostZone() {
  const hostZoneData: MsgAddHostZone = {
    authority: 'cheqd1gov...', // Governance authority address
    hostChainId: 'osmosis-1',
    connectionId: 'connection-0',
    ibcDenom: 'ibc/ABC123...',
    nativeDenom: 'uosmo',
    transferChannelId: 'channel-0',
    minSwapAmount: '1000'
  };

  const proposalResponse = await sdk.addHostZoneProposal(
    hostZoneData,
    'Add Osmosis as Host Zone', // Proposal title
    [{ denom: 'ncheq', amount: '10000000000' }], // Deposit
    'cheqd1proposer...', // Proposer address
    {
      amount: [{ denom: 'ncheq', amount: '5000' }],
      gas: '300000'
    }
  );

  console.log('Host zone proposal submitted:', proposalResponse.transactionHash);
}
```

#### 更新主机区配置

```typescript
async function proposeUpdateHostZone() {
  const updateData = {
    authority: 'cheqd1gov...',
    hostChainId: 'osmosis-1',
    // Updated configuration parameters
    minSwapAmount: '2000' // New minimum swap amount
  };

  const updateResponse = await sdk.updateHostZoneProposal(
    updateData,
    'Update Osmosis Host Zone Configuration',
    [{ denom: 'ncheq', amount: '10000000000' }],
    'cheqd1proposer...',
    {
      amount: [{ denom: 'ncheq', amount: '5000' }],
      gas: '300000'
    }
  );

  console.log('Update proposal submitted:', updateResponse.transactionHash);
}
```

### 高级配置

#### TWAP 价格数据查询

```typescript
async function sendTWAPQuery() {
  const twapQueryResponse = await sdk.sendQueryIbcDenomTWAP(
    'cheqd1sender...',
    'ibc/ABC123...', // IBC denomination
    {
      amount: [{ denom: 'ncheq', amount: '5000' }],
      gas: '200000'
    },
    'Query TWAP for price data'
  );

  console.log('TWAP query sent:', twapQueryResponse);
}
```

#### 完整收费摘要工作流程

```typescript
async function completeFeeAbstractionWorkflow() {
  try {
    // 1. Check account has IBC assets available
    const accountAddress = 'cheqd1sender...';
    const ibcBalances = await checkIBCBalances(accountAddress);
    
    if (ibcBalances.length === 0) {
      throw new Error('No IBC tokens available. Please bridge assets from Osmosis first.');
    }

    // 2. Query host chain configuration
    const hostConfig = await sdk.querier[defaultFeeabstractionExtensionKey].hostChainConfig({});
    console.log('Host chain config:', hostConfig);

    // 3. Query current module balances
    const moduleBalances = await sdk.querier[defaultFeeabstractionExtensionKey].feeabsModuleBalances({});
    console.log('Module balances:', moduleBalances);

    // 4. Use IBC tokens for transaction fees directly
    // Fee abstraction automatically handles the conversion behind the scenes
    console.log('Fee abstraction is ready for use with IBC tokens');

    console.log('Fee abstraction workflow completed successfully');
  } catch (error) {
    console.error('Fee abstraction workflow failed:', error);
  }
}
```

### QQ 错误处理

```typescript
async function handleFeeAbstractionErrors() {
  try {
    // Example: Using fee abstraction in a DID operation
    const didCreationResponse = await sdk.createDidDocTx(
      'cheqd1sender...',
      didDocument,
      'key1',
      { amount: [{ denom: 'ibc/ABC123...', amount: '100000' }], gas: '300000' }
    );
  } catch (error) {
    if (error.message.includes('insufficient funds')) {
      console.error('Account has insufficient IBC tokens');
      console.log('Please bridge more assets from Osmosis');
    } else if (error.message.includes('invalid denom')) {
      console.error('Invalid IBC denomination provided');
      console.log('Check supported IBC denominations');
    } else if (error.message.includes('host zone not found')) {
      console.error('Host zone not configured for this IBC token');
    } else {
      console.error('Unexpected fee abstraction error:', error);
    }
  }
}
```

### 与其他模块的整合

收费抽象可以与其他Cheqd SDK模块一起使用:

```typescript
async function useWithDIDOperations() {
  // Create a DID document using fee abstraction for payment
  const didDocument = {
    // DID document structure
  };

  // Use IBC tokens for fee payment via fee abstraction
  const didCreationResponse = await sdk.createDidDocTx(
    'cheqd1creator...',
    didDocument,
    'key1',
    {
      amount: [{ denom: 'ibc/ABC123...', amount: '100000' }], // Pay with IBC tokens
      gas: '300000'
    }
  );

  console.log('DID created with fee abstraction:', didCreationResponse.transactionHash);
}
```

### 最佳做法

1.  **第一桥中型散货箱资产**:确保您在尝试使用付费抽象之前, 已经连接了 Osmosis 所需的中型散货箱标志
2.  **检查账户余额**: 检查您的账户在交易前有足够的 IBC 令牌余额
3.  **处理中型散货箱延迟**: 计算应用程序流中的 IBC 令牌传输延迟
4.  **验证主机区**: 总是在使用 IBC 令牌前验证主机区域配置是否适当
5.  **恢复错误**:对网络和符号相关问题实施强有力的错误处理
6.  **气体估计**: 使用适当的气体限制进行费用抽象交易
7.  **支持的警告**: 跟踪支持中型散货箱面额的收费抽象

关于收费抽象概念和执行的更详细资料,请访问 [收费抽象文档](https://docs.cheqd.io/product)。 。 。 .

## QQ 开发者指南

### 在无害环境管理项目中安装

在需要建立无害环境管理的项目中安装国家防范机制一揽子计划,利用我们 `latest` 释放频道以安装稳定版本 :

```bash
npm install @cheqd/sdk@latest
```

要安装 beta 释放,用我们的 `-develop` 联合国 `beta` 频道 :

```bash
npm install @cheqd/sdk@beta
```

### 在共同JS项目中安装

在需要共同JS建设的项目中安装这一国家防范机制软件包,利用我们 `cjs` 释放频道以安装最新的稳定普通JS版本 :

```bash
npm install @cheqd/sdk@cjs
```

## 页:1

我们 [产品文件网站](https://docs.cheqd.io/product) 解释一下如何 `@cheqd/sdk` 实值 [在Veramo SDK中消费的](https://docs.cheqd.io/product/sdk/veramo) (作为该套件如何被消耗的例子).

## 社区

我们 [**Discord 服务器**](http://cheqd.link/discord-github) 是我们开源社区、软件开发者和节点运营商的主要聊天渠道.

请与我们接触 在那里讨论,帮助, 和反馈项目.

## 找别的地方

[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/cheqd) [![Discord](https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white)](http://cheqd.link/discord-github) [![Twitter](https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white)](https://twitter.com/intent/follow?screen_name=cheqd_io) [![LinkedIn](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white)](http://cheqd.link/linkedin) [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://blog.cheqd.io/) [![YouTube](https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white)](https://www.youtube.com/channel/UCBUGvvH6t3BAYo5u41hJPzw/)

## 常见问题

### @cheqd/sdk 是什么？

使用 CosmJS 构建的 SDK 类型Script 与 cheqd 网络分类账交互

### 如何安装 @cheqd/sdk？

在项目目录运行 npm install @cheqd/sdk，或使用 pnpm add / yarn add / bun add。

### @cheqd/sdk 支持 TypeScript 吗？

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

### @cheqd/sdk 支持 ESM 还是 CommonJS？

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

### @cheqd/sdk 需要什么版本的 Node\.js？

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

### @cheqd/sdk 可以商用吗？

@cheqd/sdk 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @cheqd/sdk 的下载量有多少？

根据 npm 官方下载统计，@cheqd/sdk 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,850 次，日均约 95 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @cheqd/sdk 还在维护吗？

最新版本 5\.5\.1 发布于 2026/06/18（4 个月前）；至今共发布 238 个版本，其中过去 12 个月发布了 29 个；首次发布于 2022/07/28。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

