I have a private key (not the seed phrase) for an old account. How can I create a keypair from that to use with the CLI?
First I don’t know what you are really asking for as maybe you are confused about how keys work. Or maybe you ask about validator key pairs as you need two keys to run validator nodes. A validator key and a voting key. But I regress, if you are asking how to use your private key with the CLI its as easy as pie. Just place the private key in a file in your HDD’s home directory location so has the pathname like this:
Where substitue your username where you see the johnycash username, unless your a good guitar player.
Now you need to set your solana config to the mainnet so issue command:
solana config set --url https://api.mainnet-beta.solana.com
Then you will use that key and the solana-keygen CLI to get the wallet public key address like so:
Then you will get back the Public Key of your private key file looking like this:
So then whatever the pubkey is you have to use that key to tell people to send you some SOL to that public address.
Never give anyone your private key and keep it locked on your computer and never give anyone any password to your computer and save a copy of the key printed on paper as you lost the passphrase and you cannot generate the passphrase apparently very easily. Sollet.io wallet has some ability to do this.
Do you know if this is a sollet.io private key or was it generated with the solana-keygen software? You must use the same way that you used to generate these keys to be safe so if you created it with sollet.io then use that website to restore the key and check your balance. Elsewise use the solana-keygen and then only the solana transfer and solana balance commands to process funds betwixt accounts.
If using a Phantom wallet, the private key that it exports is a different format than what the CLI expects. The private key that Phantom exports looks like a long hash, but the keypairs generated by solana-keygen are a JSON array of numbers. How can we convert the Phantom hash into a keypair that’s usable by Solana CLI?
Hi @emersonthis and welcome to the forum!
That’s a great question! I’ve run into the want to do this before, but I didn’t solve it at the time.
I’ll either find a way to do with with the Solana CLI, or I’ll create a quick script to do it, but I’ll probably not get to it until about 15 hours from now.
I’ll let you know as soon as I figure it out, though!
Cool! I’ve been doing more reading about this, and I think the heart of the issue is that Phantom exports a base58 string, but Solana CLI expects a Uint8Array.
Exactly. It should be trivial to use a little Deno or Node.js script to convert it.
let bs58 = require('bs58'); let secretKey=bs58.decode("__Your Secret Key__"); let x = Keypair.fromSecretKey(secretKey); console.log(x.publicKey.toBase58());
I don’t think you need to do the separate step to create the Keypair from the secret key.
Here’s something that worked for me, and with Deno you can test it without needing to
npm install or anything.
script_url=https://gist.githubusercontent.com/zicklag/feb30b217b07c013641dbfce16a754eb/raw/471f27ba6dcda188cfbd83f44299637653bfc56a/base58-to-array.ts deno run $script_url [exported private key string from Phantom]
(I hadn’t heard of Deno until Zicklag mentioned it here. It looks very handy for things like this.)
how can i recover my acc with [125,15,498,569…195] these type of private key
generated with GitHub - vsec7/Sol-Wallet-Generator: Solana Wallet Generator
@hacky_noob That sounds like the contents of a keypair file. If you’re using Phantom wallet you can actually copy/paste that array of numbers into the import screen and it should work.
i have only that secretKey backed up, which is in [125,15,498,569…195] these format
@hacky_noob I’m no longer clear about what you are trying to do. I thought you wanted to get a backed up private key into Phantom wallet. If that is what you want to do, you can literally copy/paste the contents of that file (in the exact format you showed) into this Phantom wallet import screen.
If this isn’t your question, please explain what you meant when you said “recover”.
yes i tried it didnt worked
Maybe you accidentally modified the private key? Is there an extra comma maybe or something weird?
Do not show us the key, though!
Edit: Oh, or maybe you need to update your Phantom extension?
can u try generating wallet using these script GitHub - vsec7/Sol-Wallet-Generator: Solana Wallet Generator
n then recover using secret key
cause i forget to backup mnemonic i only have secret key
@hacky_noob I was able to use that script and generate a wallet, then import it into Phantom by copy and pasting the JSON array output from my terminal window.
Maybe you should try to uninstall and install Phantom again. Maybe you have an old version.
Yep, that’s the one I used. It worked fine. I tried a couple different keys, too.
Hello Blockchainlover2019, I ran the program but it doesn’t show anything. I might not have the right folder structure can you possibly direct me to the GitHub file. I am a noob so apologize.