sdk-cosmos
v0.0.19
Published
javascript lib to interact with zeta blockchain
Readme
@zetachain/sdk-cosmos
JavaScript library to interact with ZetaChain blockchain
Installation
npm install @zetachain/sdk-cosmosTable of Contents
Usage
RPC Clients
import { zeta } from '@zetachain/sdk-cosmos';
const { createRPCQueryClient } = zeta.ClientFactory;
const client = await createRPCQueryClient({ rpcEndpoint: RPC_ENDPOINT });
// now you can query the cosmos modules
const balance = await client.cosmos.bank.v1beta1
.allBalances({ address: 'zeta1addresshere' });
Composing Messages
Cosmos Messages
import { cosmos } from '@zetachain/sdk-cosmos';
const {
fundCommunityPool,
setWithdrawAddress,
withdrawDelegatorReward,
withdrawValidatorCommission
} = cosmos.distribution.v1beta1.MessageComposer.fromPartial;
const {
multiSend,
send
} = cosmos.bank.v1beta1.MessageComposer.fromPartial;
const {
beginRedelegate,
createValidator,
delegate,
editValidator,
undelegate
} = cosmos.staking.v1beta1.MessageComposer.fromPartial;
const {
deposit,
submitProposal,
vote,
voteWeighted
} = cosmos.gov.v1beta1.MessageComposer.fromPartial;Connecting with Wallets and Signing Messages
Creating Signers
To broadcast messages, you can create signers with a variety of options:
Amino Signer
import { getOfflineSignerAmino as getOfflineSigner } from 'cosmjs-utils';Proto Signer
import { getOfflineSignerProto as getOfflineSigner } from 'cosmjs-utils';⚠️ WARNING: NOT RECOMMENDED TO USE PLAIN-TEXT MNEMONICS. Please take care of your security and use best practices such as AES encryption and/or methods from 2factor applications.
import { chains } from 'chain-registry';
const mnemonic =
'unfold client turtle either pilot stock floor glow toward bullet car science';
const chain = chains.find(({ chain_name }) => chain_name === 'zeta');
const signer = await getOfflineSigner({
mnemonic,
chain
});Broadcasting Messages
const { send } = cosmos.bank.v1beta1.MessageComposer.withTypeUrl;
const msg = send({
amount: [
{
denom: 'coin',
amount: '1000'
}
],
toAddress: address,
fromAddress: address
});
const fee = {
amount: [
{
denom: 'coin',
amount: '864'
}
],
gas: '86364'
};
const response = await stargateClient.signAndBroadcast(address, [msg], fee);License
MIT
