-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
39 lines (34 loc) · 909 Bytes
/
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
const {
Connection,
PublicKey,
clusterApiUrl,
Keypair,
LAMPORTS_PER_SOL
} = require("@solana/web3.js")
const wallet = new Keypair()
const publicKey = new PublicKey(wallet._keypair.publicKey)
const privateKey = wallet._keypair.secretKey
const getWalletBalance = async() => {
try{
const connection = new Connection(clusterApiUrl('devnet'),'confirmed')
const walletBalance = await connection.getBalance(publicKey)
console.log(`wallet ballance is ${walletBalance}`)
}catch(err){
console.log(err)
}
}
const airdropSol = async() => {
try{
const connection = new Connection(clusterApiUrl('devnet'), 'copnfirmed')
const airdropSig = await connection.requestAirdrop(publicKey, 2* LAMPORTS_PER_SOL)
await connection.confirmTransaction(airdropSig)
}catch(err){
console.log(err)
}
}
const main = async() => {
await getWalletBalance()
await airdropSol()
await getWalletBalance()
}
main()