Merge pull request #2 from arihantbansal/create-agent-wallet

allow creating fresh wallet for agent
This commit is contained in:
ARYAN
2024-11-27 17:37:22 +05:30
committed by GitHub

View File

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