Ethereum wallet creation and recovery

const seedPhrase = await bip39.generateMnemonic(128);
const hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(seedPhrase));
const wallet = hdwallet.derivePath(path).getWallet();
import Wallet from 'ethereumjs-wallet';
const wallet = Wallet.generate();
import bip39 from 'react-native-bip39'
import { hdkey } from 'ethereumjs-wallet';
const seedPhrase = await bip39.generateMnemonic(128);
console.log(seedPhrase)
// generate hdwallet from seed phrase
const hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(seedPhrase));

// from BIP44, HD derivation path is:
// m / purpose’ / coin_type’ / account’ / change / address_index
const path = “m/44'/60'/0'/0/0”;
const wallet = hdwallet.derivePath(path).getWallet();
console.log(“privateKey: “ + wallet.getPrivateKeyString());
console.log(“address: “ + wallet.getAddressString());
// split seed phrase string to seed phrase array of strings
const seedPhraseList = seedPhrase.split(“ “);
const { isValidMnemonic } = ethers.utils;
isValidMnemonic(seedPhrase);
const hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(seedPhrase));
import { ethers } from 'ethers';
import bip39 from 'react-native-bip39';
import { hdkey } from 'ethereumjs-wallet';
const { isValidMnemonic } = ethers.utils;const validResult = isValidMnemonic(seedPhrase);// generate hdwallet from seed phrase
const hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(seedPhrase));
// from BIP44, HD derivation path is:
// m / purpose’ / coin_type’ / account’ / change / address_index
const path = “m/44'/60'/0'/0/0”;
const wallet = hdwallet.derivePath(path).getWallet();
console.log(`privateKey: ${ wallet.getPrivateKeyString()}`);
console.log(`address: ${ wallet.getAddressString()}`);

--

--

--

Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Create a MEAN Web App in 5 Minutes

5 VSCode Themes Every Developer Must Try in 2021

Understanding the Importance of the key prop in React

Typical TypeScript: Using Unions to Enforce Inputs

Configuring a loading bar for Angular 9 application

Integrating Google Maps in a React application

JSS By The Numbers — Mid 2018 Edition

End-To-End Testing Using Cypress

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Victor Yeo

Victor Yeo

Engineer

More from Medium

Blockchain Innovations for Africa by Africans: Introducing the Africoin Project

Atossa — Next-generation of crypto trading platform

An Introduction to the Andre Cronje Ecosystem

Web 3.0 Versus Web 2.0