diff --git a/src/agent/index.ts b/src/agent/index.ts index c6371b0..07fbe52 100644 --- a/src/agent/index.ts +++ b/src/agent/index.ts @@ -30,11 +30,23 @@ 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", + "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; }