Skip to Content
DocumentationWalletsCreate Multiple Wallets

Create Multiple Wallets

Creates multiple Solana wallets (more specifically KeyPairSigner objects) at once. All wallets will be created with the same options.

Returns: Promise<Array<KeyPairSigner>>

const wallets = await connection.createWallets(numberOfWallets, options);

Parameters

  • numberOfWallets: number - The number of wallets to create
  • options: Object (optional) - Same options as createWallet:
    • prefix: string | null (optional) - Generate addresses starting with these characters
    • suffix: string | null (optional) - Generate addresses ending with these characters
    • envFileName: string | null (optional) - Save private keys to this .env file
    • envVariableName: string (optional) - Environment variable name to store the keys (default: “PRIVATE_KEY”)
    • airdropAmount: Lamports | null (optional) - Amount of test SOL to request from faucet (default: 1 SOL)
    • commitment: Commitment | null (optional) - Desired commitment level for airdrop

Examples

Create multiple wallets with default settings:

// Create 5 wallets with default settings const wallets = await connection.createWallets(5); console.log(`Created ${wallets.length} wallets`); // Access individual wallets const [alice, bob, charlie, dave, eve] = wallets; console.log("Alice's address:", alice.address); console.log("Bob's address:", bob.address);

Create wallets for testing:

// Create 3 wallets for testing const testWallets = await connection.createWallets(3); // Use them in your tests for (const wallet of testWallets) { console.log(`Wallet ${wallet.address} created`); // Each wallet will have 1 SOL airdropped by default const balance = await connection.getLamportBalance(wallet.address); console.log(`Balance: ${balance} lamports`); }

Create wallets for different purposes:

// Create wallets for different roles const [adminWallet, userWallet, treasuryWallet] = await connection.createWallets(3); console.log("Admin wallet:", adminWallet.address); console.log("User wallet:", userWallet.address); console.log("Treasury wallet:", treasuryWallet.address);

Create wallets with custom options:

// Create 3 wallets with a specific airdrop amount const wallets = await connection.createWallets(3, { airdropAmount: lamports(2n * SOL), // Each wallet gets 2 SOL }); // Create wallets with vanity addresses const vanityWallets = await connection.createWallets(2, { prefix: "ABC", // All addresses will start with "ABC" airdropAmount: lamports(1n * SOL), });

See also

Last updated on