web3dart icon indicating copy to clipboard operation
web3dart copied to clipboard

Get wallet from seed phrase

Open JAtoms opened this issue 3 years ago • 3 comments

I'd like to know if we can get a wallet using seed phrases from a different wallet.

JAtoms avatar Jul 28 '22 02:07 JAtoms

Got the same issue, I use bip39 lib but after I get wrong address (not the same that I see in metamask for example). Do you have any information about that @xclud

alexandrebottero avatar Jul 29 '22 14:07 alexandrebottero

Until we can do it with web3dart, this is how i do it:

I used 2 libs:

  • bip39 (https://pub.dev/packages/bip39)
  • ethers (https://pub.dev/packages/ethers)

Code wise, i did:

import 'package:bip39/bip39.dart' as bip39;
import 'package:ethers/signers/wallet.dart' as EWallet;

String mnemonic = mnemonicController.text; //TextFormField controller
if (!bip39.validateMnemonic(mnemonic)) {
      //error
}
final walletMnemonic = EWallet.Wallet.fromMnemonic(mnemonic);
final privateKey = walletMnemonic.privateKey;
final credentials = EthPrivateKey.fromHex(privateKey!);

Now you can use web3dart EthPrivateKey/Credentials object.

jvinai avatar Aug 04 '22 08:08 jvinai

ethers now is outdated. Any other solutions?

Kujbor avatar Aug 16 '23 03:08 Kujbor