0

By reading through posts and questions/answers here and there, I realized that there're no multiple inputs and outputs on one transaction in Ethereum, which is different from Bitcoin.

I also learned that by using contract, you can send to multiple addresses with just one transaction to that contract, like this.

function sendToMany(address[] recipients) {
    for(uint i = 0; i< recipients.length; i++){
         i.send(msg.value/recipients.length);
     }
}

So I'm wondering how I can combine multiple input addresses using contract. Any suggestion or skeleteon solidity code for this?

2

You could combine multiple inputs and then forward the money as follows (This is a rough example, which works, but could use more validations, keeping track of what each account sent, etc.):

uint public requiredSenders = 10; // How many people have to contribute before transferring to beneficiary. (Could be eth accumulated instead).
uint public currentSenders = 0;
uint public accumulatedFunds = 0;

address public beneficiary = 0x0...; // Who receives the money.

function combineAndTransfer() public payable {
 currentSenders++;
 require(currentSenders <= requiredSenders);

 // Accumulate funds
 accumulatedFunds += msg.sender;

 //If requirements are met, transfer the funds.
 if(currentSenders == requiredSenders){
  uint fundsToTransfer = accumulatedFunds;
  accumulatedFunds = 0;
  beneficiary.transfer(fundsToTransfer);
 }

}

Notice that this requires each account to individually execute the function to send the funds and then, when the last of them sends the funds (meeting the requirements) the accumulated funds are transferred to the beneficiary.

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.