Skip to content

Instantly share code, notes, and snippets.

@13x54n
Created June 23, 2023 07:16
Show Gist options
  • Save 13x54n/8fb35c0625adeaa34074370f3fc95f8a to your computer and use it in GitHub Desktop.
Save 13x54n/8fb35c0625adeaa34074370f3fc95f8a to your computer and use it in GitHub Desktop.
Wallet Creation and Import on React using ethers.
const handleImportWallet = (_type) => {
if (_type === "privateKey") {
const _wallet = new ethers.Wallet(privateKey);
setWallet(_wallet);
} else if (_type === "mnemonic") {
const _wallet = ethers.HDNodeWallet.fromPhrase(mnemonic);
// @dev we can import users many accounts
// const secondAccount = _wallet.derivePath(`m/44'/60'/0'/0/1`);
// const thirdAccount = _wallet.derivePath(`m/44'/60'/0'/0/2`);
setWallet(_wallet);
}
};
const handleCreateWallet = () => {
const _wallet = ethers.Wallet.createRandom();
setWallet(_wallet);
setWalletStatus("password");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment