2

I can receive ETH and transfer to owner via:

function () payable {
    owner.transfer(msg.value); // owner = address of owner
}

How can I have a function which does the reverse thing? Take ETH from owner and transfer to msg.sender?

5

You can't take Eth from anyone. The contract has only access to Ether which is stored inside the contract. So the owner has to send Ether to the contract which the contract can then send to wherever (for example msg.sender in another function call).

0

using smart contract to transfer from user address to smart contract address and transfer ETH to the address which you want with:

function withdraw(address _to) public {
    _to.transfer(address(this).balance);
}

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.