4

I would like to know how to send ether from multiple accounts. For example, suppose I have 3 accounts with 5 ether in each account, how do I send the total (15 ether) to an account in a single transaction? I’m asking because from what I understand the “from” parameter in “sendTransaction” only accepts a single account.

The reason I’m asking this is because I need to accept Ether payments in my system and I would like to generate a unique account for each deposit, but I’m not sure how to spend the Ether I receive without having to send multiple transactions.

I want my users to deposit tokens to my address. Now let us say 10 users send 1 token each. There would be 10 corresponding addresses. Now how do I implement this such that my main address always show the total sum amount (10 tokens, in this case) and whenever I try to withdraw that amount, the transaction is actually happening on 10 different addresses , but how do I post it as a single transaction ?

Can it be possibly done using HD Wallets ? How does coinbase internally handle the spending from multiple transactions as a single transaction ?

1 Answer 1

1

As you noticed, there is no way to send a single from multiple addresses. There is always just one sender.

For Ether transfers the Ether value is always taken from the sender's balance and you can't take it from other accounts (that would be a rather big security hole). You can't take them in one transaction even if you have their private keys. But what you can do is create a smart contract which uses a factory pattern - it creates new smart contracts whenever needed. Each of these smart contracts has a unique address and they can be used to forward the assets to one single address. So the sender sends to one of the contracts created by such a factory contract and that contract forwards the Ethers with some logic.

For tokens, the basic ERC20 token does not support multiple senders. But you have a lot more freedom here if you write your own token - you are free to add more functionality which is outside the standard. In theory you can do almost whatever you want - even take tokens from other users' balances since you write the transfer logic.

If you want to accept some already existing tokens (which are more orthodox and secure) you don't have many options either. The best option, probably, is to get your users to approve your custom contract to spend their tokens and then, in one transaction, your custom contract withdraws the tokens from all of their balances with transferFrom.

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.