cli: Update examples for new Secp256k1HdWallet options
This commit is contained in:
parent
c0c8061ab1
commit
580b417b70
@ -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<GasLimits<CosmWasmFeeTable>>; // 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(
|
||||
|
||||
@ -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)}`);
|
||||
}
|
||||
});
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user