13

Is it possible sending ether to multiple addresses in one go, better called batch sending? I want to make an API to transfer ether to 100 address at once so that I do not need to make 100 transactions.

1
  • Here is Dapp for ether and erc20 token batch sending: bulksender.app
    – howe
    Oct 14, 2020 at 4:07

4 Answers 4

13

Here is Dapp to make it easier for you: https://multisender.app

If you want to do it yourself, here is some code for you

contract MultisenderApp {

function multisendEther(address[] calldata _contributors, uint256[] calldata _balances) external payable {
    uint256 total = msg.value;
    uint256 i = 0;
    for (i; i < _contributors.length; i++) {
        require(total >= _balances[i]);
        assert(total - _balances[i] > 0);
        total = total - _balances[i];
        (bool success, ) = _contributors[i].call.value(_balances[i])("");
        require(success, "Transfer failed.");
    }
}    

this way, you can be sure that whoever interacts with this function, won't take more eth than he/she should.

9

This can be kinda of delicate at times, but web3 does support batch requests https://github.com/ethereum/wiki/wiki/JavaScript-API#batch-requests Here is their example on their site. I can include an example for sending ether if this is not clear

var batch = web3.createBatch();
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
batch.add(web3.eth.Contract(abi).at(address).balance.request(address, callback2));
batch.execute();

The Specific example would be something akin to eth.sendTransaction({from:sender, to:receiver, value: amount})

var batch = web3.createBatch();
batch.add(web3.eth.sendTransaction({from:sender, to:receiver, value: amount}));
batch.add(web3.eth.sendTransaction({from:sender, to:receiver2, value: amount2}));
batch.execute();

Just an FYI Batching requests do not make them faster! Making many requests at once will sometimes be faster, as requests are processed asynchronously. Batch requests are mainly used to ensure events happen in serial.

8
  • i just want to send ether. why do i need to include contract abi?
    – rahul_eth
    May 8, 2018 at 14:19
  • This was the example on their site for generic batch requests which didn't show sending but would be very similar, I can edit it for specifically sending ether if that will help. May 8, 2018 at 14:20
  • I want to make 10 ether transaction to 10 different addresses in the single transaction fee. does it possible through batch transaction?
    – rahul_eth
    May 8, 2018 at 14:23
  • I added in an example for sending ether May 8, 2018 at 14:35
  • 1
    will try and reach you soon
    – rahul_eth
    May 8, 2018 at 14:44
2
function sendBatch(address[] _addrs) public payable {
    for(uint i = 0; i < _addrs.length; i++) {
        _addrs[i].transfer(msg.value.div(_addrs.length));
    }
}

This simple solidity function would do exactly what you're asking about. You would just need to provide an array of addresses when executing the function and it will split the ETH you send to all those addresses evenly.

0

if you want batch send Ether or Token,you can use: https://algocryptodapp.github.io/Bee-Sender/

or send ether use solidity:

 for (uint i=0; i < address.length; i++) {
            address[i].transfer(amounts[i]);
        }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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