From 1ee39167dec9f9646bac9ae7e3706e3901d93a59 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 11 Feb 2021 15:56:29 +0100 Subject: [PATCH] Add stargate example --- packages/cli/examples/stargate.ts | 23 +++++++++++++++++++++++ packages/cli/run_examples.sh | 3 +++ 2 files changed, 26 insertions(+) create mode 100644 packages/cli/examples/stargate.ts diff --git a/packages/cli/examples/stargate.ts b/packages/cli/examples/stargate.ts new file mode 100644 index 00000000..f4577461 --- /dev/null +++ b/packages/cli/examples/stargate.ts @@ -0,0 +1,23 @@ +import { makeCosmoshubPath, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; +import { assertIsBroadcastTxSuccess, SigningStargateClient } from "@cosmjs/stargate"; + +const mnemonic = "economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone"; +const path = makeCosmoshubPath(3); +const prefix = "cosmos"; +const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, path, prefix); +const [firstAccount] = await wallet.getAccounts(); +console.log("Signer address:", firstAccount.address); + +const rpcEndpoint = "ws://localhost:26658"; +const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet); + +const recipient = "cosmos1xv9tklw7d82sezh9haa573wufgy59vmwe6xxe5"; +const amount = { + denom: "ucosm", + amount: "1234567", +}; +const result = await client.sendTokens(firstAccount.address, recipient, [amount], "Have fun with your star coins"); +assertIsBroadcastTxSuccess(result); +console.log("Successfully broadcasted:", result); + +client.disconnect(); diff --git a/packages/cli/run_examples.sh b/packages/cli/run_examples.sh index 7fce9821..fde36611 100755 --- a/packages/cli/run_examples.sh +++ b/packages/cli/run_examples.sh @@ -13,3 +13,6 @@ cosmwasm-cli --init examples/generate_address.ts --code "process.exit(0)" cosmwasm-cli --init examples/helpers.ts --code "process.exit(0)" cosmwasm-cli --init examples/local_faucet.ts --code "process.exit(0)" cosmwasm-cli --init examples/mask.ts --code "process.exit(0)" +if [ -n "${SIMAPP_ENABLED:-}" ]; then + cosmwasm-cli --init examples/stargate.ts --code "process.exit(0)" +fi