0

I have to send 221,000 tokens (ERC20) to 6477 different addresses. Airdrop guy used some automatic sending app and that tells 1.94 ETH is needed as approx cost of operation to send all this. Is there any app, which can help here and reduce cost. 1.94 ETH as gas cost is insane.

Thanks

1
  • 1
    Do you need to send these tokens right after the moment token contract will be deployed? Or you will have already deployed contact at the moment of token mass sending? Do you have list of addresses and amounts to be sent, somewhere on-chain already? – Mikhail Vladimirov Jan 13 '20 at 9:33
1

Don't know details about your exact case, but here are some tricks that could be used to reduce gas cost when sending tokens to may addresses:

  1. Do several transfers in one transaction. This will save you approximately 21000 gas per transfer.
  2. Make recipients pay for gas, e.g. by signing cheques for them off-chain, so they will redeem these cheques on-chain. This will make transfers free for you.
  3. Deploy token smart contract with pre-populated balances, probably already stored somewhere on chain. This will cost you approximately 2000-3000 gas per recipient.

Let me know if you need more details about some of the these options.

1

You'll need to implement something like this:

pragma solidity 0.4.26;
import './IERC20Token.sol';

contract Airdrop {
    address public owner;
    mapping(address => uint256) public balances;

    constructor() public {
        owner = msg.sender;
    }

    function transferBatch(IERC20Token _token, address[] _targets, uint256[] _amounts) external {
        require(msg.sender == owner);
        uint256 length = _targets.length;
        require(length == _amounts.length);
        for (uint256 i = 0; i < length; i++) {
            address target = _targets[i];
            uint256 amount = _amounts[i];
            require(balances[target] == 0);
            require(_token.transfer(target, amount));
            balances[target] = amount;
        }
    }
}

Then you'll need to deploy this contract and transfer to it the entire amount that you want to distribute.

Finally, you'll need to determine how many addresses you want to transfer to in a single transaction.

The more addresses per transaction, the lower your total cost will be.

However, you cannot surpass the block gas-limit per transaction.

Moreover, in order to optimize the speed of execution, you would want to allow miners to squeeze more than a single transaction into one block. So, for example, if the average size of a transaction is a little more than 1/2 of the block gas-limit, then miners will not be able to squeeze more than one transaction into each block; if the average size of a transaction is a little more than 1/3 of the block gas-limit, then miners will not be able to squeeze more than two transactions into each block; and so forth.

So you'll need to do some experiments (on Ganache, for example, or better yet - for accuracy reasons - on Ropsten), in order to find an optimal batch-size.

From personal experience, 100 addresses per batch should be slightly less than 1/3 of the block gas-limit, so you might wanna use this as your batch size.


UPDATE:

You'll be able to save a significant amount of gas (thus reducing the overall cost), by removing the balances variable; however, note that this variable is there to protect you from distributing more than once per each address (checking the actual balance of that address is useless for this purpose, since its owner can easily transfer his/her tokens from this address to some other address).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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