Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
cosmos-client
Advanced tools
JavaScript / TypeScript client for Cosmos SDK blockchain.
npm install --save cosmos-client
import { cosmosclient, rest, proto } from 'cosmos-client';
describe('bank', () => {
it('send', async () => {
expect.hasAssertions();
const sdk = new cosmosclient.CosmosSDK('http://localhost:1317', 'testchain');
const privKey = new 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 rest.cosmos.auth
.account(sdk, fromAddress)
.then((res) => res.data.account && cosmosclient.codec.unpackCosmosAny(res.data.account))
.catch((_) => undefined);
if (!(account instanceof proto.cosmos.auth.v1beta1.BaseAccount)) {
console.log(account);
return;
}
// build tx
const msgSend = new proto.cosmos.bank.v1beta1.MsgSend({
from_address: fromAddress.toString(),
to_address: toAddress.toString(),
amount: [{ denom: 'token', amount: '1' }],
});
const txBody = new proto.cosmos.tx.v1beta1.TxBody({
messages: [cosmosclient.codec.packAny(msgSend)],
});
const authInfo = new proto.cosmos.tx.v1beta1.AuthInfo({
signer_infos: [
{
public_key: cosmosclient.codec.packAny(pubKey),
mode_info: {
single: {
mode: proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT,
},
},
sequence: account.sequence,
},
],
fee: {
gas_limit: cosmosclient.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 rest.cosmos.tx.broadcastTx(sdk, {
tx_bytes: txBuilder.txBytes(),
mode: rest.cosmos.tx.BroadcastTxMode.Block,
});
console.log(res);
expect(res.data.tx_response?.raw_log?.match('failed')).toBeFalsy();
});
});
Use 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.
proto.d.ts
errorInsert:
import global_tendermint = tendermint;
FAQs
REST API Client for Cosmos SDK Blockchain
The npm package cosmos-client receives a total of 232 weekly downloads. As such, cosmos-client popularity was classified as not popular.
We found that cosmos-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.