Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ethereum : How to auto-split an ETH transaction into 2 other transactions

Let's say I have a shared wallet where ethers are collected for me and my brother. We share 50% each other of this wallet.

if one ETH transaction comes to this wallet, is there an automated way to auto send received ethers to my personal wallet and to my brother's one, without us to do anything special?

Can it be done through a special smartcontract (with fallback) or any other way?

like image 851
Jean F. Avatar asked Nov 08 '22 05:11

Jean F.


1 Answers

You can deploy this contract (don't forget change addresses)

When someone sends you ethers, he needs to put 100000 gas, this additional gas needs to send 2 transactions: for you and your bro

pragma solidity ^0.4.25;
contract Split {
    address public constant MY_ADDRESS = 0x5Ac652E32b8064000a4ab34aF0AE24E4966E309E;
    address public constant BRO_ADDRESS = 0x43CcDF0774813B6E14E64b18b34dE438B039663C;

    function () external payable {
        if (msg.value > 0) {
            // msg.value - received ethers
            MY_ADDRESS.transfer(msg.value / 2);
            // address(this).balance - contract balance after transaction to MY_ADDRESS (half of received ethers)  
            BRO_ADDRESS.transfer(address(this).balance);
        }
    }
}
like image 72
Yegor Zaremba Avatar answered Nov 15 '22 11:11

Yegor Zaremba