So this is a simple Solana / web3.js Airdrop code. I was able to check the wallet balance. But when I tried to perform an airdrop, internal error is thrown.
Below is my code
const{
Connection,
PublicKey,
clusterApiUrl,
Keypair,
LAMPORTS_PER_SOL
} = require("@solana/web3.js")
const wallet = new Keypair()
const publicKey = new PublicKey(wallet._keypair.publicKey)
const secretKey = wallet._keypair.secretKey
const getWalletBalance = async() => {
try{
const connection = new Connection(clusterApiUrl('devnet'),'confirmed')
const walletBalance = await connection.getBalance(publicKey)
console.log(`Wallet Balance is ${walletBalance}`)
}
catch(er){
console.log(er)
}
}
const airDropSol = async() =>{
try{
const connection = new Connection(clusterApiUrl('devnet'),'confirmed')
const fromAirDropSignature = await connection.requestAirdrop(publicKey, 2 * LAMPORTS_PER_SOL)
await connection.confirmTransaction(fromAirDropSignature)
}catch(er){
console.log('Error Here: '+er)
}
}
const main = async() =>{
await getWalletBalance()
await airDropSol()
await getWalletBalance()
}
main()
Below Error is thrown when executed.
Wallet Balance is 0
Error: airdrop to D6oLiSL2CrJkeEMmPZs2akHzUzoqD2M7yMVJWcB5KUF failed: Internal error
Wallet Balance is 0
Request Airdrop failed.
Kindly help me to resolve this. Thanks :)