or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

abi.mdcontracts.mdcrypto.mdindex.mdproviders.mdutils.mdwallets.md
tile.json

wallets.mddocs/

Wallets and Signers

Wallets and signers manage Ethereum accounts and provide transaction signing capabilities. They support various key management methods including private keys, mnemonic phrases, HD wallets, and JSON keystores.

Capabilities

Basic Wallet

Create and manage Ethereum accounts using private keys with full transaction signing support.

/**
 * Basic wallet implementation for private key management and transaction signing
 */
class Wallet extends BaseWallet {
  constructor(key: string | SigningKey, provider?: Provider);
  
  readonly address: string;
  readonly privateKey: string;
  readonly publicKey: string;
  
  // Account creation
  static createRandom(provider?: Provider): Wallet;
  static fromPhrase(phrase: string, password?: string, provider?: Provider): Wallet;
  
  // Provider connection
  connect(provider: Provider): Wallet;
  
  // Signing operations
  signMessage(message: string | Uint8Array): Promise<string>;
  signTransaction(transaction: TransactionRequest): Promise<string>;
  signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataField[]>, value: Record<string, any>): Promise<string>;
  
  // Transaction operations
  sendTransaction(transaction: TransactionRequest): Promise<TransactionResponse>;
  
  // Encryption/decryption
  encrypt(password: string, options?: EncryptOptions): Promise<string>;
  static fromEncryptedJson(json: string, password: string, progress?: ProgressCallback): Promise<Wallet>;
  static fromEncryptedJsonSync(json: string, password: string): Wallet;
}

Usage Examples:

import { Wallet, JsonRpcProvider } from "ethers";

// Create wallet from private key
const wallet = new Wallet("0x...", provider);

// Create random wallet
const randomWallet = Wallet.createRandom();

// Create from mnemonic phrase
const mnemonicWallet = Wallet.fromPhrase("word1 word2 ... word12");

// Sign a message
const signature = await wallet.signMessage("Hello, Ethereum!");

// Send transaction
const tx = await wallet.sendTransaction({
  to: "0x...",
  value: ethers.parseEther("1.0")
});

HD Node Wallet

Hierarchical Deterministic (HD) wallet implementation supporting BIP-32/BIP-44 key derivation.

/**
 * HD wallet supporting BIP-32/BIP-44 hierarchical key derivation
 */
class HDNodeWallet extends BaseWallet {
  readonly address: string;
  readonly privateKey: string;
  readonly publicKey: string;
  readonly chainCode: string;
  readonly path?: string;
  readonly index: number;
  readonly depth: number;
  
  // Wallet creation
  static fromPhrase(phrase: string, password?: string, path?: string, provider?: Provider): HDNodeWallet;
  static fromSeed(seed: BytesLike): HDNodeWallet;
  static fromExtendedKey(extendedKey: string): HDNodeWallet;
  
  // Key derivation
  derivePath(path: string): HDNodeWallet;
  deriveChild(index: number): HDNodeWallet;
  
  // Extended keys
  get extendedKey(): string;
  get neuter(): HDNodeWallet;
}

/**
 * Read-only version of HDNodeWallet for public key operations only
 */
class HDNodeVoidWallet extends VoidSigner {
  readonly address: string;
  readonly publicKey: string;
  readonly chainCode: string;
  readonly path?: string;
  readonly index: number;
  readonly depth: number;
  
  derivePath(path: string): HDNodeVoidWallet;
  deriveChild(index: number): HDNodeVoidWallet;
}

Usage Examples:

import { HDNodeWallet } from "ethers";

// Create HD wallet from mnemonic
const hdWallet = HDNodeWallet.fromPhrase("word1 word2 ... word24");

// Derive specific account
const account0 = hdWallet.derivePath("m/44'/60'/0'/0/0");
const account1 = hdWallet.derivePath("m/44'/60'/0'/0/1");

// Derive child wallets
const childWallet = hdWallet.deriveChild(0);

Mnemonic Phrase Management

BIP-39 mnemonic phrase utilities for secure seed phrase generation and validation.

/**
 * BIP-39 mnemonic phrase management for secure seed generation
 */
class Mnemonic {
  readonly phrase: string;
  readonly password: string;
  readonly wordlist: Wordlist;
  readonly entropy: string;
  
  constructor(guard: any, entropy: string, phrase: string, password?: string, wordlist?: Wordlist);
  
