'I want to get the address from mnemonic with the proper derivation path

I am very new to blockchain programming and programming in general. I want to generate my SOL address using the mnemonic seed phrase with the derivation path "m/44'/501'/0'/0". I can't find a proper BIP44 module for python where you can specify the derivation path.



Solution 1:[1]

After a long search through the internet, I have finally found a way of solving my problem that I want to share with you.

from bip_utils import *

MNEMONIC = "...12 words phrase..."

seed_bytes = Bip39SeedGenerator(MNEMONIC).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)

print(bip44_chg_ctx.PublicKey().ToAddress())

This code outputs the first address of your mnemonic. This is only for Sollet and Phantom wallet!

If you are using Solflare you can cut the line bip44_chg_ctx = bip44_acc_ctx.Change(Bip44Changes.CHAIN_EXT) out!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyaaz