Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2022 01:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save topherPedersen/ae0ede07a6b6beca5fedfb74c471c324 to your computer and use it in GitHub Desktop.
Solana 101: Funding Your Solana Account via Airdrop (From's Solana 101 Course)
import {Connection, PublicKey, LAMPORTS_PER_SOL} from '@solana/web3.js';
import type {NextApiRequest, NextApiResponse} from 'next';
import {getNodeURL} from '@figment-solana/lib';
export default async function fund(
req: NextApiRequest,
res: NextApiResponse<string>,
) {
try {
const {network, address} = req.body;
const url = getNodeURL(network);
const connection = new Connection(url, 'confirmed');
const publicKey = new PublicKey(address);
const hash = await connection.requestAirdrop(publicKey, LAMPORTS_PER_SOL);
await undefined;
} catch (error) {
let errorMessage = error instanceof Error ? error.message : 'Unknown Error';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment