Importing Solana Mnemonics with Python

323 Views Asked by At

I need to use HD wallets with pysolana.

Hello everyone, I'm working on solana with Python. I can generate random Solana wallets with the code I wrote below.

mnemo = Mnemonic("english")
my_words = mnemo.generate(128)
    
seed_bytes = Bip39SeedGenerator(my_words).Generate("")
bip44_mst_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.SOLANA)
bip44_acc_ctx = bip44_mst_ctx.Purpose().Coin().Account(0)
bip44_chg_ctx = bip44_acc_ctx.Change(Bip44Changes.CHAIN_EXT)
ADDR = bip44_chg_ctx.PublicKey().ToAddress()

But here's the problem, these wallets are HD Wallets. If I want to use these wallets, I need to import these seeds into the solders library. But the solders library does not support HD wallets.

The only useful Python Solana library is also coded to work with the solders library.

Here is the urls: https://michaelhly.com/solana-py/rpc/api/#solana.rpc.api.Client.send_transaction Solders keypairs: https://kevinheavey.github.io/solders/tutorials/keypairs.html

2

There are 2 best solutions below

1
On BEST ANSWER

HD wallet support has been added. https://github.com/kevinheavey/solders/pull/75

0
On

I believe this is all correct, you just need to use the secret key bytes from bip44_chg_ctx to create a Keypair, ie:

keypair = Keypair.from_seed(bip44_chg_ctx.PrivateKey().Raw().ToBytes())

Note that the documentation for Raw() on Bip44PrivateKey seems to be incorrect: https://github.com/ebellocchia/bip_utils/blob/fc9e7723a7cf44c964976694912818ccd027936a/bip_utils/bip/bip44_base/bip44_keys.py#L189C28-L189C28