# @cosmos-client/core 中文文档

规范地址：https://npmcn.com/package/%40cosmos-client/core/

版本：0\.47\.4
npm 元数据更新时间：2023-10-18T10:04:29.625Z
中文译文更新时间：2026-11-10T21:50:17.109Z
软件包许可：ISC

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

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

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

- 包体积（解压后）：35.7 MB，336 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- 运行依赖：9 个
- 首次发布：2021-10-17T07:48:12.959Z
- 最新版本发布：2023-10-18T10:04:29.418Z
- 近 30 天下载量：3258（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：34（近 12 个月 0 个）

## 中文简介

Cosmos SDK 块链的 REST API 客户端

## 安装

```sh
npm install @cosmos-client/core
```

也可以使用：`pnpm add @cosmos-client/core`、`yarn add @cosmos-client/core`、`bun add @cosmos-client/core`

## README

# @ 宇宙客户/核心

Cosmos SDK 块链的 REST API 客户端

## 安装

```shell
npm install @cosmos-client/core
```

### 谨慎

软件包名称 `cosmos-client` 已贬值。 请使用 `@cosmos-client/core` 换句话说.

## Discord 社区

[邀请链接](https://discord.gg/FKp94XDYSa)

### 插件模块

-   [`@cosmos-client/ibc`](https://github.com/cosmos-client/ibc-ts)
-   [`@cosmos-client/liquidity`](https://github.com/cosmos-client/liquidity-ts)
-   [`@cosmos-client/cosmwasm`](https://github.com/cosmos-client/cosmwasm-ts)
-   [`@cosmos-client/bandprotocol`](https://github.com/cosmos-client/bandprotocol-ts)

## 实例

```typescript
import cosmosclient from '@cosmos-client/core';
import Long from 'long';

describe('bank', () => {
  it('send', async () => {
    expect.hasAssertions();

    const sdk = new cosmosclient.CosmosSDK('http://localhost:1317', 'testchain');

    const privKey = new cosmosclient.proto.cosmos.crypto.secp256k1.PrivKey({
      key: await cosmosclient.generatePrivKeyFromMnemonic('joke door law post fragile cruel torch silver siren mechanic flush surround'),
    });
    const pubKey = privKey.pubKey();
    const address = cosmosclient.AccAddress.fromPublicKey(pubKey);

    expect(address.toString()).toStrictEqual('cosmos14ynfqqa6j5k3kcqm2ymf3l66d9x07ysxgnvdyx');

    const fromAddress = address;
    const toAddress = address;

    // get account info
    const account = await cosmosclient.rest.auth
      .account(sdk, fromAddress)
      .then((res) => cosmosclient.codec.protoJSONToInstance(cosmosclient.codec.castProtoJSONOfProtoAny(res.data.account)))
      .catch((_) => undefined);

    if (!(account instanceof cosmosclient.proto.cosmos.auth.v1beta1.BaseAccount)) {
      console.log(account);
      return;
    }

    // build tx
    const msgSend = new cosmosclient.proto.cosmos.bank.v1beta1.MsgSend({
      from_address: fromAddress.toString(),
      to_address: toAddress.toString(),
      amount: [{ denom: 'token', amount: '1' }],
    });

    const txBody = new cosmosclient.proto.cosmos.tx.v1beta1.TxBody({
      messages: [cosmosclient.codec.instanceToProtoAny(msgSend)],
    });
    const authInfo = new cosmosclient.proto.cosmos.tx.v1beta1.AuthInfo({
      signer_infos: [
        {
          public_key: cosmosclient.codec.instanceToProtoAny(pubKey),
          mode_info: {
            single: {
              mode: cosmosclient.proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT,
            },
          },
          sequence: account.sequence,
        },
      ],
      fee: {
        gas_limit: Long.fromString('200000'),
      },
    });

    // sign
    const txBuilder = new cosmosclient.TxBuilder(sdk, txBody, authInfo);
    const signDocBytes = txBuilder.signDocBytes(account.account_number);
    txBuilder.addSignature(privKey.sign(signDocBytes));

    // broadcast
    const res = await cosmosclient.rest.tx.broadcastTx(sdk, {
      tx_bytes: txBuilder.txBytes(),
      mode: rest.tx.BroadcastTxMode.Block,
    });
    console.log(res);

    expect(res.data.tx_response?.raw_log?.match('failed')).toBeFalsy();
  });
});
```

## 前端开发者

在类似的东西 `polyfill.ts` 在Angular(当然在其他前端框架中类似的东西)中,不要忘记输入这个语句. 如果没有这个声明, 串接 JSON 事件的结果包括 `Long` 类型字段会错误.

```typescript
import Long from 'long';
import * as $protobuf from 'protobufjs/minimal';

$protobuf.util.Long = Long;
$protobuf.configure();
```

## 用于图书馆开发者

安装协议缓冲编译器

```shell
sudo apt -y install protobuf-compiler
```

或者说

```shell
brew install protobuf 
```

使用 [星点](https://github.com/tendermint/starport) 测试.

第一个数位主版本和第二个数位小版本应该与宇宙SDK相匹配. 第三位数补丁版本可以独立递增.

### 页:1 `proto.d.ts` 错误

在 proto.d.ts 文件结尾处添加以下一行,并在出错点时将 pardmint 替换为 global termint .

```typescript
import global_tendermint = tendermint;
```

## 常见问题

### @cosmos-client/core 是什么？

Cosmos SDK 块链的 REST API 客户端

### 如何安装 @cosmos-client/core？

在项目目录运行 npm install @cosmos-client/core，或使用 pnpm add / yarn add / bun add。

### @cosmos-client/core 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/cosmos-client\_\_core 是否存在。

### @cosmos-client/core 支持 ESM 还是 CommonJS？

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

### @cosmos-client/core 可以商用吗？

@cosmos-client/core 使用 ISC 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @cosmos-client/core 的下载量有多少？

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

### @cosmos-client/core 还在维护吗？

最新版本 0\.47\.4 发布于 2023/10/18（3 年前）；至今共发布 34 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/10/17。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

