Skip to Content
Playground@wallet · Mnemonic

HD Wallet / Mnemonic

Generate BIP-39 mnemonics and derive hierarchical-deterministic accounts for both Conflux eSpace and Core Space. All crypto happens in-browser via @scure/bip39 and @scure/bip32.

network:Testnet· chain 71
import { generateMnemonic, validateMnemonic, deriveAccounts, deriveAccount } from '@cfxdevkit/core'

// 1. Generate BIP-39 mnemonic phrases
const mnemonic   = generateMnemonic()      // 12 words (128-bit entropy)
const mnemonic24 = generateMnemonic(256)   // 24 words (256-bit entropy)

console.log('-- 12-word mnemonic --')
console.log(mnemonic)
console.log('-- 24-word mnemonic --')
console.log(mnemonic24)

// 2. Validate a mnemonic
const v = validateMnemonic(mnemonic)
console.log('-- Validation --')
console.log('valid  : ' + v.valid)
console.log('words  : ' + v.wordCount)

const bad = validateMnemonic('this is not a valid bip39 phrase at all')
console.log('bad    : valid=' + bad.valid + '  words=' + bad.wordCount)

// 3. Derive multiple HD wallet accounts
// Each account has both an eSpace (EVM) and Core Space address
const accounts = deriveAccounts(mnemonic, { count: 3 })
console.log('-- Derived Accounts (first 3) --')
for (const a of accounts) {
console.log('[' + a.index + '] eSpace : ' + a.evmAddress)
console.log('    Core   : ' + a.coreAddress)
}

// 4. Single account at a specific index
const acc5 = deriveAccount(mnemonic, 5)
console.log('-- Account at index 5 --')
console.log('eSpace path : ' + acc5.paths.evm)
console.log('Core   path : ' + acc5.paths.core)
console.log('eSpace addr : ' + acc5.evmAddress)
console.log('Core   addr : ' + acc5.coreAddress)


How it works

  1. generateMnemonic() uses @scure/bip39 — browser-safe, audited BIP-39 library.
  2. validateMnemonic(phrase) checks word count (12 or 24) and BIP-39 checksum validity.
  3. deriveAccounts(mnemonic, { count }) follows BIP-44: eSpace coin type 60 (Ethereum path), Core Space coin type 503 (Conflux path).
  4. Both addresses come from the same mnemonic but different derivation paths — they are cryptographically linked.
  5. Private keys (a.evmPrivateKey, a.corePrivateKey) are available on each account for signing.
// @cfxdevkit/wallet is a focused re-export from @cfxdevkit/core import { generateMnemonic, deriveAccounts } from '@cfxdevkit/wallet'
Last updated on