0

Is there any possibility to withdraw ether from crowdsale contract? 0x6c725F41E98451F167820551013BD2f5BE8bFE6f

I had also "pre-sale like" contract has MyToken in it 0x0b43BC4bF3f5a3596d720b5f9D40DF3A4F64B01f shoud be closed by deadline

Contract to interact with tokens (0x4bA192fED75E40B0Ddf641c0e4149B08a73C59f0) (code avail at etherscan)

And token contract which transfers tokens if user send funds(eth) to contract (where now funds stuck(ABI + code below))

I tried to use SafeWithdrawal (for sure it didn't work) One of contributors bouht tokens 2 times 33+33 tokens( https://etherscan.io/tx/0x4bac9c86a1e366230ff6f837fa2b4bc384cf079e884ea192076c7a88ff206812) and https://etherscan.io/tx/0x0fa28f20142e5b7d5789273fb0f9fd6369476e9abf216293e0f8758ccf317074) and then sent it back to contract but in one tx (66) contract to withdrewed him only half of value he spent. (0.5 eth instead 1) I tried to send tokens back from all adresses i can.. but has no result (maybe amount was too large >33?) So now i have no idea how to withdew funds from contract as a creator

[ { "constant": false, "inputs": [], "name": "checkGoalReached", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "deadline", "outputs": [ { "name": "", "type": "uint256", "value": "1504678344" } ], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "beneficiary", "outputs": [ { "name": "", "type": "address", "value": "0xd702dbc0da81ea63621a0b181e12a15e2748e87c" } ], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "tokenReward", "outputs": [ { "name": "", "type": "address", "value": "0x4ba192fed75e40b0ddf641c0e4149b08a73c59f0" } ], "payable": false, "type": "function" }, { "constant": true, "inputs": [ { "name": "", "type": "address" } ], "name": "balanceOf", "outputs": [ { "name": "", "type": "uint256", "value": "0" } ], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "fundingGoal", "outputs": [ { "name": "", "type": "uint256", "value": "2.7825e+22" } ], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "amountRaised", "outputs": [ { "name": "", "type": "uint256", "value": "0" } ], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "price", "outputs": [ { "name": "", "type": "uint256", "value": "15000000000000000" } ], "payable": false, "type": "function" }, { "constant": false, "inputs": [], "name": "safeWithdrawal", "outputs": [], "payable": false, "type": "function" }, { "inputs": [ { "name": "ifSuccessfulSendTo", "type": "address", "index": 0, "typeShort": "address", "bits": "", "displayName": "if Successful Send To", "template": "elements_input_address", "value": "0xd702dbc0da81eA63621a0B181E12a15E2748e87C" }, { "name": "fundingGoalInEthers", "type": "uint256", "index": 1, "typeShort": "uint", "bits": "256", "displayName": "funding Goal In Ethers", "template": "elements_input_uint", "value": "27825" }, { "name": "durationInMinutes", "type": "uint256", "index": 2, "typeShort": "uint", "bits": "256", "displayName": "duration In Minutes", "template": "elements_input_uint", "value": "65500" }, { "name": "finneyCostOfEachToken", "type": "uint256", "index": 3, "typeShort": "uint", "bits": "256", "displayName": "finney Cost Of Each Token", "template": "elements_input_uint", "value": "15" }, { "name": "addressOfTokenUsedAsReward", "type": "address", "index": 4, "typeShort": "address", "bits": "", "displayName": "address Of Token Used As Reward", "template": "elements_input_address", "value": "0x4bA192fED75E40B0Ddf641c0e4149B08a73C59f0" } ], "payable": false, "type": "constructor" }, { "payable": true, "type": "fallback" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "beneficiary", "type": "address" }, { "indexed": false, "name": "amountRaised", "type": "uint256" } ], "name": "GoalReached", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "backer", "type": "address" }, { "indexed": false, "name": "amount", "type": "uint256" }, { "indexed": false, "name": "isContribution", "type": "bool" } ], "name": "FundTransfer", "type": "event" } ]

    pragma solidity ^0.4.2;
    contract token { function transfer(address receiver, uint amount){  } }
    
    contract Crowdsale {
        address public beneficiary;
        uint public fundingGoal; uint public amountRaised; uint public deadline; uint public price;
        token public tokenReward;
        mapping(address => uint256) public balanceOf;
        bool fundingGoalReached = false;
        event GoalReached(address beneficiary, uint amountRaised);
        event FundTransfer(address backer, uint amount, bool isContribution);
        bool crowdsaleClosed = false;
    
        /* data structure to hold information about campaign contributors */
    
        /*  at initialization, setup the owner */
        function Crowdsale(
            address ifSuccessfulSendTo,
            uint fundingGoalInEthers,
            uint durationInMinutes,
            uint finneyCostOfEachToken,
            token addressOfTokenUsedAsReward
        ) {
            beneficiary = ifSuccessfulSendTo;
            fundingGoal = fundingGoalInEthers * 1 ether;
            deadline = now + durationInMinutes * 1 minutes;
            price = finneyCostOfEachToken * 1 finney;
            tokenReward = token(addressOfTokenUsedAsReward);
        }
    
        /* The function without name is the default function that is called whenever anyone sends funds to a contract */
        function () payable {
            if (crowdsaleClosed) throw;
            uint amount = msg.value;
            balanceOf[msg.sender] = amount;
            amountRaised += amount;
            tokenReward.transfer(msg.sender, amount / price);
            FundTransfer(msg.sender, amount, true);
        }
    
        modifier afterDeadline() { if (now >= deadline) _; }
    
        /* checks if the goal or time limit has been reached and ends the campaign */
        function checkGoalReached() afterDeadline {
            if (amountRaised >= fundingGoal){
                fundingGoalReached = true;
                GoalReached(beneficiary, amountRaised);
            }
            crowdsaleClosed = true;
        }
    
    
        function safeWithdrawal() afterDeadline {
            if (!fundingGoalReached) {
                uint amount = balanceOf[msg.sender];
                balanceOf[msg.sender] = 0;
                if (amount > 0) {
                    if (msg.sender.send(amount)) {
                        FundTransfer(msg.sender, amount, false);
                    } else {
                        balanceOf[msg.sender] = amount;
                    }
                }
            }
    
            if (fundingGoalReached && beneficiary == msg.sender) {
                if (beneficiary.send(amountRaised)) {
                    FundTransfer(beneficiary, amountRaised, false);
                } else {
                    //If we fail to send the funds to beneficiary, unlock funders balance
                    fundingGoalReached = false;
                }
            }
        }
    }
4
  • By reading the contract: yes, it sends Ethers if certain conditions are met Jan 11, 2022 at 16:29
  • Maybe safewithdrawal doesn't work cause amountRaised = 1.3eth but contract has only 0.5 or there is no approval for creator adress (balanceOf)?
    – okayBro
    Jan 11, 2022 at 16:39
  • 1
    Your overall question is very vague, so I gave a very vague answer. Please edit your question to pinpoint your problem, what you have tried, what doesn't work and other needed details. Jan 11, 2022 at 16:54
  • 1
    "Maybe safewithdrawal doesn't work cause amountRaised = 1.3eth but contract has only 0.5" Yep, this is why.
    – Foxxxey
    Dec 7, 2022 at 1:39

1 Answer 1

1

The contract has a bug. It always overrides balanceOf[msg.sender], so if it was called twice it will only count the last one.

    function () payable {
        if (crowdsaleClosed) throw;
        uint amount = msg.value;
        /* *** BUG *** */
        balanceOf[msg.sender] = amount;
        /* *** BUG *** */
        amountRaised += amount;
        tokenReward.transfer(msg.sender, amount / price);
        FundTransfer(msg.sender, amount, true);
    }

It could be fixed with balanceOf[msg.sender] += amount.

Your Answer

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

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