1

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 :)

Yilmaz
  • 35,338
  • 10
  • 157
  • 202
Soam
  • 11
  • 2

2 Answers2

1

The current maximum for airdrops on devnet is usually limited to 1 SOL, so you can just change the requestAirdrop line to:

const fromAirDropSignature = await connection.requestAirdrop(publicKey, 1 * LAMPORTS_PER_SOL)
Pang
  • 9,564
  • 146
  • 81
  • 122
Jon C
  • 7,019
  • 10
  • 17
0

I tested your code and it is working:

enter image description here

Internal error means, solana team might be doing maintenance during you execute your code or there were too many requests at that time which is a common problem for faucets.

Yilmaz
  • 35,338
  • 10
  • 157
  • 202