7

I've been playing with Token contracts, so far so good, however once the Ether is sent and the tokens created, what happens to the Ether?

I have some Ether on the contract address, how do I withdraw it?

I guess it's not about the contract code but about the interface, I've been using Ethereum Wallet. The send funds screen only allows to fund the contract, not send from it.

1
  • 2
    The contract has to have an explicit method to make a transfers to an address. Another possibility is if the contract has a selfdestruct option. If the contract has none of this then I'm afraid the ether is stuck within it.
    – Ismael
    Commented Sep 2, 2017 at 17:34

1 Answer 1

8

The function would be something like this:

pragma solidity >=0.8.0;

function withdraw() {
    payable(msg.sender).transfer(address(this).balance);
}

Just make sure you only allow yourself to access it

1
  • Indeed, adding require ( msg.sender == owner ); before the transfer was all it took. Thank you. Commented Sep 5, 2017 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.