Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cosmos-client

Package Overview
Dependencies
Maintainers
2
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cosmos-client

REST API Client for Cosmos SDK Blockchain

  • 0.39.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
93
decreased by-61.89%
Maintainers
2
Weekly downloads
 
Created
Source

cosmos-client-ts

JavaScript / TypeScript client for Cosmos SDK blockchain.

Install

npm install --save cosmos-client

Example

import { CosmosSDK, AccAddress, PrivKeySecp256k1 } from "cosmos-client";
import { auth } from "cosmos-client/x/auth";
import { bank } from "cosmos-client/x/bank";

const sdk = new CosmosSDK(hostURL, chainID);

// get account info
const privKeyBuffer = await sdk.generatePrivKeyFromMnemonic(mnemonic);
const privKey = new PrivKeySecp256k1(privKeyBuffer);
const fromAddress = AccAddress.fromPublicKey(privKey.getPubKey());
const account = await auth
  .accountsAddressGet(sdk, fromAddress)
  .then((res) => res.data.result);

// get unsigned tx
const toAddress = fromAddress;

const unsignedStdTx = await bank
  .accountsAddressTransfersPost(sdk, toAddress, {
    base_req: {
      from: fromAddress.toBech32(),
      memo: "Hello, world!",
      chain_id: sdk.chainID,
      account_number: account.account_number.toString(),
      sequence: account.sequence.toString(),
      gas: "",
      gas_adjustment: "",
      fees: [],
      simulate: false,
    },
    amount: [{ denom: "token", amount: "1000" }],
  })
  .then((res) => res.data);

// sign
const signedStdTx = auth.signStdTx(
  sdk,
  privKey,
  unsignedStdTx,
  account.account_number,
  account.sequence,
);

// broadcast
const result = await auth
  .txsPost(sdk, signedStdTx, "sync")
  .then((res) => res.data);

For library developlers

swagger.yml

openapi-generator generate -g typescript-axios -i swagger.yaml -o ./src

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

Keywords

FAQs

Package last updated on 03 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc