Setting up Cosmos signer

import { SigningStargateClient, DeliverTxResponse } from "@cosmjs/stargate";
import {
  DirectSecp256k1HdWallet,
  OfflineDirectSigner,
} from "@cosmjs/proto-signing";

const mnemonic = "<your_mnemonic>";
const rpc = "<cosmos-node-rpc>" // the sdk when initialised has the squid.chains object which has the rpc's for each chain

const getSignerFromMnemonic = async (): Promise<OfflineDirectSigner> => {
  return DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
    prefix: "<chain-bech32-prefix>",
  });
};
const offlineSigner: OfflineDirectSigner = await getSignerFromMnemonic();

const signerAddress = (await offlineSigner.getAccounts())[0].address;

const signer = await SigningStargateClient.connectWithSigner(
  rpc,
  offlineSigner
);

Last updated