I have more than one ETH wallet. I want to automatically combine these wallets into one wallet. For example, when I get an ETH in wallet 0x1, I want it to automatically transfer it to wallet 0x2. Can I do this with a smart contract? Or how can I do it? Can you help me?
2 Answers
You can use a simple contract with a payable fallback function for this. For example:
pragma solidity 0.7.0;
contract Forwarder {
address payable owner;
constructor (address payable _owner) {
owner = _owner;
}
fallback () external payable {
owner.transfer(msg.value);
}
}
Every time ETH is sent to the contract, the fallback function is called, which forwards the ETH (msg.value
) to owner
.
-
Thank you but that's not what I want. I want it transferred when ETH comes to my A wallet, not a contract.– wexweysAug 12, 2020 at 17:13
-
You asked "Can I do this with a smart contract?", if you don't want to use a smart contract, you'll have to set up some kind of system that checks for incoming transactions, and automatically sends a new transaction. You can't pull ETH from an address with a smart contract.– MortenAug 12, 2020 at 20:01
You can do it using a forwarder wallet, you instruct your user to transfer to an address which will automatically transfer inbound funds to a parent/central wallet.
Here's a project i created doing the same: https://github.com/farirat/solidity-forwarder-wallet
Run the tests and you will get the complete workflow.