0

I'm trying to write something like ICO projects do and I got this problem when it comes to withdraw the ether in the contract's balance to my wallet.

function withdrawal () public payable 
{                       
    address bank = 0x...... ;
    address myAddress = this;
    require(myAddress.balance >= 1000000000000000);
    bank.transfer(address(this).balance);

   } 

When the contract has ether in it, nothing happens. It doesn't even try to send it. So I'm wondering what I am doing wrong, or if there is a better way to do it. Thanks in advance guys, appreciate every answer.

0

I suspec that your contract doesn't actually have a valid balance and/or require(myAddress.balance >= 1000000000000000); is your problem. You should change this to require(address(this).balance >= 1000000000000000) That being said this is incredibly inefficient code and can be better written as

contract ICO {
    address public bank = ......;

    function withdrawal() public {
        require(address(this).balance >= 1000000000000000);
        bank.transfer(address(this).balance);
    }

}

Also make sure the address declare as bank isn't a contract, and if it is, that it has a payable fallback function, otherwise this will also fail

edit:

Due to the way your code written I suspect you are quite new to solidity, and don't yet understand all the gotchas, intricacies, and tricks that come to writting solidity smart contracts. I would recommend trying simpler contracts first, and become better affiliated with the language before attempting to write ICO contracts.

https://github.com/ConsenSys/smart-contract-best-practices

https://theethereum.wiki/w/index.php/ERC20_Token_Standard

http://solidity.readthedocs.io/en/v0.4.24/introduction-to-smart-contracts.html

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.