Created
June 1, 2023 03:25
-
-
Save iboss-ptk/e3eb0d33dd870a817123beb5eb7902d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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