Utilities for Cosmos SDK 0.40
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Protocol buffer message types and encoding utilities for creating and signing transactions. Includes type-safe message builders for all Cosmos SDK modules.
All messages implement the EncodeObject interface with a type URL and protobuf message value.
interface EncodeObject {
/** Protocol buffer type URL */
readonly typeUrl: string;
/** Encoded message value */
readonly value: any;
}Messages for token transfers and multi-sends.
/** Send tokens message */
interface MsgSendEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.bank.v1beta1.MsgSend";
readonly value: Partial<MsgSend>;
}
/** Multi-send tokens message */
interface MsgMultiSendEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.bank.v1beta1.MsgMultiSend";
readonly value: Partial<MsgMultiSend>;
}
/** Type guard for MsgSend */
function isMsgSendEncodeObject(encodeObject: EncodeObject): encodeObject is MsgSendEncodeObject;
/** Type guard for MsgMultiSend */
function isMsgMultiSendEncodeObject(encodeObject: EncodeObject): encodeObject is MsgMultiSendEncodeObject;
/** Bank module registry types */
const bankTypes: ReadonlyArray<[string, GeneratedType]>;Usage Examples:
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
// Create send message
const sendMsg: MsgSendEncodeObject = {
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: MsgSend.fromPartial({
fromAddress: "cosmos1sender...",
toAddress: "cosmos1recipient...",
amount: [{ denom: "uatom", amount: "1000000" }],
}),
};
// Type guard usage
if (isMsgSendEncodeObject(someMessage)) {
// TypeScript knows this is MsgSendEncodeObject
console.log(someMessage.value.fromAddress);
}Messages for delegation, undelegation, and validator operations.
/** Delegate tokens message */
interface MsgDelegateEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.staking.v1beta1.MsgDelegate";
readonly value: Partial<MsgDelegate>;
}
/** Undelegate tokens message */
interface MsgUndelegateEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate";
readonly value: Partial<MsgUndelegate>;
}
/** Begin redelegate message */
interface MsgBeginRedelegateEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.staking.v1beta1.MsgBeginRedelegate";
readonly value: Partial<MsgBeginRedelegate>;
}
/** Cancel unbonding delegation message */
interface MsgCancelUnbondingDelegationEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation";
readonly value: Partial<MsgCancelUnbondingDelegation>;
}
/** Create validator message */
interface MsgCreateValidatorEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.staking.v1beta1.MsgCreateValidator";
readonly value: Partial<MsgCreateValidator>;
}
/** Edit validator message */
interface MsgEditValidatorEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.staking.v1beta1.MsgEditValidator";
readonly value: Partial<MsgEditValidator>;
}
/** Type guards for staking messages */
function isMsgDelegateEncodeObject(encodeObject: EncodeObject): encodeObject is MsgDelegateEncodeObject;
function isMsgUndelegateEncodeObject(encodeObject: EncodeObject): encodeObject is MsgUndelegateEncodeObject;
function isMsgBeginRedelegateEncodeObject(encodeObject: EncodeObject): encodeObject is MsgBeginRedelegateEncodeObject;
function isMsgCancelUnbondingDelegationEncodeObject(encodeObject: EncodeObject): encodeObject is MsgCancelUnbondingDelegationEncodeObject;
function isMsgCreateValidatorEncodeObject(encodeObject: EncodeObject): encodeObject is MsgCreateValidatorEncodeObject;
function isMsgEditValidatorEncodeObject(encodeObject: EncodeObject): encodeObject is MsgEditValidatorEncodeObject;
/** Staking module registry types */
const stakingTypes: ReadonlyArray<[string, GeneratedType]>;Usage Examples:
import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
// Create delegate message
const delegateMsg: MsgDelegateEncodeObject = {
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
value: MsgDelegate.fromPartial({
delegatorAddress: "cosmos1delegator...",
validatorAddress: "cosmosvaloper1validator...",
amount: { denom: "uatom", amount: "5000000" },
}),
};Messages for withdrawing rewards and setting withdraw addresses.
/** Withdraw delegator rewards message */
interface MsgWithdrawDelegatorRewardEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward";
readonly value: Partial<MsgWithdrawDelegatorReward>;
}
/** Withdraw validator commission message */
interface MsgWithdrawValidatorCommissionEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission";
readonly value: Partial<MsgWithdrawValidatorCommission>;
}
/** Set withdraw address message */
interface MsgSetWithdrawAddressEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress";
readonly value: Partial<MsgSetWithdrawAddress>;
}
/** Fund community pool message */
interface MsgFundCommunityPoolEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.distribution.v1beta1.MsgFundCommunityPool";
readonly value: Partial<MsgFundCommunityPool>;
}
/** Type guards for distribution messages */
function isMsgWithdrawDelegatorRewardEncodeObject(encodeObject: EncodeObject): encodeObject is MsgWithdrawDelegatorRewardEncodeObject;
function isMsgWithdrawValidatorCommissionEncodeObject(encodeObject: EncodeObject): encodeObject is MsgWithdrawValidatorCommissionEncodeObject;
function isMsgSetWithdrawAddressEncodeObject(encodeObject: EncodeObject): encodeObject is MsgSetWithdrawAddressEncodeObject;
function isMsgFundCommunityPoolEncodeObject(encodeObject: EncodeObject): encodeObject is MsgFundCommunityPoolEncodeObject;
/** Distribution module registry types */
const distributionTypes: ReadonlyArray<[string, GeneratedType]>;Messages for governance proposals, voting, and deposits.
/** Submit proposal message */
interface MsgSubmitProposalEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.gov.v1beta1.MsgSubmitProposal";
readonly value: Partial<MsgSubmitProposal>;
}
/** Vote on proposal message */
interface MsgVoteEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.gov.v1beta1.MsgVote";
readonly value: Partial<MsgVote>;
}
/** Weighted vote message */
interface MsgVoteWeightedEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.gov.v1beta1.MsgVoteWeighted";
readonly value: Partial<MsgVoteWeighted>;
}
/** Deposit on proposal message */
interface MsgDepositEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.gov.v1beta1.MsgDeposit";
readonly value: Partial<MsgDeposit>;
}
/** Type guards for gov messages */
function isMsgSubmitProposalEncodeObject(encodeObject: EncodeObject): encodeObject is MsgSubmitProposalEncodeObject;
function isMsgVoteEncodeObject(encodeObject: EncodeObject): encodeObject is MsgVoteEncodeObject;
function isMsgVoteWeightedEncodeObject(encodeObject: EncodeObject): encodeObject is MsgVoteWeightedEncodeObject;
function isMsgDepositEncodeObject(encodeObject: EncodeObject): encodeObject is MsgDepositEncodeObject;
/** Gov module registry types */
const govTypes: ReadonlyArray<[string, GeneratedType]>;Usage Examples:
import { MsgVote, VoteOption } from "cosmjs-types/cosmos/gov/v1beta1/tx";
import Long from "long";
// Create vote message
const voteMsg: MsgVoteEncodeObject = {
typeUrl: "/cosmos.gov.v1beta1.MsgVote",
value: MsgVote.fromPartial({
proposalId: Long.fromNumber(1),
voter: "cosmos1voter...",
option: VoteOption.VOTE_OPTION_YES,
}),
};Messages for Inter-Blockchain Communication transfers.
/** IBC transfer message */
interface MsgTransferEncodeObject extends EncodeObject {
readonly typeUrl: "/ibc.applications.transfer.v1.MsgTransfer";
readonly value: Partial<MsgTransfer>;
}
/** Type guard for IBC transfer */
function isMsgTransferEncodeObject(encodeObject: EncodeObject): encodeObject is MsgTransferEncodeObject;
/** IBC module registry types */
const ibcTypes: ReadonlyArray<[string, GeneratedType]>;Usage Examples:
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
import { Height } from "cosmjs-types/ibc/core/client/v1/client";
import Long from "long";
// Create IBC transfer message
const transferMsg: MsgTransferEncodeObject = {
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
value: MsgTransfer.fromPartial({
sourcePort: "transfer",
sourceChannel: "channel-0",
token: { denom: "uatom", amount: "1000000" },
sender: "cosmos1sender...",
receiver: "osmo1receiver...",
timeoutHeight: Height.fromPartial({
revisionNumber: Long.fromNumber(1),
revisionHeight: Long.fromNumber(12345000),
}),
timeoutTimestamp: Long.fromNumber(0),
}),
};/** Authz module registry types */
const authzTypes: ReadonlyArray<[string, GeneratedType]>;
/** Feegrant module registry types */
const feegrantTypes: ReadonlyArray<[string, GeneratedType]>;
/** Group module registry types */
const groupTypes: ReadonlyArray<[string, GeneratedType]>;
/** Vesting module registry types */
const vestingTypes: ReadonlyArray<[string, GeneratedType]>;The registry maps type URLs to their corresponding protobuf generated types.
/** Protocol buffer type registry */
class Registry {
constructor(types?: Iterable<[string, GeneratedType]>);
/** Register a new type */
register(typeUrl: string, type: GeneratedType): void;
/** Look up type by URL */
lookupType(typeUrl: string): GeneratedType | undefined;
/** Encode message */
encode(encodeObject: EncodeObject): Uint8Array;
/** Decode message */
decode(encodeObject: { typeUrl: string; value: Uint8Array }): any;
}
/** Generated protobuf type */
interface GeneratedType {
encode(message: any, writer?: Writer): Writer;
decode(input: Reader | Uint8Array, length?: number): any;
fromJSON(object: any): any;
toJSON(message: any): unknown;
fromPartial(object: DeepPartial<any>): any;
}
/** Default registry types for all supported modules */
const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]>;Usage Examples:
import { Registry } from "@cosmjs/proto-signing";
import { defaultRegistryTypes } from "@cosmjs/stargate";
// Create registry with default types
const registry = new Registry(defaultRegistryTypes);
// Add custom type
import { MsgCustom } from "./proto/custom/tx";
registry.register("/custom.MsgCustom", MsgCustom);
// Encode message
const encoded = registry.encode({
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: sendMessage,
});import { SigningStargateClient } from "@cosmjs/stargate";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
// Create multiple messages
const messages = [
// Send tokens
{
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: MsgSend.fromPartial({
fromAddress: account.address,
toAddress: "cosmos1recipient...",
amount: [{ denom: "uatom", amount: "1000000" }],
}),
},
// Delegate tokens
{
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
value: MsgDelegate.fromPartial({
delegatorAddress: account.address,
validatorAddress: "cosmosvaloper1validator...",
amount: { denom: "uatom", amount: "5000000" },
}),
},
];
// Sign and broadcast
const result = await client.signAndBroadcast(
account.address,
messages,
"auto",
"Multi-action transaction"
);import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
// Custom CosmWasm message
const wasmMsg = {
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
value: MsgExecuteContract.fromPartial({
sender: account.address,
contract: "cosmos1contract...",
msg: new TextEncoder().encode(JSON.stringify({
transfer: {
recipient: "cosmos1recipient...",
amount: "1000000"
}
})),
funds: [],
}),
};
const result = await client.signAndBroadcast(
account.address,
[wasmMsg],
"auto"
);