Created
June 23, 2023 07:16
-
-
Save 13x54n/8fb35c0625adeaa34074370f3fc95f8a to your computer and use it in GitHub Desktop.
Wallet Creation and Import on React using ethers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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