5

How do I export a wallet from a provider like phantom or solflare that results in a json file that I can use with the Solana CLI?

3 Answers 3

4

For some obscure reason exporting from phantom gives a base58 encoded keypair.

Export button

However, you can easily convert it with a 2 liner in python, provided the base58 package is installed

>>> import base58
>>> [i for i in base58.b58decode('<PRIVATE_KEY_BASE58>')]
[1, 2, 3, ...]

For solflare you can directly go to select account at the top right -> the gear icon next to the account to export -> export private key. It is already a 64 uint array you can use with the solana CLI

I recommend doing the opposite process, generate a bip39 mnemonic on your computer then create account keypairs from it to be loaded in wallets (phantom accepts a 64 uint array), this as the advantage of allowing a single proper backup for tinkering while separating account loaded for tinkering in the wallet from the main hot wallet mnemonic.

Moreover, if need be, the entire tinkering mnemonic can be entered in the wallet in a different browser profile for ease of navigation between accounts

3

Solana CLI also comes with a tool to 'recover' a wallet to a keypair with your mnemonic seed phrase.

solana-keygen recover 'prompt:?key=0/0' --outfile keypair.json

If you have multiple accounts in your Phantom wallet, you increment the first number after ?key=

For example, 0/0 will target the first wallet, 1/0 will target the second, and so on.

Edit: You can get your mnemonic phrase in Phantom by going to Settings, then Show Secret Recovery Phrase at the bottom of the settings menu.

2
  • This is how I usually do it as well
    – cloudberry
    Commented Jul 28, 2022 at 20:12
  • this does not appear to describe in detail how to do this exactly? how do I get a phrase or key from the wallet like phantom or solflare? It seems between the 2 answers I get it.. Commented Jul 30, 2022 at 1:46
0

I wrote a small Python script that converts private key into byte array. It is fairly simple and it has come in handy many times.

Answered in another question here - https://solana.stackexchange.com/a/2739/486

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.