1

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.

4
  • @Rob Hitchens B9lab Can u please see if that is something you can answer? Commented Nov 7, 2018 at 3:34
  • 1
    One problem with your airdrop is that for every recipient you are consuming an extra slot with 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.
    – Ismael
    Commented Nov 7, 2018 at 18:22
  • the storage of receipient record can be compromised. Would you suggest omitting it will help me ? How much gas cost you think it'll save per transaction and for 80? Commented Nov 8, 2018 at 12:54
  • 1
    In your code the mapping 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.
    – Ismael
    Commented Nov 8, 2018 at 20:43

1 Answer 1

1

Here are few hints:

  1. replace public modifier with external in your contract. Here is why
  2. Not used gas (limit) is returned back to you so you may put as much as possible. On time of writing it's around 6-7M.
  3. You may put low gas price (e.g. 1 GWEI). However, your transaction will take some time. You may estimate it here: https://ethgasstation.info/
8
  • Thanks, since I have already deployed contract onto the main network so how much you think the first point will add benefit? If it will worth alot, I will go about re-deploying. Commented Nov 6, 2018 at 8:03
  • I think it worth redeploying, you may experiment on rinkeby to see benefits. gas limit won't save you funds. If you specify too low gas limit it will just burn. If you want to use an existing contract you may only decrease gas price @FarihaAbbasi Commented Nov 6, 2018 at 8:05
  • Thanks so Im looking towards, re-deploying contract with usage of "external" and then If I use 4500000 gas limit and 2 Gwei gas Price, would you suggest is it all a good combination for airdrop to 80 addresses? I ran into "Out of gas" exception while transferring to 80 addresses with 4 GWEI and 4500000 Gas limit. So you think, I will not get this issue again? Commented Nov 6, 2018 at 8:11
  • Out of gas is because of low gas limit. When you use external it should be lower. I cannot tell you the exact price you should experiment. I would put 6M to be safe. You may deploy to test network to experiment rinkeby.etherscan.io Commented Nov 6, 2018 at 8:15
  • I made the necessary changing to the contract, re-deployed, used 4500000 gas limit and 1 Gwei on ropsten test network, it worked fine. On main net, my transaction took more than 8-9 hours and finally dropped. see link Commented Nov 7, 2018 at 3:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.