Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
docs: add airdrop example (#17770)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry authored Jun 6, 2021
1 parent 9ed1626 commit 18ec675
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions web3.js/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3257,15 +3257,26 @@ export class Connection {
}

/**
* Request an allocation of lamports to the specified account
* Request an allocation of lamports to the specified address
*
* ```typescript
* import { Connection, PublicKey, LAMPORTS_PER_SOL } from "@solana/web3.js";
*
* (async () => {
* const connection = new Connection("https://api.testnet.solana.com", "confirmed");
* const myAddress = new PublicKey("2nr1bHFT86W9tGnyvmYW4vcHKsQB3sVQfnddasz4kExM");
* const signature = await connection.requestAirdrop(myAddress, LAMPORTS_PER_SOL);
* await connection.confirmTransaction(signature);
* })();
* ```
*/
async requestAirdrop(
to: PublicKey,
amount: number,
lamports: number,
): Promise<TransactionSignature> {
const unsafeRes = await this._rpcRequest('requestAirdrop', [
to.toBase58(),
amount,
lamports,
]);
const res = create(unsafeRes, RequestAirdropRpcResult);
if ('error' in res) {
Expand Down

0 comments on commit 18ec675

Please sign in to comment.