  // Mnemonic creation
  static fromPhrase(phrase: string, password?: string, wordlist?: Wordlist): Mnemonic;
  static fromEntropy(entropy: BytesLike, password?: string, wordlist?: Wordlist): Mnemonic;
  
  // Seed computation
  computeSeed(): string;
  
  // Validation
  static isValidMnemonic(phrase: string, wordlist?: Wordlist): boolean;
  
  // Entropy generation
  static entropyToMnemonic(entropy: BytesLike, wordlist?: Wordlist): string;
  static mnemonicToEntropy(mnemonic: string, wordlist?: Wordlist): string;
}

Wordlists for BIP-39 Mnemonics

Wordlists provide language-specific word collections for BIP-39 mnemonic phrase generation and validation. Each wordlist contains exactly 2048 words used to encode entropy into human-readable phrases.

/**
 * Abstract base class for all wordlists
 */
abstract class Wordlist {
  readonly locale: string;
  
  constructor(locale: string);
  
  // Split phrase into words (language-specific)
  split(phrase: string): Array<string>;
  
  // Join words into phrase (language-specific)
  join(words: Array<string>): string;
  
  // Get word at specific index (0-2047)
  abstract getWord(index: number): string;
  
  // Get index of specific word
  abstract getWordIndex(word: string): number;
}

/**
 * English wordlist implementation (recommended for compatibility)
 */
class LangEn extends Wordlist {
  static wordlist(): Wordlist;
}

/**
 * Optimized wordlist implementation using compression
 */
class WordlistOwl extends Wordlist {
  constructor(locale: string, data: string, checksum: string);
}

/**
 * Alternative optimized wordlist implementation
 */
class WordlistOwlA extends Wordlist {
  constructor(locale: string, data: string, checksum: string);
}

/**
 * Registry of available wordlists by ISO 639-1 language codes
 */
const wordlists: Record<string, Wordlist>;

Available Languages:

  • cz - Czech
  • en - English (recommended)
  • es - Spanish
  • fr - French
  • it - Italian
  • ja - Japanese
  • ko - Korean
  • pt - Portuguese
  • zh_cn - Chinese (Simplified)
  • zh_tw - Chinese (Traditional)

Usage Examples:

import { 
  wordlists, 
  LangEn, 
  Mnemonic, 
  HDNodeWallet 
} from "ethers";

// Use English wordlist (default and recommended)
const englishWordlist = wordlists.en;
const phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";

// Validate mnemonic with specific wordlist
const isValid = Mnemonic.isValidMnemonic(phrase, englishWordlist);

// Create mnemonic with specific wordlist
const mnemonic = Mnemonic.fromPhrase(phrase, "password", englishWordlist);

// Generate entropy and convert to mnemonic
const entropy = "0x133755ff"; // 128 bits minimum
const mnemonicPhrase = Mnemonic.entropyToMnemonic(entropy, wordlists.en);

// Use different languages
const frenchWordlist = wordlists.fr;
const spanishWordlist = wordlists.es;

// Create wallet with specific wordlist  
const hdWallet = HDNodeWallet.fromPhrase(phrase, "password", "m/44'/60'/0'/0/0", frenchWordlist);

// Working with wordlist directly
const wordAtIndex = englishWordlist.getWord(0); // "abandon"
const indexOfWord = englishWordlist.getWordIndex("abandon"); // 0

// Split and join operations (language-specific)
const words = englishWordlist.split("word1 word2 word3");
const rejoined = englishWordlist.join(words);

Notes:

  • English wordlist is recommended for maximum compatibility
  • Each wordlist contains exactly 2048 words (2^11) for 11-bit encoding
  • Distribution builds may exclude non-English wordlists to reduce size
  • Use wordlists-extra.min.js if you need additional languages in distribution builds

Keystore JSON Support

Import and export wallets using encrypted JSON keystore format (UTC/JSON).

/**
 * Check if a string is a valid keystore JSON format
 */
function isKeystoreJson(json: string): boolean;

/**
 * Decrypt a keystore JSON synchronously
 */
function decryptKeystoreJsonSync(json: string, password: string): KeystoreAccount;

/**
 * Decrypt a keystore JSON asynchronously with progress callback
 */
function decryptKeystoreJson(json: string, password: string, progress?: ProgressCallback): Promise<KeystoreAccount>;

/**
 * Encrypt a keystore JSON synchronously
 */
