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 1/2] 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; } From 43d06c9bfb04816e9b9f9d77514b18aa94e1db76 Mon Sep 17 00:00:00 2001 From: Arihant Bansal <17180950+arihantbansal@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:32:04 +0530 Subject: [PATCH 2/2] add warning --- src/agent/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/agent/index.ts b/src/agent/index.ts index 01d5042..07fbe52 100644 --- a/src/agent/index.ts +++ b/src/agent/index.ts @@ -44,6 +44,7 @@ export class SolanaAgentKit { "\n----------------------------------\n", this.wallet.secretKey, "\n----------------------------------\n", + "Please fund this wallet with SOL to use it (on mainnet), or use the faucet method to request funds (only on devnet/testnet).", ); } this.wallet_address = this.wallet.publicKey;