2

I'm trying to send tokens to multiple wallets as soon as possible.

A. function can be run by only one wallet under onlyOwner.

   function batchTransfer(address[] memory receivers, uint256[] memory amounts)
        external
        onlyOwner
    {
        for (uint256 i = 0; i < receivers.length; i++) {
            _transfer(receivers[i], amounts[i]);
        }
    }

B. function can be run by 5 wallets registerd under Authorized.

   function batchTransfer(address[] memory receivers, uint256[] memory amounts)
        external
        Authorized
    {
        for (uint256 i = 0; i < receivers.length; i++) {
            _transfer(receivers[i], amounts[i]);
        }
    }

Which would be faster to send tokens to multiple wallets?

Using 5 wallets to run function B at around the same time vs. Using one wallet to run function A 5 times.

2 Answers 2

1

Using multiple wallets to execute case B will reduce the overall time required to send tokens to multiple wallets. Still, it comes with some additional risks such as multiple calls will be generated to update the same state on the blockchain which might cause some issues.

So, its better to stick with case A just to be on the safe side.

2
  • thanks! then if I stick to case A, up to how many wallets can I send per transaction? any recommended or usual process to do that?
    – bbusdriver
    Commented Apr 17, 2023 at 6:06
  • 1
    That depends on which blockchain you're using There is no specific number but I once did a transaction with loop of 250 Commented Apr 17, 2023 at 7:01
1

The speed of token transfers depends on network congestion, gas prices, and transaction execution time. It has nothing to do with the complexity of the function. A single _transfer will take as much time as batchTransfer

To determine to how many wallets you can send tokens to in a single transaction, you'll need to estimate the gas consumption per iteration in the loop.

In theory, you can use up to the block gas limit, which is 30M gas on most of the network. But in practice, it depends on how much you pay for gas and how the network is congested.

Eth Gaslimit

Polygon Gaslimit

But from my experience on a batch transfer, you can easily send to up to 100 to 200 addresses.

1
  • Thanks. Good to know, but my question is whether I should run case B in parallel with multiple accounts to send tokens to more people than using only 1 account like case A
    – bbusdriver
    Commented Apr 17, 2023 at 8:37

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.