# @cosmos-client/core

> REST API client for Cosmos SDK blockchain

Latest version **0.47.4** (published 2023-10-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install @cosmos-client/core
pnpm add @cosmos-client/core
yarn add @cosmos-client/core
bun add @cosmos-client/core
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; large bundle; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.47.4 |
| Published | 2023-10-18 |
| First published | 2021-10-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 9 |
| Unpacked size | 34.1 MB |
| Known vulnerabilities | 0 (+33 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 34 |
| Author | CauchyE, Inc. |
| Maintainers | kimurayu45z |
| Keywords | Blockchain, Cosmos SDK |

## Links

- npm: https://www.npmjs.com/package/@cosmos-client/core
- Repository: https://github.com/cosmos-client/cosmos-client-ts
- Homepage: https://github.com/cosmos-client/cosmos-client-ts#readme
- Issues: https://github.com/cosmos-client/cosmos-client-ts/issues
- npm.io page: https://npm.io/package/@cosmos-client/core

## Dependencies (9)

- [rxjs](https://npm.io/package/rxjs.md) ^7.4.0
- [axios](https://npm.io/package/axios.md) ^0.23.0
- [bip32](https://npm.io/package/bip32.md) ^2.0.6
- [bip39](https://npm.io/package/bip39.md) ^3.0.4
- [bech32](https://npm.io/package/bech32.md) ^1.1.4
- [process](https://npm.io/package/process.md) ^0.11.10
- [secp256k1](https://npm.io/package/secp256k1.md) ^4.0.2
- [tweetnacl](https://npm.io/package/tweetnacl.md) ^1.0.3
- [protobufjs](https://npm.io/package/protobufjs.md) ^6.11.3

## Recent versions

- 0.47.4 (latest) — 2023-10-18
- 0.47.4-rc1 — 2023-10-06
- 0.47.3 — 2023-09-27
- 0.47.3-rc2 — 2023-09-22
- 0.47.3-rc1 — 2023-09-12
- 0.47.1 — 2023-06-02
- 0.47.1-rc1 — 2023-05-30
- 0.46.1 — 2022-12-09
- 0.46.0 — 2022-08-12
- 0.46.0-rc7 — 2022-06-30
- 0.46.0-rc6 — 2022-06-30
- 0.46.0-rc5 — 2022-06-28
- 0.46.0-rc4 — 2022-06-28
- 0.45.13 — 2022-06-24
- 0.46.0-rc3 — 2022-06-24
- … 19 more at https://npm.io/package/@cosmos-client/core/versions

## README

# @cosmos-client/core

REST API client for Cosmos SDK blockchain

## Install

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

### Caution

The package name `cosmos-client` is deprecated. Please use `@cosmos-client/core` alternatively.

## Discord community

[Invitation link](https://discord.gg/FKp94XDYSa)

### Plugin modules

- [`@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)

## Examples

```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();
  });
});
```

## For frontend developers

In something like `polyfill.ts` in Angular (of course something like that in other frontend frameworks), don't forget to input this statement.
If there isn't this statement, the outcome of serializing JSON of instances including `Long` type field will be wrong.

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

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

## For library developlers

Install Protocol Buffer Compiler

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

or

```shell
brew install protobuf 
```

Use [starport](https://github.com/tendermint/starport) to test.

The first digit major version and the second digit minor version should match Cosmos SDK.
The third digit patch version can be independently incremented.

### for `proto.d.ts` error

Add the following line to the end of the proto.d.ts file and replace tendermint with global_tendermint at the error points.

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

---
_Source: https://npm.io/package/@cosmos-client/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
