Create Wallet
Creates a new Solana wallet (more specifically a KeyPairSigner).
If you like, the wallet will have a prefix/suffix of your choice, the wallet will have a SOL balance ready to spend, and the keypair will be saved to a file for you to use later.
Returns: Promise<KeyPairSigner>
const wallet = await connection.createWallet({
prefix: "be", // Optional: Generate address starting with these characters
suffix: "en", // Optional: Generate address ending with these characters
envFileName: ".env", // Optional: Save private key to this .env file
envVariableName: "PRIVATE_KEY", // Optional: Environment variable name to store the key
airdropAmount: 1_000_000_000n, // Optional: Amount of test SOL to request from faucet
});Options
All options are optional:
prefix:string | null- Prefix for wallet addresssuffix:string | null- Suffix for wallet addressenvFileName:string | null- Path to .env file to save keypairenvVariableName:string- Name of environment variable to store keypair (default: “PRIVATE_KEY”)airdropAmount:Lamports | null- Amount of SOL to airdrop (default: 1 SOL)commitment:Commitment | null- Desired commitment level for airdrop (default: “finalized”)
Examples
Create a basic wallet:
const wallet = await connection.createWallet();Create a wallet with a specific prefix and suffix:
const wallet = await connection.createWallet({
prefix: "COOL",
suffix: "WALLET",
});Create a wallet and save it to an environment file:
const wallet = await connection.createWallet({
envFileName: ".env",
envVariableName: "MY_WALLET_KEY",
});Create a wallet with a custom airdrop amount:
const wallet = await connection.createWallet({
airdropAmount: lamports(2n * SOL),
});See also: Create Multiple Wallets, Load Wallet from File, Load Wallet from Environment
Last updated on