EncodeObject:
Typed Encode Objects
CosmJS also provides typed encode objects for common messages. These narrow thetypeUrl to a string literal and constrain value to the correct Protobuf
type, giving you compile-time safety:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
The JavaScript representation of Cosmos SDK messages in CosmJS
EncodeObject:
interface EncodeObject {
readonly typeUrl: string;
readonly value: any;
}
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { coins } from "@cosmjs/proto-signing";
const msg: EncodeObject = {
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: MsgSend.fromPartial({
fromAddress: "cosmos1sender...",
toAddress: "cosmos1recipient...",
amount: coins(1_000_000, "uatom"),
}),
};
typeUrl to a string literal and constrain value to the correct Protobuf
type, giving you compile-time safety:
import { MsgSendEncodeObject } from "@cosmjs/stargate";
const msg: MsgSendEncodeObject = {
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: MsgSend.fromPartial({ ... }),
};
@cosmjs/stargate| Type | typeUrl |
|---|---|
MsgSendEncodeObject | /cosmos.bank.v1beta1.MsgSend |
MsgDelegateEncodeObject | /cosmos.staking.v1beta1.MsgDelegate |
MsgUndelegateEncodeObject | /cosmos.staking.v1beta1.MsgUndelegate |
MsgBeginRedelegateEncodeObject | /cosmos.staking.v1beta1.MsgBeginRedelegate |
MsgWithdrawDelegatorRewardEncodeObject | /cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward |
MsgDepositEncodeObject | /cosmos.gov.v1beta1.MsgDeposit |
MsgSubmitProposalEncodeObject | /cosmos.gov.v1beta1.MsgSubmitProposal |
MsgVoteEncodeObject | /cosmos.gov.v1beta1.MsgVote |
MsgTransferEncodeObject | /ibc.applications.transfer.v1.MsgTransfer |
@cosmjs/cosmwasm| Type | typeUrl |
|---|---|
MsgStoreCodeEncodeObject | /cosmwasm.wasm.v1.MsgStoreCode |
MsgInstantiateContractEncodeObject | /cosmwasm.wasm.v1.MsgInstantiateContract |
MsgInstantiateContract2EncodeObject | /cosmwasm.wasm.v1.MsgInstantiateContract2 |
MsgExecuteContractEncodeObject | /cosmwasm.wasm.v1.MsgExecuteContract |
MsgMigrateContractEncodeObject | /cosmwasm.wasm.v1.MsgMigrateContract |
MsgUpdateAdminEncodeObject | /cosmwasm.wasm.v1.MsgUpdateAdmin |
MsgClearAdminEncodeObject | /cosmwasm.wasm.v1.MsgClearAdmin |
Was this page helpful?