cosmos-client-ts
JavaScript / TypeScript client for Cosmos SDK blockchain.
Install
npm install --save cosmos-client
Example
import { CosmosSDK } from "cosmos-client";
import { auth } from "cosmos-client/x/auth";
import { bank } from "cosmos-client/x/bank";
const sdk = new CosmosSDK(hostURL, chainID);
let fromAddress: AccAddress;
let privKey: PrivKeySecp256k1;
const account = await auth.queryAccount(sdk, fromAddress);
if (account instanceof Error) {
console.error(account);
return;
}
let toAddress: AccAddress;
let sendReq: SendReq;
const unsignedStdTx: StdTx = await bank.send(sdk, toAddress, sendReq);
if (unsignedStdTx instanceof Error) {
console.error(unsignedStdTx);
return;
}
const signedStdTx: StdTx = auth.signStdTx(
sdk,
privKey,
unsignedStdTx,
account.account_number,
account.sequence + 1,
);
const broadcastReq: BroadcastReq = {
tx: signedStdTx,
mode: "sync",
};
await auth.broadcast(sdk, broadcastReq);