allow generating new keypair

This commit is contained in:
Arihant Bansal
2024-11-26 17:31:12 +05:30
parent 92651642e8
commit 4116dac40a

View File

@@ -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;
}