Skip to main content

Overview

LocalWallet handles cryptographic key management and transaction signing for the LFG SDK.
import { LocalWallet } from "@oraichain/lfg-client-js";

Static Methods

fromMnemonic()

Create a wallet from a BIP39 mnemonic phrase.
const wallet = await LocalWallet.fromMnemonic(
  "your twelve word mnemonic phrase goes here",
  "lfg"
);
mnemonic
string
required
12 or 24-word BIP39 mnemonic phrase
prefix
string
required
Address prefix (use "lfg" for LFG DEX)
Returns: Promise<LocalWallet>

fromPrivateKey()

Create a wallet from a private key.
const wallet = await LocalWallet.fromPrivateKey("0xYourPrivateKeyHex", "lfg");
privateKey
string
required
Private key as hex string (with or without 0x prefix)
prefix
string
required
Address prefix (use "lfg")
Returns: Promise<LocalWallet>

Properties

address

The wallet’s public address.
console.log(wallet.address); // "lfg1..."
Type: string

pubKey

The wallet’s public key.
console.log(wallet.pubKey?.value); // Public key bytes
Type: PubKey | undefined

Usage Examples

Environment Variables

// From mnemonic
const wallet = await LocalWallet.fromMnemonic(process.env.MNEMONIC!, "lfg");

// From private key
const wallet = await LocalWallet.fromPrivateKey(
  process.env.PRIVATE_KEY!,
  "lfg"
);

Wallet Factory

async function createWallet(): Promise<LocalWallet> {
  if (process.env.MNEMONIC) {
    return await LocalWallet.fromMnemonic(process.env.MNEMONIC, "lfg");
  } else if (process.env.PRIVATE_KEY) {
    return await LocalWallet.fromPrivateKey(process.env.PRIVATE_KEY, "lfg");
  }
  throw new Error("No wallet credentials found");
}
Never commit private keys or mnemonics to version control. Always use environment variables or secure secret management.