-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.ts
42 lines (37 loc) · 1.13 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { debugLog, Result, Try } from '~/suite-utils';
import { Node } from '~/node';
import { Pubkey } from '~/types/account';
import { AirdropOptions } from '~/types/airdrop';
export namespace Airdrop {
const DEFAULT_AIRDROP_AMOUNT = 1;
const MAX_AIRDROP_SOL = 2;
/**
* Reuqest airdrop SOL
* only devnet, testnet
*
* @param {Pubkey} pubkey
* @return Promise<Result<string, Error>>
*/
export const request = async (
pubkey: Pubkey,
options: Partial<AirdropOptions> = {},
): Promise<Result<string, Error>> => {
return Try(async () => {
debugLog('Now airdropping...please wait');
const airdropAmount = !options.dropAmount
? DEFAULT_AIRDROP_AMOUNT.toLamports()
: options.dropAmount.toLamports();
if (airdropAmount > MAX_AIRDROP_SOL.toLamports()) {
throw Error(
`Over max airdrop amount: ${airdropAmount}, max: ${MAX_AIRDROP_SOL.toLamports()}`,
);
}
const sig = await Node.getConnection().requestAirdrop(
pubkey.toPublicKey(),
airdropAmount,
);
await Node.confirmedSig(sig);
return 'success';
});
};
}