简体   繁体   English

我想通过正确的推导路径从助记符中获取地址

[英]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".我想使用推导路径“m/44'/501'/0'/0”的助记种子短语生成我的 SOL 地址。 I can't find a proper BIP44 module for python where you can specify the derivation path.我找不到适合 python 的 BIP44 模块,您可以在其中指定派生路径。

After a long search through the inte.net, I have finally found a way of solving my problem that I want to share with you.在 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())

This code outputs the first address of your mnemonic.此代码输出助记词的首地址。 This is only for Sollet and Phantom wallet!这仅适用于 Sollet 和 Phantom 钱包!

If you are using Solflare you can cut the line bip44_chg_ctx = bip44_acc_ctx.Change(Bip44Changes.CHAIN_EXT) out!如果您使用的是 Solflare,则可以将bip44_chg_ctx = bip44_acc_ctx.Change(Bip44Changes.CHAIN_EXT)行删掉!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为路径获得正确的大小写? - How can I get the proper capitalization for a path? 如何在适当的情况下获取python脚本的路径? - How do I get path to python script, with proper case? 想要从用户处获取IP地址以手动输入(而不是按其位置) - Want to get ip address from user to be manually typed in (not by their location) 我想获取我在 python 中单击的文件的路径 - I want to get the path of the file I clicked in python 为什么btclib.mnemonic_from_raw_entropy声称我传递给它的熵少于128位? - Why does btclib.mnemonic_from_raw_entropy claim I passed it less than 128 bits of entropy? 我试图获取我机器上的所有文件夹,但它只提供相对路径我想要完整路径 - I am trying to get all folders on my machine but it only gives relative path I want full path 我希望能够从根路径和子路径加载类 - I want to be able to load class from both root and sub path 我想在 python 中使用正则表达式提取地址,我可以在其中使用lookbehind,以便获得前面的 3-4 个保存地址的字符串 - i want extract address using regex in python where i can use a lookbehind so that i get the preceding 3-4 strings that hold the address 我想从列表中获取字符串 - I want to get string from list "我想从 json 文件中获取数据" - I want to get the data from a json file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM