0

I need to send BNB or BSC tokens to multiple addresses. I saw some answers but they are used for loop. I can't use a loop because it takes a lot of time and the server is not responding. Is there any method to solve this process?

I'm trying the node-js sendTransaction method but there is no chance to send multiple addresses.

1 Answer 1

0

You could submit a flashbot bundle (https://docs.flashbots.net/flashbots-auction/searchers/advanced/understanding-bundles) (EDIT : Oops, no, they don't exist on the BSC) Or use a smart contract for that. Here's an example for ETH

contract Sender {
  function sendETHToAddresses(address[] calldata to, uint[] calldata values) external payable {
    require(to.length == values.length, "mismatched inputs");
    // inefficient,do the check in JS before sending 
    /* 
    uint sum;
    for(uint i; i < values.length; ++i) {
      sum += values[i];
    }
    require(sum <= msg.value, "Not enough ETH");
    */
    for(uint i; i < values.length; ++i) {
      (bool os, ) = payable(to[i]).call{value: values[i]}(new bytes(0));
      require(os, "transfer failed");
    }
  }
}
4
  • It's solidity? And ur using for loop. I think it takes lot of time.
    – sri vijay
    Commented Jan 18, 2023 at 5:55
  • It is solidity, yes. And no, that would be only one transaction, so you're eliminating your sever issue
    – Foxxxey
    Commented Jan 18, 2023 at 6:03
  • So I first need to write solidity (for multiple addresses send Process ) right? And I can't solve this process without writing solidity right?
    – sri vijay
    Commented Jan 18, 2023 at 6:06
  • Yes. I believe there is no way not to use a loop. In the solution above you write a contract and every transfer call you call this contract. This is the best solution, as well as being cheaper for you. If you haven't solved this problem yet let me know.
    – Ether Man
    Commented May 20 at 4:13

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.