From 580b417b70a8ea37e466766aaf40dd5674b8410e Mon Sep 17 00:00:00 2001 From: willclarktech Date: Tue, 20 Apr 2021 17:53:33 +0200 Subject: [PATCH] cli: Update examples for new Secp256k1HdWallet options --- packages/cli/examples/coralnet.ts | 6 +++--- packages/cli/examples/faucet_addresses.ts | 10 ++++++---- packages/cli/examples/stargate.ts | 14 ++++++++------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/cli/examples/coralnet.ts b/packages/cli/examples/coralnet.ts index f1fc9cc2..9aaa73de 100644 --- a/packages/cli/examples/coralnet.ts +++ b/packages/cli/examples/coralnet.ts @@ -5,7 +5,7 @@ import { GasPrice, GasLimits, makeCosmoshubPath, Secp256k1HdWallet } from "@cosm interface Options { readonly httpUrl: string; readonly bech32prefix: string; - readonly hdPath: HdPath; + readonly hdPaths: readonly HdPath[]; readonly gasPrice: GasPrice; readonly gasLimits: Partial>; // only set the ones you want to override } @@ -14,13 +14,13 @@ const coralnetOptions: Options = { httpUrl: "https://lcd.coralnet.cosmwasm.com", gasPrice: GasPrice.fromString("0.025ushell"), bech32prefix: "coral", - hdPath: makeCosmoshubPath(0), + hdPaths: [makeCosmoshubPath(0)], gasLimits: { upload: 1500000, }, }; -const wallet = await Secp256k1HdWallet.generate(12, coralnetOptions.hdPath, coralnetOptions.bech32prefix); +const wallet = await Secp256k1HdWallet.generate(12, coralnetOptions); const [{ address }] = await wallet.getAccounts(); const client = new SigningCosmWasmClient( diff --git a/packages/cli/examples/faucet_addresses.ts b/packages/cli/examples/faucet_addresses.ts index af88efb0..57efc874 100644 --- a/packages/cli/examples/faucet_addresses.ts +++ b/packages/cli/examples/faucet_addresses.ts @@ -4,9 +4,11 @@ import { toBase64 } from "@cosmjs/encoding"; 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"; -for (let i of [0, 1, 2, 3, 4]) { - const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic, { hdPath: makeCosmoshubPath(i) }); - const [{ address, pubkey }] = await wallet.getAccounts(); +const accountNumbers = [0, 1, 2, 3, 4]; +const hdPaths = accountNumbers.map(makeCosmoshubPath); +const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic, { hdPaths: hdPaths }); +const accounts = await wallet.getAccounts(); +accounts.forEach(({ address, pubkey }, i) => { console.info(`Address ${i}: ${address}`); console.info(`Pubkey ${i}: ${toBase64(pubkey)}`); -} +}); diff --git a/packages/cli/examples/stargate.ts b/packages/cli/examples/stargate.ts index f4577461..129c827a 100644 --- a/packages/cli/examples/stargate.ts +++ b/packages/cli/examples/stargate.ts @@ -1,12 +1,14 @@ -import { makeCosmoshubPath, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; +import { makeCosmoshubPath } from "@cosmosjs/amino"; +import { 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 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 wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { hdPaths: [path], prefix: prefix }); +const [account] = await wallet.getAccounts(); +console.log("Signer address:", account.address); const rpcEndpoint = "ws://localhost:26658"; const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet); @@ -16,7 +18,7 @@ const amount = { denom: "ucosm", amount: "1234567", }; -const result = await client.sendTokens(firstAccount.address, recipient, [amount], "Have fun with your star coins"); +const result = await client.sendTokens(account.address, recipient, [amount], "Have fun with your star coins"); assertIsBroadcastTxSuccess(result); console.log("Successfully broadcasted:", result);