[英]I want to get the address from mnemonic with the proper derivation path
总的来说,我对区块链编程和编程非常陌生。 我想使用推导路径“m/44'/501'/0'/0”的助记种子短语生成我的 SOL 地址。 我找不到适合 python 的 BIP44 模块,您可以在其中指定派生路径。
在 inte.net 上进行了长时间的搜索后,我终于找到了一种解决问题的方法,并希望与您分享。
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())
此代码输出助记词的首地址。 这仅适用于 Sollet 和 Phantom 钱包!
如果您使用的是 Solflare,则可以将bip44_chg_ctx = bip44_acc_ctx.Change(Bip44Changes.CHAIN_EXT)
行删掉!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.