Please, how can I remove ether that's stuck in a contract? If it's impossible to do that, what then is the function that will enable me remove ether from a contract I created?

  • Could you post up a link to the contract? Did you include any withdrawal or selfdestruct functions in the contract when you wrote it? – TC8 Jan 28 '18 at 12:21
  • TC8, I did not include it because I don't know how to. This is the link to the contract I copied hashnode.com/post/… – sissy Jan 28 '18 at 12:52
  • If you could, paste the address of the contract? – Victory Jan 28 '18 at 13:51

Once a contract has been published there's no way to modify it, so if no withdrawal or selfdestruct functions were included then there is no means of adding them to the contract at a later date, and the funds are effectively stuck in that contract forever.

Looking at the contract in the link you supplied,the 'HashnodeTestCoin' contract does define the following:

address public fundsWallet;           // Where should the raised ETH go?

and in the constructor function this address is assigned to the contract creator (final line):

// This is a constructor function 
// which means the following function name has to match the contract name declared above
function HashnodeTestCoin() {
        balances[msg.sender] = 1000000000000000000000;               // Give the creator all initial tokens. This is set to 1000 for example. If you want your initial tokens to be X and your decimal is 5, set this value to X * 100000. (CHANGE THIS)
        totalSupply = 1000000000000000000000;                        // Update total supply (1000 for example) (CHANGE THIS)
        name = "HashnodeTestCoin";                                   // Set the name for display purposes (CHANGE THIS)
        decimals = 18;                                               // Amount of decimals for display purposes (CHANGE THIS)
        symbol = "HTCN";                                             // Set the symbol for display purposes (CHANGE THIS)
        unitsOneEthCanBuy = 10;                                      // Set the price of your token for the ICO (CHANGE THIS)
        fundsWallet = msg.sender;                                    // The owner of the contract gets ETH

the contract looks to be structured so any eth it receives should be forwarded to the fundsWallet address - it's not the nicest way of doing things but it should have worked!

did you change the name of the contract from 'HashnodeTestCoin', and if so did you also change the name of the constructor function to match it?

You haven't stated which Contract you deployed, or the arguments you passed it either. If you didn't deploy HashnodeTestCoin (or whatever you renamed it to) then the owner address may not have been assigned correctly. If you changed the name of the contract but didn't update the name of the Constructor then it would never have run the constructor and thus never assigned your address as fundsWallet.

A more conventional means of assigning ownership is to create an 'Ownable' contract first, then define 'HashnodeTestCoin' as 'Ownable'; this would make sure your address is assigned to the contract when it was deployed. the Ownable contract would look something like this:

contract Ownable {
    address public owner;

    function Ownable() {owner = msg.sender;}

    modifier onlyOwner {
        if (msg.sender != owner) throw;

    function transferOwnership(address newOwner) onlyOwner {
        if (newOwner != address(0)) {
            owner = newOwner;

Then HashnodeTestCoin would be declared as follows:

    contract HashnodeTestCoin is StandardToken, Ownable {
|improve this answer|||||
  • TC8, thanks a lot. I haven't verified my contract, but it's exactly like this, but of course I changed the name, and other stuff. But when all the tokens have been bought, and I sent ether to the contract address, it ceased the ether. It didn't send tokens because it's finished, but it ceased the ether that was sent. So I'm looking for a way to add a withdrawal function that I can use to withdraw stuck ether in the next contract I plan to deploy.. Exactly like this. – sissy Jan 28 '18 at 14:05
  • This page may be useful for your next contract - there are some major pitfalls to avoid when it comes to withdrawal functions! – TC8 Jan 28 '18 at 14:50
  • TC8 I'm not good with solidity codes and all. Please can you give me the withdrawal function code that I can put in the contract to withdraw stuck ether. I read somewhere that to withdraw, you can go to MEW and interact with it there. – sissy Jan 28 '18 at 15:15
  • As much as I'd like to help @sissy I'm afraid it would be counter-productive for me to just send you the function for you to copy and paste it into your contract - if you're developing public crowdsale contracts you'll be handling other people's money and I'd advise learning how to code properly before deploying anything on the mainnet! – TC8 Jan 28 '18 at 15:27

All the Ether sent to your contract is immediately forwarded to the owner of the contract. Its in the code, check it.

|improve this answer|||||

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.