One of the first step when you develop on a blockchain is to create one of multiple public keys that you can use to test your program.
To do that, you need to create a wallet that will hold your public keys.
Phantom is a very popular Wallet solution - as the website says, Phantom is a browser extension that makes it easy to store, buy, send, receive, swap tokens and collect NFTs on the Solana blockchain.
When you are developing a program on Solana, you prefer to use the different cli tools to interact with the blockchain.
This article will describe how you can share your public keys between Phantom and the cli.
There are a lot of documents that describe how to install the phantom extension and you should follow this instructions described here: https://phantom.app/download
When installing the extension, you will be presented first with that screen:
Unless you already had a wallet with Phantom, you must click on “Create a new wallet”
This will then ask you to create a password: this password will protect the access to your Phantom extension from your browser.
The final step will give you access to your “secret recovery phrase” :
Important: It is very important that you keep both your Phantom password and the secret recovery phrase secret. If you leak them, an attacker could steal all your tokens from all your Solana addresses…
Solana CLI wallet creation
You need first to install the different Solana CLI tools:
sh -c "$(curl -sSfL https://release.solana.com/v1.10.4/install)" solana-install update
There is an option to recover your keys from the seed phrase using:
$ solana solana-keygen recover -o key.txt ASK [recover] seed phrase: [recover] If this seed phrase has an associated passphrase, enter it now. Otherwise, press ENTER to continue: Recovered pubkey `HWsU...PGod`. Continue? (y/n): y
If you use the seed phrase that you got from Phantom, the recovered pubkey won’t be the key that you have in Phantom.
The issue seems to be that the seed phrases management between Phantom and the Solana CLI are not compatible.
You can still share public keys between those 2 environments.
The solution is to create a new key using the Solana cli:
solana-keygen new -o ~/.config/solana/id.json Generating a new keypair For added security, enter a BIP39 passphrase NOTE! This passphrase improves security of the recovery seed phrase NOT the keypair file itself, which is stored as insecure plain text BIP39 Passphrase (empty for none): Wrote new keypair to /Users/pcarion/.config/solana/id.json pubkey: 4w..up Save this seed phrase and your BIP39 passphrase to recover your new keypair: word1 word2 ...
You get here a new seed phrase that you should also store securely.
At this stage you now have 2 Solana addresses : one in Phantom and one in the CLI.
As Phantom provides a nice and convenient interface to interact with your key, you want to import your cli key inside Phantom.
For your development needs, you may want to get SOLs from the dev network:
➜ solana solana airdrop 1 4wYX...pgup --url https://api.devnet.solana.com Requesting airdrop of 1 SOL ➜ solana solana balance 4wYX...pgup --url https://api.devnet.solana.com 1 SOL
Import your CLI Solana key to Phantom
Note: the steps to do that were found in reddit.
The private key for your cli address is stored in plain text in the file :
The first step is copy it:
cat ~/.config/solana/id.json | pbcopy
Then, using the hamburger menu in the Phantom extension, click on “Add / Connect Wallet”
Then “Import private key” :
In that screen, you can give a name and paste the private key of your cli address:
If you switch to the dev network in Phantom, you’ll then be able to see the SOLs you air dropped perviously: