Files
solana-agent-kit/src/tools/request_faucet_funds.ts
2024-11-26 16:24:38 +05:30

28 lines
756 B
TypeScript

import { SolanaAgentKit } from "../index";
import { LAMPORTS_PER_SOL } from "@solana/web3.js";
/**
* Request SOL from the Solana faucet (devnet/testnet only)
* @param agent - SolanaAgentKit instance
* @returns Transaction signature
* @throws Error if the request fails or times out
*/
export async function request_faucet_funds(
agent: SolanaAgentKit,
): Promise<string> {
const tx = await agent.connection.requestAirdrop(
agent.wallet_address,
5 * LAMPORTS_PER_SOL,
);
const latestBlockHash = await agent.connection.getLatestBlockhash();
await agent.connection.confirmTransaction({
signature: tx,
blockhash: latestBlockHash.blockhash,
lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
});
return tx;
}