alan-sdk / alan.dart

Pure Dart library allowing you to easily integrate with any Cosmos-based chain.
MIT License
32 stars 31 forks source link

How to get mnemonic phrase after creating a random wallet account #200

Closed mostafamshk closed 1 year ago

mostafamshk commented 1 year ago

Hey I'm using alan.dart for my custom wallet that manages my custom cosmos-sdk based blockchain. I couldn't find any data in Wallet class that represents the mnemonic phrase after creating a random wallet.

and I have to show the user his mnemonic phrase after he creates an account and I can't.

Can you guys help me? Thanks

RiccardoM commented 1 year ago

Hi @mostafamshk. Unfortunately we don't provide a function to retrieve a mnemonic from a generated wallet, since each wallet might be generated in different ways and there might not always be a way to get the mnemonic from it (e.g. if the wallet was generrated from a private key). In order to achieve what you want to get, I would suggest:

  1. Generating the mnemonic before generting the wallet. You can do this using the bip39 package and this code:
    Bip39.generateMnemonic(strength: 256)
  2. Use the Wallet.derive function to create a Wallet instance using the mnemonic you have generated:
    const wallet = Wallet.derive(mnemonic, networkInfo)

This way you will have full control over the generated mnemonic and you will be able to show it where you need.