Direct Signing (recommended)
Amino Signing
OfflineSigner and can be passed directly to
SigningStargateClient:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Create and manage HD wallets from mnemonic phrases with CosmJS
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
"your twelve or twenty-four word mnemonic phrase ...",
{ prefix: "cosmos" },
);
const [{ address }] = await wallet.getAccounts();
import { Secp256k1HdWallet } from "@cosmjs/amino";
const wallet = await Secp256k1HdWallet.fromMnemonic(
"your twelve or twenty-four word mnemonic phrase ...",
{ prefix: "cosmos" },
);
OfflineSigner and can be passed directly to
SigningStargateClient:
import { SigningStargateClient, GasPrice } from "@cosmjs/stargate";
const client = await SigningStargateClient.connectWithSigner(
"https://rpc.my-chain.network",
wallet,
{ gasPrice: GasPrice.fromString("0.025uatom") },
);
const result = await client.sendTokens(
address,
"cosmos1recipient...",
[{ denom: "uatom", amount: "1000000" }],
"auto",
);
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
const wallet = await DirectSecp256k1HdWallet.generate(24, {
prefix: "cosmos",
});
const mnemonic = wallet.mnemonic;
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { makeCosmoshubPath } from "@cosmjs/amino";
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: "cosmos",
hdPaths: [makeCosmoshubPath(0), makeCosmoshubPath(1), makeCosmoshubPath(2)],
});
const accounts = await wallet.getAccounts();
// Three different addresses, all derived from the same mnemonic
serialize() and deserialize() methods are deprecated and will be removed in a future version of CosmJS. If you rely on this feature, comment at cosmos/cosmjs#1796.const encrypted = await wallet.serialize("strong-password");
// Store `encrypted` in a database or file
const restored = await DirectSecp256k1HdWallet.deserialize(
encrypted,
"strong-password",
);
Was this page helpful?