I have an airdrop function that allow the owner input array of addresses and an amount to give. It work well with small number of addresses about (100) but bigger than that, gaz limit is reached.
I wonder, is it my code that block that or just the fact that it cost X amount to airdrop X token multiply by the array length so it's just costing a lot to send and the gaz limit really reached?
I tried to find answer here and over the web but I'm not sure how to format my question. Like, is there any limit of an address array as argument?
Here is my code :
function airDrop(address[] recipients,uint amount ) public {
require(msg.sender == owner);
require(amount > 0);
uint256 supposedDropAmount = (recipients.length).mul(amount);
//be sure it's not over the limit
uint256 checkedSupply = dropAmount.add(supposedDropAmount);
// return money if something goes wrong
require(checkedSupply <= AirdropCap); // block airdrop
//require date time
require(now > airdropTime);
for( uint256 i = 0 ; i < recipients.length ; i++ ) {
assert(token.mint(recipients[i], amount));
emit TokenDrop( recipients[i], amount );
}
numDrops = numDrops.add(recipients.length);
dropAmount = dropAmount.add(recipients.length.mul(amount));
}
Notice the token.mint
is external in another contract, and that airdropTime is much in the past than now. As I said, it work with small array of address.