This is my airdrop function:
mapping (address => bool) public airdrops;
function airdropTokens(address[] _recipient, uint256[] _tokens) public onlyOwner{
uint airdropped;
for(uint256 i = 0; i< _recipient.length; i++)
{
airdrops[_recipient[i]] = true;
require(token.transferFrom(msg.sender, _recipient[i], _tokens[i] * decimalFactor));
airdropped = airdropped.add(_tokens[i] * decimalFactor);
}
}
What should be optimal gas limit and gas price for this? I initially used, gasPrice = 50000000000 and gasLimit = 4500000, which works out at $47.27. Is this normal? I managed to successfully send a batch of 20 addresses at 3.5 GWEI / 2500000 Gas limit see: airdrop to 20 addresses transaction
But for other batch of 80 addresses, it failed at 4 GWEI / 4500000 Gas limit, see link here Any ideas on how to manage the gas better? If I was to send out the 350 more batches at the recommended prices, it would cost me around £16k!!
P.S: Currently, each airdrop transaction is sending tokens to 80 addresses at once.
airdrops[_recipient[i]] = true;
, you pay 20k gas to store a single bit. From the successful transaction you use around 125k gas per token transfer which seems a bit high. I'd take a look at to optimize transferFrom.airdrops
is never used again, but if you use it in another function then you should keep it. Rounding numbers 20k x 80 =1600k = 1.6m.