ERC20 batchTransfer functionality

Hi there, I asked this question in a telegram group a few days ago and I think it is worth being asked again here. Do you guys think it is necessary to create an ERC20 extension with a batchTransfer functionality? As the name implies, the interfaces can be:

function batchTransfer(address[.] memory recipients, uint256[.] memory amounts) public;
function batchTransfer(address[.] memory recipients, uint256 amount) public;

This should be useful nowadays given the gas fees are increasing rapidly.

2 Likes

Hi @maxareo,

It depends on the use case for the ERC20 token. Though anything which reduces the amount of gas would be good.

I did some experiments and found out batchTransfer can save 5% transaction cost for 3 recipients a batch, roughly 35% for 7 recipients a batch and up to 67% for 14 recipients a batch.

# cost per recipient for 3 recipients
(39257 - 37187)/39257

# cost per recipient for 7 recipients
(39257 - 25583)/39257

# cost per recipient for 14 recipients
(39257 - 12970)/39257

The gains seem to be fairly convincing.

1 Like

Hi @maxareo,

You could also look at using Multicall: Release Candidate for Contracts 4.1

I like this abstraction, however, would there be an example walking us through a use case?

function multicall(bytes[] calldata data) external returns (bytes[] memory results) {
    results = new bytes[](data.length);
    for (uint i = 0; i < data.length; i++) {
        results[i] = Address.functionDelegateCall(address(this), data[i]);
    }
    return results;
}

Like how someone can pass input parameters and what will be returned? No example can be better than a batchTransfer of ERC20 tokens. Thanks.

1 Like

Hi @maxareo,

Have a look at the tests for Multicall for an example:

2 Likes

Can you help me? I need to send to multiple wallets paying the lowest possible fees. I saw a transaction on BSC that paid only 2 Dollars of fee to send to 500 different wallets.
I want to do the same but I don't know how to do it