[英][Solana / Solana/Web3.js]Unable to Airdrop Sol. Internal Error is thrown
所以这是一个简单的 Solana / web3.js Airdrop 代码。 我能够检查钱包余额。 但是当我尝试执行空投时,会抛出内部错误。
下面是我的代码
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()
执行时抛出以下错误。
Wallet Balance is 0
Error: airdrop to D6oLiSL2CrJkeEMmPZs2akHzUzoqD2M7yMVJWcB5KUF failed: Internal error
Wallet Balance is 0
请求空投失败。
请帮我解决这个问题。 谢谢:)
de.net 上空投的当前最大值通常限制为 1 SOL,因此您只需将requestAirdrop
行更改为:
const fromAirDropSignature = await connection.requestAirdrop(publicKey, 1 * LAMPORTS_PER_SOL)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.