Skip to content

Instantly share code, notes, and snippets.

@daoka
Created May 15, 2019 01:25
Show Gist options
  • Save daoka/18b0ca7734b1d8311447d522cf222acd to your computer and use it in GitHub Desktop.
Save daoka/18b0ca7734b1d8311447d522cf222acd to your computer and use it in GitHub Desktop.
nem2-hd-wallets test
import { MnemonicPassPhrase, ExtendedKey, Network, Wallet } from 'nem2-hd-wallets';
const mnemonic = MnemonicPassPhrase.createRandom();
console.log(mnemonic);
const bip32seed = mnemonic.toEntropy();
console.log(`seed: ${bip32seed}`);
const xKey = ExtendedKey.createFromSeed(bip32seed);
console.log(`xkey: ${xKey.toBase58()}`);
const wallet = new Wallet(xKey);
const masterAccount = wallet.getAccount();
console.log(`masterAddr: ${masterAccount.address.plain()}`);
const c0Account = wallet.getChildAccount('m/44\'/43\'/0\'/0\'/0\'');
console.log(`c0Addr: ${c0Account.address.plain()}`);
const c1Account = wallet.getChildAccount('m/44\'/43\'/1\'/0\'/0\'');
console.log(`c1Addr: ${c1Account.address.plain()}`);
const c0_1Account = wallet.getChildAccount('m/44\'/43\'/0\'/1\'/0\'');
console.log(`c0_1Addr: ${c0_1Account.address.plain()}`);
MnemonicPassPhrase {
  plain:
   'belt release family when top midnight apart birth claim decade scrub suffer borrow observe slogan arm mouse desert warm mixed pond account soft deliver' }
seed: 14f6a54a7d1e4f18c290b529a713076c51a130f2f85d90a777dcc71a7c033391
xkey: xprv9s21ZrQH143K2QXF9LPWQXR5TS1cdh1daaidRCuZsRL1aoA84EuDvmHzwdf8MkjJvHLgizNM9VbzytrgfKvDKcXw25vz6rs5BzaUhBuhFQZ
masterAddr: SBAJ3SXZQ6D2BELUOGNEUUB7RMM37KMXM34GI555
c0Addr: SB3NQOGPLNCL77QRNZHZ2CUSLK4GP6PTOJMYNXOP
c1Addr: SDGNSKIFXGTPUAHF7LIMH5SSHSJIFVZ5BUJP2DG3
c0_1Addr: SBQK3GPVSA4QOEHPR57ZAUDOV6DTMHRUSN4DWG3L
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment