Hello, I hope this doesn't get flagged for a duplicate post as I have reviewed what others have sent and am very confused about how mine isn't working the same.
I am trying to create a simple batch transfer contract that allows users to input an ERC20/721/1155 address and airdrop tokens to an array of addresses. But I keep getting errors when running a transaction on the Goerli testnet via etherscan, so I was hoping to get some answers as to why it's not working for me, but is for others.
For now, I'll share the funciton I am using for the erc20 drop:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract AirdropContractTest {
event AirdropCoins(address indexed from, address[] to, uint256[] amount);
/**
* @dev Batch transfer ERC20 tokens to a list of recipients.
* @param token Address of the ERC20 contract.
* @param recipients List of addresses to transfer the tokens to.
* @param amount Amount of tokens to transfer to each recipient.
*/
function batchTransferERC20(
IERC20 token,
address[] calldata recipients,
uint256[] calldata amount
) external {
uint256 recipientsLength = recipients.length; // Cache the length of the recipients
// Sender must have enough tokens to send to recipients
require(recipientsLength== amount.length, "Each recipient needs tokens");
// Loop through all the recipients and send them the specified amount
for (uint256 i = 0; i < recipientsLength; i++) {
require(token.transfer(recipients[i], amount[i]));
}
emit AirdropCoins(msg.sender, recipients, amount);
}
}
I am caching the length of the recipients for gas saving, am doing a loop to send each address the designated amount of tokens, and then emitting an event.
When I deploy to Goerli and check on the goerli etherscan, I input the following arguments:
Token Address - 0x182323E55C07f1afa3bD555008DDe89Dd035D4D1
Addresses to airdrop to: [0x90BadE35Da052450B01e99b38Cbb550BC3f1dD58, 0xD6D7fE937a64dE974923e2f80b44DA3B18BdCc13]
Amount - 5
Currently the wallet I am using to airdrop has 9700 of that token, so 5 should be easy to send to each address, but the error I get is: Fail with error 'ERC20: transfer amount exceeds balance'.
This doesn't make sense to me and would love help in trying to figure out what the issue is.