Skip to content

Instantly share code, notes, and snippets.

@iboss-ptk
Created June 1, 2023 03:25
Show Gist options
  • Save iboss-ptk/e3eb0d33dd870a817123beb5eb7902d2 to your computer and use it in GitHub Desktop.
Save iboss-ptk/e3eb0d33dd870a817123beb5eb7902d2 to your computer and use it in GitHub Desktop.
import { SigningStargateClient, StdFee, coin } from "@cosmjs/stargate";
import { chains } from "chain-registry";
import { getOfflineSignerProto } from "cosmjs-utils";
import { cosmwasm } from "osmojs";
import { ExecuteMsg } from "./contracts/WbtcController.types";
const { executeContract } = cosmwasm.wasm.v1.MessageComposer.withTypeUrl;
async function main() {
// get offline signer
const chain = chains.find(({ chain_name }) => chain_name === "osmosis");
if (typeof chain === "undefined") {
throw new Error("Chain not found");
}
const signer = await getOfflineSignerProto({
mnemonic: "...",
chain,
});
const client = await SigningStargateClient.offline(signer);
// specify execute msg, this will be turned into JSON bytes and passed to msgExecuteContract
const msgIssueMintRequest: ExecuteMsg = {
issue_mint_request: {
amount: "100000000",
deposit_address: "bt1q...",
tx_id: "",
},
};
// compose msg execute contract
const encoder = new TextEncoder();
const msgExecuteContract = executeContract({
sender: "osmo1...",
contract: "osmo1...",
// encode execute msg as byte array of JSON string
msg: encoder.encode(JSON.stringify(msgIssueMintRequest)),
funds: [],
});
// specify fee (this one is arbitrary)
const fee: StdFee = {
amount: [coin(1000000, "uosmo")],
gas: "1000000",
};
const tx = await client.sign("osmo1...", [msgExecuteContract], fee, "memo");
console.log(tx);
}
main().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment