I use example in docs solana for python

I try get key pair and import to phantom by private key:

from solders.keypair import Keypair
from mnemonic import Mnemonic

mnemo = Mnemonic("english")
words = mnemo.generate(strength=256)
seed = mnemo.to_seed(words)
keypair1 = Keypair.from_bytes(seed)
print("keypair1: {}".format(keypair1))

keypair2 = Keypair()
print("keypair2: {}".format(keypair2))


keypair1: 4pqdZVgkCaALGNqvumkcC9gH5ZRj13DupL9go2DfZMhX9c7Mi9cei9AySWHNdcaxf5cnpZ2yyHtc5dvqW9qof2LX
keypair2: 4af72sYDF4ugnoMpNjoyBTmrDpgBKJqNUJGq8Lpy6vsao9kV9nxHtKiExqSwSkgKebJQHMeYWCQbH5JscbckkMck

Keypair1 was created by seed phrase and when i try import in phantom app i get error "bad format".

Keypair2 was created without seed phrase and when i try import in phantom app i not get error and import success

Why can't i import keypair1 and get error "bad format"?

2 Answers 2


It's still a mystery to me why the code in my question generates an invalid key pair when generated from a mnemonic phrase.

If you know why my code in the question creates an "invalid" private key from a mnemonic phrase and can explain it in detail, I'd be happy to mark your answer as the solution.

Apparently the code in my question is not generating the key pair correctly. Although it is worth noting that the addresses created in this way are displayed in solana explorer and funds can be transferred to them. It's also worth noting that the public key derived from such a primary key is on the ed25519 curve. However, it will no longer be possible to sign a transaction with such a private key.

I changed the code and now the keys are created using the pybip39 library:

from pybip39 import Mnemonic, Seed
from solders.keypair import Keypair

mnemonic = Mnemonic()
passphrase = "42"
seed = Seed(mnemonic, passphrase)
expected_keypair = Keypair.from_seed(bytes(seed)[:32])
keypair = Keypair.from_seed_phrase_and_passphrase(mnemonic.phrase, passphrase)
assert keypair.pubkey() == expected_keypair.pubkey()


globe way dress ribbon found orbit slice soccer kangaroo there spatial topple

The pair of keys obtained in this way works correctly, in. the private key can be imported into the phantom application and transactions can be signed using this private key.


dereviation paths are handled a bit differently in different wallets. Looks like the one you created wasnt compatible with the phantom deriviation path maybe. SolAndy did a video on it in case you want to research a bit further: https://www.youtube.com/watch?v=9_9IObnJdEY&t=1803s&ab_channel=Solandy%5Bsolandy.sol%5D

Here is some explanation on it in written form: https://docs.solana.com/de/wallet-guide/paper-wallet

This is the derivitaion paths phantom supports: https://help.phantom.app/hc/en-us/articles/12988493966227-What-derivation-paths-does-Phantom-wallet-support-

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.