function encryptKeystoreJsonSync(account: KeystoreAccount, password: string, options?: EncryptOptions): string;

/**
 * Encrypt a keystore JSON asynchronously with progress callback
 */
function encryptKeystoreJson(account: KeystoreAccount, password: string, options?: EncryptOptions, progress?: ProgressCallback): Promise<string>;

interface KeystoreAccount {
  address: string;
  privateKey: string;
}

interface EncryptOptions {
  iv?: BytesLike;
  entropy?: BytesLike;
  client?: string;
  salt?: BytesLike;
  uuid?: string;
  scrypt?: {
    N?: number;
    r?: number;
    p?: number;
  };
}

Crowdsale Wallet Support

Support for Ethereum crowdsale wallet format from the early Ethereum days.

/**
 * Check if a string is a valid crowdsale JSON format
 */
function isCrowdsaleJson(json: string): boolean;

/**
 * Decrypt a crowdsale JSON wallet
 */
function decryptCrowdsaleJson(json: string, password: string): CrowdsaleAccount;

interface CrowdsaleAccount {
  address: string;
  privateKey: string;
}

Signing Key Management

Low-level cryptographic key management for ECDSA operations.

/**
 * ECDSA signing key for cryptographic operations
 */
class SigningKey {
  constructor(privateKey: BytesLike);
  
  readonly privateKey: string;
  readonly publicKey: string;
  readonly compressedPublicKey: string;
  readonly address: string;
  
  // Signing operations
  sign(digest: BytesLike): Signature;
  
  // Key computation
  computeSharedSecret(otherKey: BytesLike): string;
  
  // Static utilities
  static computePublicKey(key: BytesLike, compressed?: boolean): string;
  static recoverPublicKey(digest: BytesLike, signature: SignatureLike): string;
  static addPoints(p0: BytesLike, p1: BytesLike, compressed?: boolean): string;
}

JSON-RPC Signer

Signer implementation that delegates signing operations to a JSON-RPC provider (like MetaMask).

/**
 * Signer that delegates operations to a JSON-RPC provider
 */
class JsonRpcSigner extends AbstractSigner {
  constructor(provider: JsonRpcApiProvider, address: string);
  
  // Account information
  getAddress(): Promise<string>;
  
  // Signing operations
  signMessage(message: string | Uint8Array): Promise<string>;
  signTransaction(transaction: TransactionRequest): Promise<string>;
  signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataField[]>, value: Record<string, any>): Promise<string>;
  
  // Transaction operations
  sendTransaction(transaction: TransactionRequest): Promise<TransactionResponse>;
  
  // Provider connection
  connect(provider: Provider): JsonRpcSigner;
}

Void Signer

Read-only signer for operations that don't require private key access.

/**
 * Read-only signer for operations without private key access
 */
class VoidSigner extends AbstractSigner {
  constructor(address: string, provider?: Provider);
  
  readonly address: string;
  
  // Account information
  getAddress(): Promise<string>;
  
  // Signing operations (will throw)
  signMessage(message: string | Uint8Array): Promise<string>;
  signTransaction(transaction: TransactionRequest): Promise<string>;
  signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataField[]>, value: Record<string, any>): Promise<string>;
  
  // Provider connection
  connect(provider: Provider): VoidSigner;
}

HD Wallet Path Utilities

Utilities for working with BIP-44 derivation paths.

/**
 * Default BIP-44 derivation path for Ethereum accounts
 */
const defaultPath: string; // "m/44'/60'/0'/0/0"

/**
 * Get BIP-44 derivation path for a specific account index
 */
function getAccountPath(index: number): string;

/**
 * Get indexed account path (alias for getAccountPath)
 */
function getIndexedAccountPath(index: number): string;

Usage Examples:

import { defaultPath, getAccountPath, HDNodeWallet } from "ethers";

console.log(defaultPath); // "m/44'/60'/0'/0/0"
console.log(getAccountPath(5)); // "m/44'/60'/0'/0/5"

// Use with HD wallet
const hdWallet = HDNodeWallet.fromPhrase("word1 word2 ... word12");
const account5 = hdWallet.derivePath(getAccountPath(5));

Types

type ProgressCallback = (percent: number) => void;

interface TypedDataDomain {
  name?: string;
  version?: string;
  chainId?: BigNumberish;
  verifyingContract?: string;
  salt?: BytesLike;
}

interface TypedDataField {
  name: string;
  type: string;
}