3

I would like to generate a number of Solana addresses and store them in a database. I plan to use them to display and receive payments. I don't need to verify (I only need to display a receiving address).

I tried a command line key generator - ssh-keygen -t ed25519 and then tried to import it into a Phantom wallet and got a "wrong format" error.

1
  • Solved(pretty much). I installed Solana cli and have to say I am really impressed. The only thing left is to create multiple addresses and so far I only can see one? That's if I'm undertanding addresses correctly. I'm moving over from Bitcoin where the recommended practice has been to use a new address for each transaction. My goal (if that is correct is to generate a list of addresses) and air gap them. Commented Mar 22 at 17:22

5 Answers 5

3

I'd suggest using web3.js for this:

import { Keypair } from '@solana/web3.js';

for (let i = 0; i < NUM_TO_GENERATE; i++){
    const kp = Keypair.generate();
    console.log(kp.secretKey);
    console.log(kp.publicKey.toBase58());
}
1
  • Thanks but I went with Solana cli. Commented Mar 22 at 17:16
3

You can keep generating addresses with the Solana CLI's solana-keygen, same as the first keypair you created, ie:

$ solana-keygen new -o FILENAME.json --no-bip39-passphrase

Feel free to do that on a loop to create all the keypairs you want, ie:

for i in {0..3}
do
  solana-keygen new -o keypair${i}.json --no-bip39-passphrase
done
3
  • The first code ("solana-keygen new -o FILENAME.json --no-bip39-passphrase") creates new seed phrase each time. The second does the same. Commented Mar 31 at 18:44
  • Can I get just the addresses saved to a file (while also saving the new json file as it already does)? Commented Mar 31 at 18:51
  • And I'm confused about the seed phrase. Isn't that used by elliptical curve? If so, could I generate a list from it? Is that only possible from Web3.js or can I also do that from the cli? Commented Mar 31 at 18:59
0

If you use JS/TS, you can also use the helpers library maintained by the Solana Foundation Dev Ecosystem team:

const keypairs = makeKeypairs(30);

keypairs will be an array of 30 keypairs.

2
  • I'M doing all the key generation from the command line and the console. Is it possible to get that library to run there? I'm familiar with using JS in the browse. Commented Apr 13 at 20:53
  • @RobertLefebvre you can always run JS in the command line. Either node (to run a JS file) or esrun (or other tools, but esrun is the best) to run a TS file.
    – mikemaccana
    Commented Apr 23 at 17:34
0

Got this to work. Needed to change the config for each time through the loop

for i in {1..20}
do
    echo "keypriv # $i"
    solana-keygen new -o ~/pubAddressesForDB3/keypriv$i.json --no-bip39-passphrase
solana config set --keypair ~/pubAddressesForDB3/keypriv$i.json
    echo "keypub # $i"
    solana-keygen pubkey --outfile ~/pubAddressesForDB3/keypub$i.json
done
0

for batch solana wallet generation you can use our well made script – Solana Keys Generator. This script can easy generate thousands of solana accounts and store them in .csv file (publicKey,privateKey), also solana-keygen saves .json keys.

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.