1

Hi I've been reading around and I came across Web3.js

It's not apparent to me how I can send Ether from one wallet to multiple recipients other than in a batch-style request (which inevitably takes a lot of time and is prone to failure)

I see people suggesting contracts but almost 9/10 of the posts I read were referring to ERC20 tokens but I am looking to send just plain ol' Ether.

I have a website where people are going to be earning Ethers and all types of cryptos and the amount they earn is stored in a MongoDB database,

For Monero, I just pull the values the earn from the MongoDB database and push them into an array. I wait for the array to be filled with Promises and then I execute the function with an array, and Monero Wallet RPC knows that its an array and sends all the transactions out as one big payment.

How do I do something similar in Ethereum?

0

You'll have to use a smart contract to fulfill your purpose.

A short pseudo example:

// example code - proceed with cation before using on the mainnet!!!

function batchEtherSend(uint256[] amounts, address[] receipents) payable public {
    require(amounts.length == receipents.length, "invalid params");

    // for loop 
        if(addresses[i] != address(0)) { // check for valid address 
            addresses[i].transfer(amounts[i]); // note transfer will revert if any one fails
        }

}
  • 1
    this example is for solidity or web3js? – knitty Mar 26 at 10:39
  • This would be in Solidity as it's a smart contract. If this were in web3.js it would represent multiple transactions, not one. Which is what you wanted to avoid. – MSwezey Mar 26 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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