docs: add airdrop example (#17770)

This commit is contained in:
Justin Starry 2021-06-06 12:20:14 -07:00 committed by GitHub
parent 9ed1626e00
commit 18ec6756e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions

View File

@ -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) {