我想从助记词中获取具有正确推导路径的地址

发布于 2025-01-09 09:29:23 字数 107 浏览 1 评论 0原文

我对区块链编程和一般编程非常陌生。我想使用助记符种子短语和派生路径“m/44'/501'/0'/0”生成我的 SOL 地址。我找不到适合 python 的 BIP44 模块,您可以在其中指定派生路径。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫轩蝶泪 2025-01-16 09:29:23

经过网上查了好久,终于找到了解决问题的方法,分享给大家。

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) 行!

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!

那支青花 2025-01-16 09:29:23

2024 年 6 月为我工作:

from solders.keypair import Keypair
from mnemonic import Mnemonic

mnemo = Mnemonic("english")
seed = mnemo.to_seed("your mnemonic phrase here")

for i in range(10):
    path = f"m/44'/501'/{i}'/0'"
    keypair = Keypair.from_seed_and_derivation_path(seed, path)
    public_key = keypair.pubkey()
    print(f"Wallet {i+1}:")
    print(f"Public Key: {public_key}")
    print(f"Private Key: {keypair}")

Worked for me on Jun 2024:

from solders.keypair import Keypair
from mnemonic import Mnemonic

mnemo = Mnemonic("english")
seed = mnemo.to_seed("your mnemonic phrase here")

for i in range(10):
    path = f"m/44'/501'/{i}'/0'"
    keypair = Keypair.from_seed_and_derivation_path(seed, path)
    public_key = keypair.pubkey()
    print(f"Wallet {i+1}:")
    print(f"Public Key: {public_key}")
    print(f"Private Key: {keypair}")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文