mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-16 15:10:26 +00:00
Merge pull request #2 from arihantbansal/create-agent-wallet
allow creating fresh wallet for agent
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user