1

I deployed a smart contract for crowdsale that has a function of receiveETH():

function receiveETH(address beneficiary) internal {      
    uint coinToSend = bonus(msg.value.mul(COIN_PER_ETHER).div(1 ether)); // Compute the number to send
    Backer backer = backers[beneficiary];
    coin.transfer(beneficiary, coinToSend); // Transfer right now 
    backer.coinSent = backer.coinSent.add(coinToSend);
    backer.weiReceived = backer.weiReceived.add(msg.value); // Update the total wei collected during the crowdfunding for this backer    
    etherReceived = etherReceived.add(msg.value); // Update the total wei collected during the crowdfunding
    coinSentToEther = coinSentToEther.add(coinToSend);
    // Send events
    LogCoinsEmited(msg.sender ,coinToSend);
    LogReceivedETH(beneficiary, etherReceived); 
}

this contract I have deployed on testnet, but it could not receive ether. For example, I use some test accounts to send ether to that deployed smart contract address, everytime it says success on etherscan and the Tx cost is deducted, while the ether is not successfully transferred and smart contract ether amount remains 0. linkenter image description here

I wonder what's wrong here? Does crowdsale contract has a function that's triggered everytime a new transfer comes in?

P.S. just noticed I have the fallback function defined:

function() stopInEmergency respectTimeFrame payable {
    receiveETH(msg.sender);
}

it looks perfect for me, but still my contract does not receive ether when I try to send to it. What else is wrong here?

  • is it because of payable keyword? I tried to add payable but it says internal function cannot be payable – Zixuan Zhang Oct 2 '17 at 19:01
1

The internal keyword means that your function can only be called from within the contract or contracts deriving from it. You cannot call it publicly.

If you want this function to be callable from outside of the contract, you should change internal to public.

You do need to add payable if you plan to have any Ethereum be sent on with this function call.

To fix this, change you should change internal to public payable, which should make this function be callable publicly and also enable it to be sent Ethereum along with the transaction.

Does crowdsale contract has a function that's triggered everytime a new transfer comes in?

For transferring Ethereum, yes. This would be the fallback function. Though, only 2300 gas is available. There is no function that is called on transfer for ERC20 tokens currently.

  • Thanks Alec, I now understand fallback function meaning. Please take a look at my added content, the fallback function is actually defined but it still won't receive ether – Zixuan Zhang Oct 2 '17 at 19:25
  • @ZixuanZhang On both of the transactions, the Gas Used is as much as the Gas Limit. This suggests something is causing an error or throwing because when there is an error, all gas is immediately consumed. Check to ensure nothing is causing an error and that your gas limit is high enough. – Alec Kriebel Oct 2 '17 at 20:20
0

Figured out the problem myself, it was because I didn't transfer my token contract ownership to my crowdsale contract.

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.