I am having a crowdsale contract. I am trying to run contribute function using command: contractInstance.contribute.sendTransaction(101,{from:eth.accounts[0],value:200, gas:4000000}). It is creating a transaction hash. After mining I can see the value = 200 and to: contractAddress. But it doesn't increase the contract balance. I am getting no error. My contribute function is as:

function contribute(uint _campaignID){       
    Campaign c = campaigns[_campaignID];      
    uint256 amount = msg.value; 
    c.balanceOf[msg.sender] = amount;    
    c.amountRaised += amount;
    check = 'check4';
    check = 'check5';
    FundTransfer(msg.sender, amount, true);      //event     

Variable check is used for testing purpose. Even check variable is not updated. It is working fine in solidity browser. I am using geth client. Please tell me where i am wrong?

  • 1
    Quick note, you should make it c.balanceOf[msg.sender] += amount; to allow for more than 1 contribution per sender. Sep 2 '16 at 15:01
  • When coming in the function, you should make sure the campaign exists. Perhaps check that c.tokenValue > 0. Sep 2 '16 at 15:14
  • 1
    Remove the token.transfer line, perhaps it is the one throwing. Sep 2 '16 at 15:14
  • Yeah, one check was throwing error in transfer function, now it is resolved, Thanks!!
    – Aniket
    Sep 5 '16 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.