SOL token has been airdropped successfully on the generated payer address. Still I am getting the above error.
Here's the code:
import * as spl from "@solana/spl-token";
import * as web3 from "@solana/web3.js";
const connection = new web3.Connection(web3.clusterApiUrl("devnet"));
const lender = web3.Keypair.generate();
const lenderPk = lender.publicKey;
const payer = web3.Keypair.generate();
async function main() {
console.log("request airdrop...");
const tx = await connection.requestAirdrop(
payer.publicKey,
web3.LAMPORTS_PER_SOL
);
console.log(`Airdrop tx: ${tx}`);
console.log("creating token mint...");
const tokenMint = await spl.createMint(
connection,
payer,
lenderPk,
lenderPk,
8
);
console.log(`Token mint: ${tokenMint}`);
console.log("creating token address...");
const lenderTokenAddress = await spl.createAccount(
connection,
payer,
tokenMint,
lenderPk
);
console.log(`Token address: ${tokenMint}`);
console.log("minting tokens...");
await spl.mintToChecked(
connection,
payer,
tokenMint,
lenderTokenAddress,
lenderPk,
100e8,
8
);
const lenderTokenAccount = await spl.getAccount(
connection,
lenderTokenAddress
);
console.log(`Token account account: ${lenderTokenAccount.amount}`);
}
main();