From 4116dac40aab5666e586b85d0390bda1d5d54969 Mon Sep 17 00:00:00 2001 From: Arihant Bansal <17180950+arihantbansal@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:31:12 +0530 Subject: [PATCH] allow generating new keypair --- src/agent/index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/agent/index.ts b/src/agent/index.ts index c6371b0..01d5042 100644 --- a/src/agent/index.ts +++ b/src/agent/index.ts @@ -30,11 +30,22 @@ export class SolanaAgentKit { public wallet_address: PublicKey; constructor( - privateKey: string, + privateKey?: string, rpcURL = "https://api.mainnet-beta.solana.com", ) { this.connection = new Connection(rpcURL); - this.wallet = Keypair.fromSecretKey(bs58.decode(privateKey)); + if (privateKey) { + this.wallet = Keypair.fromSecretKey(bs58.decode(privateKey)); + } else { + this.wallet = Keypair.generate(); + console.log("Generated new wallet: ", this.wallet.publicKey.toBase58()); + console.log( + "Safely store the private key: ", + "\n----------------------------------\n", + this.wallet.secretKey, + "\n----------------------------------\n", + ); + } this.wallet_address = this.wallet.publicKey; }