2

I'm trying to create a simple airdrop contract. I'm fairly experienced with Solidity, so this is not a completely noob question - but maybe I'm missing something.

My airdrop contract has a function that accepts an array of addresses

 function bulkWhitelist
    (
        address[] calldata _to,
        address _projectAddress,
        string calldata _projectName
    )
    public onlyRole(WHITELISTER_ROLE) {
        for (uint256 i=0; i<_to.length; i++) {
            whitelist[_to[i]] = true;
        }
        emit BulkWhitelist(_to, _projectAddress, _projectName, block.timestamp);
    }

Simple, I know, but I would like to keep the architecture as simple as possible.

Everything works well if I pass around 650 addresses or less to the contract as an array, but if I try to add more, I get a transaction block gas limit error. The problem is, increasing the block gas limit makes no difference - after around 650 addresses, the error always comes up with a number above the current gas limit, no matter how much I raise it.

The error also comes up if I remove the for loop from the contract - so it doesn't seem to be a gas limit per se.

I am using hardhat and I haven't deployed to a testnet to see if I still get the error - so it may be a hardhat limitation. I'll try that later, but until I get to doing it, the question is: Does anyone know of any inherent limitation in Solidity that will limit the amount of addresses that I can pass within an array as a function argument? I can't find anything online, bar the well-known 'maximum 16 arguments' limit.

Thanks

1 Answer 1

2

The block gas limit is the upper limit for a block and it is a constant. You cannot have a transaction that consumes a limit that is more than the block gas limit.

If you want to do a batch transfer, then I would suggest you to break the number fo addresses into smaller chunks, loop through the chunks and pass the batch as an array into the smart contract.

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.