Solana CookbookDevelopment

Load a local json file keypair

When running your local project may sometimes want to use local keypair. The default keypair path generated by the Solana CLI is ~/.config/solana/id.json.

You can generate a custom keypair using the Solana CLI command solana-keygen grind --starts-with hi:1. This will generate a keypair with a public key starting with "hi" and output the keypair to a json file. You can then load this keypair using the helper function below.

const keypairSigner = await loadKeypairSignerFromFile();
console.log(keypairSigner.address);
export async function loadDefaultKeypairWithAirdrop(
cluster: string
const keypairSigner2 = await loadDefaultKeypairWithAirdrop("devnet");
console.log(keypairSigner2.address);

Is this page helpful?