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.
5 Answers
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.
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.
-
i just want to send ether. why do i need to include contract abi? Commented 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. Commented 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? Commented May 8, 2018 at 14:23
-
-
1
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.
-
Good morning! Hello! Great answer! It looks like it is THAT easy! Can you please explain what is this ".div"? Commented Jun 13 at 14:52
Yes, it is possible to send Ether to multiple addresses in one transaction on Ethereum, commonly referred to as batch sending. One approach is to use a smart contract where you iterate over a list of addresses and amounts, executing transfers within a single function call. Here's a basic example in Solidity:
pragma solidity ^0.8.0;
contract BatchSender {
function sendEther(address[] memory recipients, uint[] memory amounts) external payable {
require(recipients.length == amounts.length, "Arrays length mismatch");
for (uint i = 0; i < recipients.length; i++) {
payable(recipients[i]).transfer(amounts[i]);
}
}
}
In this example, the sendEther
function takes arrays of recipient addresses (recipients
) and corresponding amounts (amounts
), and transfers Ether to each recipient in a single transaction.
Alternatively, for a more user-friendly and efficient solution, consider using Off Grid Platform's Bulk Sender. It provides a straightforward way to send native coins, tokens, and NFTs in batches across multiple EVM-compatible chains, including Ethereum. You can explore more about it here: OGP Bulk Sender.
Using Bulk Sender can help simplify the process, optimize gas costs, and ensure secure and reliable distribution of assets across multiple addresses.
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]);
}
}