BaseChainClient
JsonToArray
Helper function to convert JSON to Uint8Array.
const JsonToArray = function (json: Record<string, any>) {
var str = JSON.stringify(json, null, 0);
var ret = new Uint8Array(str.length);
for (var i = 0; i < str.length; i++) {
ret[i] = str.charCodeAt(i);
}
return ret;
Class
A base class that extends the other clients.
export default class BaseChainClient implements Partial<ChainClient> {
public signingClient?: ChainClient["signingClient"];
public queryClient?: ChainClient["queryClient"];
public signer = "";
signingClient
Same as in the ChainClient interface.
The client used to sign any transactions braodcast to the chain.
signer
string
The current signer address.
Methods
encodeExecuteMsg
Converts an execute message to an EncodeObject for signing or simulating.
encodeExecuteMsg(
address: string,
msg: Msg,
funds: Coin[]
): MsgExecuteContractEncodeObject {
return {
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
value: {
sender: this.signer,
contract: address,
msg: JsonToArray(msg),
funds,
},
};
}
Msg
export type Msg = Record<string, unknown>;
encodeInstantiateMsg
Converts an instantiate message to an EncodeObject for signing or simulating.
encodeInstantiateMsg(
codeId: number,
msg: Msg,
label: string,
options?: InstantiateOptions
): MsgInstantiateContractEncodeObject {
return {
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
value: {
sender: this.signer,
codeId: BigInt(codeId),
msg: JsonToArray(msg),
label,
'admin': options?.admin,
'funds': options?.funds as any
},
};
}
codeId
number
The code Id of the contract you are looking to instantiate.
label
string
String of text to provide additional information on the transaction.
encodeUploadMessage
Converts an upload message to an EncodeObject for signing or simulating.
encodeUploadMessage(wasmByteCode: Uint8Array): MsgStoreCodeEncodeObject {
return {
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
value: {
sender: this.signer,
wasmByteCode,
},
};
}
wasmByteCode
Uint8Array
The wasm binary code to upload to chain.
encodeMigrateMessage
Converts a migrate message to an EncodeObject for signing or simulating.
encodeMigrateMessage(
address: string,
codeId: number,
msg: Msg
): MsgMigrateContractEncodeObject {
return {
typeUrl: "/cosmwasm.wasm.v1.MsgMigrateContract",
value: {
sender: this.signer,
codeId: Long.fromNumber(codeId),
contract: address,
msg: JsonToArray(msg),
},
};
}
address
string
The contract address to migrate.
codeId
number
The code Id of the contract to migrate to.
encodeSendMessage
Converts a Send message to an EncodeObject for signing or simulating.
encodeSendMessage(
receivingAddress: string,
amount: Coin[]
): MsgSendEncodeObject {
return {
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: {
fromAddress: this.signer,
toAddress: receivingAddress,
amount,
},
};
}
receivingAddress
string
The address to receive the funds sent.
Last updated