-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (34 loc) · 1.02 KB
/
index.js
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
const {
Connection,
PublicKey,
clusterApiUrl,
Keypair,
LAMPORTS_PER_SOL
} = require("@solana/web3.js");
const wallet = Keypair.generate();
const publicKey = wallet.publicKey;
const secretKey = wallet.secretKey;
const getWalletBalance = async () => {
try {
const connection = new Connection(clusterApiUrl('devnet'), "confirmed");
const walletBalance = await connection.getBalance(publicKey);
console.log(`Wallet balance is ${walletBalance / LAMPORTS_PER_SOL} SOL`);
} catch (err) {
console.log(err);
}
};
const airDropSol = async () => {
try{
const connection = new Connection(clusterApiUrl('devnet'), "confirmed");
const fromDropSignature = await connection.requestAirdrop(publicKey, 2 * LAMPORTS_PER_SOL);
await connection.confirmTransaction(fromDropSignature);
}catch(err){
console.log(err);
}
}
const main = async () => {
await getWalletBalance();
await airDropSol();
await getWalletBalance();
};
main();