From 7af702c708a64e3d0386a95aa402c48bbb97de88 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 10 Feb 2021 15:36:38 +0100 Subject: [PATCH 01/12] Pull out CLI example runner --- .circleci/config.yml | 9 +-------- packages/cli/run_examples.sh | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100755 packages/cli/run_examples.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 25d5c737..63d92452 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -305,14 +305,7 @@ jobs: working_directory: packages/cli environment: SKIP_BUILD: 1 - command: | - ./bin/cosmwasm-cli --init examples/coralnet.ts --code "process.exit(0)" - ./bin/cosmwasm-cli --init examples/delegate.ts --code "process.exit(0)" - ./bin/cosmwasm-cli --init examples/faucet_addresses.ts --code "process.exit(0)" - ./bin/cosmwasm-cli --init examples/generate_address.ts --code "process.exit(0)" - ./bin/cosmwasm-cli --init examples/helpers.ts --code "process.exit(0)" - ./bin/cosmwasm-cli --init examples/local_faucet.ts --code "process.exit(0)" - ./bin/cosmwasm-cli --init examples/mask.ts --code "process.exit(0)" + command: ./run_examples.sh - run: name: Stop chains command: | diff --git a/packages/cli/run_examples.sh b/packages/cli/run_examples.sh new file mode 100755 index 00000000..7fce9821 --- /dev/null +++ b/packages/cli/run_examples.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -o errexit -o nounset -o pipefail +command -v shellcheck >/dev/null && shellcheck "$0" + +PATH="$(realpath ./bin):$PATH" + +cosmwasm-cli --init examples/coralnet.ts --code "process.exit(0)" +if [ -n "${LAUNCHPAD_ENABLED:-}" ]; then + cosmwasm-cli --init examples/delegate.ts --code "process.exit(0)" +fi +cosmwasm-cli --init examples/faucet_addresses.ts --code "process.exit(0)" +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)" From 6a32240185a9b075396cce7bbc74cc027694f7d9 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 10 Feb 2021 15:52:51 +0100 Subject: [PATCH 02/12] Avoid auto-importing fs and axios --- packages/cli/examples/helpers.ts | 3 +++ packages/cli/src/cli.ts | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/cli/examples/helpers.ts b/packages/cli/examples/helpers.ts index 9187b353..dce90d63 100644 --- a/packages/cli/examples/helpers.ts +++ b/packages/cli/examples/helpers.ts @@ -1,3 +1,6 @@ +import axios from "axios"; +import * as fs from "fs"; + interface Options { httpUrl: string; networkId: string; diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index efbf55d1..9c002601 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -129,16 +129,11 @@ export async function main(originalArgs: readonly string[]): Promise { console.info(colors.green("Initializing session for you. Have fun!")); console.info(colors.yellow("Available imports:")); - console.info(colors.yellow(" * axios")); - console.info(colors.yellow(" * fs")); for (const [moduleName, symbols] of imports.entries()) { console.info(colors.yellow(` * from ${moduleName}: ${symbols.join(", ")}`)); } - let init = ` - import axios from "axios"; - import * as fs from "fs"; - `; + let init = ""; for (const [moduleName, symbols] of imports.entries()) { init += `import { ${symbols.join(", ")} } from "${moduleName}";\n`; } @@ -146,6 +141,9 @@ export async function main(originalArgs: readonly string[]): Promise { if (args.selftest) { // execute some trival stuff and exit init += ` + import axios from "axios"; + import * as fs from "fs"; + await sleep(123); const readmeContent = fs.readFileSync(process.cwd() + "/README.md"); From 131928dfe551562ea6ef5c46cae4809b7252828e Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 10 Feb 2021 16:05:48 +0100 Subject: [PATCH 03/12] Do not auto-import @cosmjs/launchpad types --- packages/cli/examples/coralnet.ts | 2 + packages/cli/examples/delegate.ts | 2 + packages/cli/examples/faucet_addresses.ts | 2 + packages/cli/examples/generate_address.ts | 2 + packages/cli/examples/helpers.ts | 2 + packages/cli/examples/local_faucet.ts | 2 + packages/cli/examples/mask.ts | 2 + packages/cli/src/cli.ts | 49 ++++++----------------- 8 files changed, 27 insertions(+), 36 deletions(-) diff --git a/packages/cli/examples/coralnet.ts b/packages/cli/examples/coralnet.ts index c8488040..3bb552ad 100644 --- a/packages/cli/examples/coralnet.ts +++ b/packages/cli/examples/coralnet.ts @@ -1,3 +1,5 @@ +import { GasPrice, GasLimits, makeCosmoshubPath, Secp256k1HdWallet } from "@cosmjs/launchpad"; + interface Options { readonly httpUrl: string; readonly bech32prefix: string; diff --git a/packages/cli/examples/delegate.ts b/packages/cli/examples/delegate.ts index f99da7e7..f84314bf 100644 --- a/packages/cli/examples/delegate.ts +++ b/packages/cli/examples/delegate.ts @@ -1,3 +1,5 @@ +import { coin, coins, makeSignDoc, makeStdTx, CosmosClient, MsgDelegate, Secp256k1HdWallet } from "@cosmjs/launchpad"; + const wallet = await Secp256k1HdWallet.fromMnemonic( "enlist hip relief stomach skate base shallow young switch frequent cry park", ); diff --git a/packages/cli/examples/faucet_addresses.ts b/packages/cli/examples/faucet_addresses.ts index 604484e9..26946f69 100644 --- a/packages/cli/examples/faucet_addresses.ts +++ b/packages/cli/examples/faucet_addresses.ts @@ -1,3 +1,5 @@ +import { makeCosmoshubPath, Secp256k1HdWallet } from "@cosmjs/launchpad"; + 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"; diff --git a/packages/cli/examples/generate_address.ts b/packages/cli/examples/generate_address.ts index bb0787b6..ba9855b0 100644 --- a/packages/cli/examples/generate_address.ts +++ b/packages/cli/examples/generate_address.ts @@ -1,3 +1,5 @@ +import { encodeSecp256k1Pubkey, Secp256k1HdWallet } from "@cosmjs/launchpad"; + const mnemonic = Bip39.encode(Random.getBytes(16)).toString(); const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic); const [{ address, pubkey }] = await wallet.getAccounts(); diff --git a/packages/cli/examples/helpers.ts b/packages/cli/examples/helpers.ts index dce90d63..21e00680 100644 --- a/packages/cli/examples/helpers.ts +++ b/packages/cli/examples/helpers.ts @@ -1,6 +1,8 @@ import axios from "axios"; import * as fs from "fs"; +import { logs, GasPrice, Secp256k1HdWallet } from "@cosmjs/launchpad"; + interface Options { httpUrl: string; networkId: string; diff --git a/packages/cli/examples/local_faucet.ts b/packages/cli/examples/local_faucet.ts index 98f27217..afa4d960 100644 --- a/packages/cli/examples/local_faucet.ts +++ b/packages/cli/examples/local_faucet.ts @@ -1,3 +1,5 @@ +import { LcdClient, Secp256k1HdWallet, StdFee } from "@cosmjs/launchpad"; + const defaultHttpUrl = "http://localhost:1317"; const defaultNetworkId = "testing"; const defaultFee: StdFee = { diff --git a/packages/cli/examples/mask.ts b/packages/cli/examples/mask.ts index 7a36b0ba..7e02115a 100644 --- a/packages/cli/examples/mask.ts +++ b/packages/cli/examples/mask.ts @@ -1,3 +1,5 @@ +import { Coin } from "@cosmjs/launchpad"; + // types auto-generated by wasm.glass and cleaned up manually export type HandleMsg = | { diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 9c002601..e771217c 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -87,42 +87,6 @@ export async function main(originalArgs: readonly string[]): Promise { ["fromAscii", "fromBase64", "fromHex", "fromUtf8", "toAscii", "toBase64", "toHex", "toUtf8", "Bech32"], ], ["@cosmjs/faucet-client", ["FaucetClient"]], - [ - "@cosmjs/launchpad", - [ - "coin", - "coins", - "decodeAminoPubkey", - "decodeBech32Pubkey", - "encodeAminoPubkey", - "encodeBech32Pubkey", - "encodeSecp256k1Pubkey", - "encodeSecp256k1Signature", - "logs", - "makeCosmoshubPath", - "makeSignDoc", - "makeStdTx", - "IndexedTx", - "BroadcastTxResult", - "Coin", - "CosmosClient", - "GasLimits", - "GasPrice", - "Msg", - "MsgDelegate", - "MsgSend", - "LcdClient", - "OfflineSigner", - "PubKey", - "pubkeyToAddress", - "Secp256k1HdWallet", - "Secp256k1Wallet", - "SigningCosmosClient", - "StdFee", - "StdSignDoc", - "StdTx", - ], - ], ["@cosmjs/math", ["Decimal", "Int53", "Uint32", "Uint53", "Uint64"]], ["@cosmjs/utils", ["assert", "arrayContentEquals", "sleep"]], ]); @@ -144,6 +108,19 @@ export async function main(originalArgs: readonly string[]): Promise { import axios from "axios"; import * as fs from "fs"; + import { + coins, + encodeAminoPubkey, + encodeBech32Pubkey, + decodeBech32Pubkey, + decodeAminoPubkey, + makeCosmoshubPath, + makeSignDoc, + Secp256k1HdWallet, + Secp256k1Wallet, + StdFee, + } from "@cosmjs/launchpad"; + await sleep(123); const readmeContent = fs.readFileSync(process.cwd() + "/README.md"); From 2ec52455001134f495eee3e690885deb8b5b5523 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 10 Feb 2021 16:06:31 +0100 Subject: [PATCH 04/12] Do not auto-import @cosmjs/faucet-client types --- packages/cli/src/cli.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index e771217c..4c452104 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -86,7 +86,6 @@ export async function main(originalArgs: readonly string[]): Promise { "@cosmjs/encoding", ["fromAscii", "fromBase64", "fromHex", "fromUtf8", "toAscii", "toBase64", "toHex", "toUtf8", "Bech32"], ], - ["@cosmjs/faucet-client", ["FaucetClient"]], ["@cosmjs/math", ["Decimal", "Int53", "Uint32", "Uint53", "Uint64"]], ["@cosmjs/utils", ["assert", "arrayContentEquals", "sleep"]], ]); From fb59a0df9e378ecbc8f5cf37286eefbceef5ccad Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 10 Feb 2021 16:21:54 +0100 Subject: [PATCH 05/12] Do not auto-import @cosmjs/cosmwasm-launchpad types --- packages/cli/examples/coralnet.ts | 1 + packages/cli/examples/helpers.ts | 1 + packages/cli/src/cli.ts | 27 --------------------------- 3 files changed, 2 insertions(+), 27 deletions(-) diff --git a/packages/cli/examples/coralnet.ts b/packages/cli/examples/coralnet.ts index 3bb552ad..22954ded 100644 --- a/packages/cli/examples/coralnet.ts +++ b/packages/cli/examples/coralnet.ts @@ -1,3 +1,4 @@ +import { CosmWasmFeeTable, SigningCosmWasmClient } from "@cosmjs/cosmwasm-launchpad"; import { GasPrice, GasLimits, makeCosmoshubPath, Secp256k1HdWallet } from "@cosmjs/launchpad"; interface Options { diff --git a/packages/cli/examples/helpers.ts b/packages/cli/examples/helpers.ts index 21e00680..71dc967b 100644 --- a/packages/cli/examples/helpers.ts +++ b/packages/cli/examples/helpers.ts @@ -1,6 +1,7 @@ import axios from "axios"; import * as fs from "fs"; +import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-launchpad"; import { logs, GasPrice, Secp256k1HdWallet } from "@cosmjs/launchpad"; interface Options { diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 4c452104..00a628e7 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -36,33 +36,6 @@ export async function main(originalArgs: readonly string[]): Promise { .parse(originalArgs); const imports = new Map([ - [ - "@cosmjs/cosmwasm-launchpad", - [ - // cosmwasmclient - "Account", - "Block", - "BlockHeader", - "Code", - "CodeDetails", - "Contract", - "ContractCodeHistoryEntry", - "CosmWasmClient", - "GetSequenceResult", - "SearchByHeightQuery", - "SearchBySentFromOrToQuery", - "SearchByTagsQuery", - "SearchTxQuery", - "SearchTxFilter", - // signingcosmwasmclient - "ExecuteResult", - "CosmWasmFeeTable", - "InstantiateResult", - "SigningCosmWasmClient", - "UploadMeta", - "UploadResult", - ], - ], [ "@cosmjs/crypto", [ From 8e8011b6954e9a3ca0c33d7e965683e4ab555da2 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 10 Feb 2021 16:30:04 +0100 Subject: [PATCH 06/12] Do not auto-import types from @cosmjs/math and @cosmjs/utils --- packages/cli/src/cli.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 00a628e7..8bdec9dc 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -59,8 +59,6 @@ export async function main(originalArgs: readonly string[]): Promise { "@cosmjs/encoding", ["fromAscii", "fromBase64", "fromHex", "fromUtf8", "toAscii", "toBase64", "toHex", "toUtf8", "Bech32"], ], - ["@cosmjs/math", ["Decimal", "Int53", "Uint32", "Uint53", "Uint64"]], - ["@cosmjs/utils", ["assert", "arrayContentEquals", "sleep"]], ]); console.info(colors.green("Initializing session for you. Have fun!")); @@ -92,6 +90,8 @@ export async function main(originalArgs: readonly string[]): Promise { Secp256k1Wallet, StdFee, } from "@cosmjs/launchpad"; + import { Decimal } from "@cosmjs/math"; + import { assert, arrayContentEquals, sleep } from "@cosmjs/utils"; await sleep(123); From fbae7e2729abff09b170750b9411af0476f8c517 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 10 Feb 2021 16:43:07 +0100 Subject: [PATCH 07/12] Do not auto-import @cosmjs/encoding symbols --- packages/cli/examples/faucet_addresses.ts | 1 + packages/cli/examples/mask.ts | 1 + packages/cli/src/cli.ts | 15 +++++++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/cli/examples/faucet_addresses.ts b/packages/cli/examples/faucet_addresses.ts index 26946f69..78128815 100644 --- a/packages/cli/examples/faucet_addresses.ts +++ b/packages/cli/examples/faucet_addresses.ts @@ -1,3 +1,4 @@ +import { toBase64 } from "@cosmjs/encoding"; import { makeCosmoshubPath, Secp256k1HdWallet } from "@cosmjs/launchpad"; const mnemonic = diff --git a/packages/cli/examples/mask.ts b/packages/cli/examples/mask.ts index 7e02115a..caf9cf9f 100644 --- a/packages/cli/examples/mask.ts +++ b/packages/cli/examples/mask.ts @@ -1,3 +1,4 @@ +import { toBase64, toUtf8 } from "@cosmjs/encoding"; import { Coin } from "@cosmjs/launchpad"; // types auto-generated by wasm.glass and cleaned up manually diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 8bdec9dc..ad53374f 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -55,10 +55,6 @@ export async function main(originalArgs: readonly string[]): Promise { "Slip10RawIndex", ], ], - [ - "@cosmjs/encoding", - ["fromAscii", "fromBase64", "fromHex", "fromUtf8", "toAscii", "toBase64", "toHex", "toUtf8", "Bech32"], - ], ]); console.info(colors.green("Initializing session for you. Have fun!")); @@ -78,6 +74,17 @@ export async function main(originalArgs: readonly string[]): Promise { import axios from "axios"; import * as fs from "fs"; + import { + fromAscii, + fromBase64, + fromHex, + fromUtf8, + toAscii, + toBase64, + toHex, + toUtf8, + Bech32, + } from "@cosmjs/encoding"; import { coins, encodeAminoPubkey, From 7582199ea927c5283dd8c6e8eabe70834bb718fe Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 10 Feb 2021 16:56:01 +0100 Subject: [PATCH 08/12] Do not auto-import types from @cosmjs/crypto --- packages/cli/examples/coralnet.ts | 1 + packages/cli/examples/generate_address.ts | 1 + packages/cli/examples/helpers.ts | 1 + packages/cli/src/cli.ts | 23 ++--------------------- 4 files changed, 5 insertions(+), 21 deletions(-) diff --git a/packages/cli/examples/coralnet.ts b/packages/cli/examples/coralnet.ts index 22954ded..f1fc9cc2 100644 --- a/packages/cli/examples/coralnet.ts +++ b/packages/cli/examples/coralnet.ts @@ -1,3 +1,4 @@ +import { HdPath } from "@cosmjs/crypto"; import { CosmWasmFeeTable, SigningCosmWasmClient } from "@cosmjs/cosmwasm-launchpad"; import { GasPrice, GasLimits, makeCosmoshubPath, Secp256k1HdWallet } from "@cosmjs/launchpad"; diff --git a/packages/cli/examples/generate_address.ts b/packages/cli/examples/generate_address.ts index ba9855b0..21914d2e 100644 --- a/packages/cli/examples/generate_address.ts +++ b/packages/cli/examples/generate_address.ts @@ -1,3 +1,4 @@ +import { Bip39, Random } from "@cosmjs/crypto"; import { encodeSecp256k1Pubkey, Secp256k1HdWallet } from "@cosmjs/launchpad"; const mnemonic = Bip39.encode(Random.getBytes(16)).toString(); diff --git a/packages/cli/examples/helpers.ts b/packages/cli/examples/helpers.ts index 71dc967b..8b229e7f 100644 --- a/packages/cli/examples/helpers.ts +++ b/packages/cli/examples/helpers.ts @@ -1,6 +1,7 @@ import axios from "axios"; import * as fs from "fs"; +import { Bip39, Random } from "@cosmjs/crypto"; import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-launchpad"; import { logs, GasPrice, Secp256k1HdWallet } from "@cosmjs/launchpad"; diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index ad53374f..ce3a6598 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -35,27 +35,7 @@ export async function main(originalArgs: readonly string[]): Promise { .group(["debug", "selftest"], "Maintainer options") .parse(originalArgs); - const imports = new Map([ - [ - "@cosmjs/crypto", - [ - "Bip39", - "Ed25519", - "Ed25519Keypair", - "EnglishMnemonic", - "HdPath", - "Random", - "Secp256k1", - "Sha256", - "sha256", - "Sha512", - "sha512", - "Slip10", - "Slip10Curve", - "Slip10RawIndex", - ], - ], - ]); + const imports = new Map([]); console.info(colors.green("Initializing session for you. Have fun!")); console.info(colors.yellow("Available imports:")); @@ -85,6 +65,7 @@ export async function main(originalArgs: readonly string[]): Promise { toUtf8, Bech32, } from "@cosmjs/encoding"; + import { sha512, Bip39, Random } from "@cosmjs/crypto"; import { coins, encodeAminoPubkey, From ed26010b6b98dffe7e42150e3472ef675e327218 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 10 Feb 2021 16:57:34 +0100 Subject: [PATCH 09/12] Remove auto-import infrastructure --- packages/cli/src/cli.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index ce3a6598..0bfb1f30 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -35,19 +35,9 @@ export async function main(originalArgs: readonly string[]): Promise { .group(["debug", "selftest"], "Maintainer options") .parse(originalArgs); - const imports = new Map([]); - console.info(colors.green("Initializing session for you. Have fun!")); - console.info(colors.yellow("Available imports:")); - for (const [moduleName, symbols] of imports.entries()) { - console.info(colors.yellow(` * from ${moduleName}: ${symbols.join(", ")}`)); - } let init = ""; - for (const [moduleName, symbols] of imports.entries()) { - init += `import { ${symbols.join(", ")} } from "${moduleName}";\n`; - } - if (args.selftest) { // execute some trival stuff and exit init += ` From fe0c3d441ebb7964ecd0cf6fc899822f5981ad08 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 10 Feb 2021 17:17:27 +0100 Subject: [PATCH 10/12] Document installed packages --- packages/cli/src/cli.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 0bfb1f30..97d0c36d 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -7,6 +7,20 @@ import { TsRepl } from "./tsrepl"; import colors = require("colors/safe"); +export async function installedPackages(): Promise { + return new Promise((resolve, reject) => { + fs.readFile(__dirname + "/../package.json", { encoding: "utf8" }, (error, data) => { + if (error) { + reject(error); + } else { + const packagejson = JSON.parse(data); + const deps = Object.keys(packagejson.dependencies).sort(); + resolve(deps); + } + }); + }); +} + export async function main(originalArgs: readonly string[]): Promise { const args = yargs .options({ @@ -36,6 +50,11 @@ export async function main(originalArgs: readonly string[]): Promise { .parse(originalArgs); console.info(colors.green("Initializing session for you. Have fun!")); + const visiblePackages = (await installedPackages()).filter( + (name) => name.startsWith("@cosmjs/") || name === "axios", + ); + console.info(colors.yellow("The following packages have been installed and can be imported:")); + console.info(colors.yellow(visiblePackages.join(", "))); let init = ""; if (args.selftest) { From 2feb94e952c5326277ae05a1f28a95a3c1d09449 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 11 Feb 2021 15:14:56 +0100 Subject: [PATCH 11/12] Install stargate packages in CLI --- packages/cli/package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/cli/package.json b/packages/cli/package.json index cc471cab..a972eb46 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -40,11 +40,15 @@ ], "dependencies": { "@cosmjs/cosmwasm-launchpad": "^0.24.0-alpha.24", + "@cosmjs/cosmwasm-stargate": "^0.24.0-alpha.24", "@cosmjs/crypto": "^0.24.0-alpha.24", "@cosmjs/encoding": "^0.24.0-alpha.24", "@cosmjs/faucet-client": "^0.24.0-alpha.24", "@cosmjs/launchpad": "^0.24.0-alpha.24", "@cosmjs/math": "^0.24.0-alpha.24", + "@cosmjs/proto-signing": "^0.24.0-alpha.24", + "@cosmjs/stargate": "^0.24.0-alpha.24", + "@cosmjs/tendermint-rpc": "^0.24.0-alpha.24", "@cosmjs/utils": "^0.24.0-alpha.24", "axios": "^0.21.1", "babylon": "^6.18.0", From 1ee39167dec9f9646bac9ae7e3706e3901d93a59 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 11 Feb 2021 15:56:29 +0100 Subject: [PATCH 12/12] 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