Can someone help me and tell me where in my code is the problem. How to fix this ?


Is there any obvious error ? Help is more than appreciate.Robert

  • What are you trying to do? What is your code? – Lauri Peltonen Apr 9 '18 at 13:41
  • So this is my code. I try to do a test and send ether to the crowdsale contract and get back the right value of my tokens. I hope is easy to fix. I'm not a programmer. Any help from You is really appreciate.Robert – ROBERT Apr 9 '18 at 13:50
  • My code: ropsten.etherscan.io/address/… – ROBERT Apr 9 '18 at 14:03

When sending ether to the contract address it would call this function in your contract:

function () payable whenNotPaused beforeDeadline afterStartTime saleNotClosed  {
    require(msg.value >= minContribution);

    // Update the sender's balance of wei contributed and the amount raised
    uint amount = msg.value;
    uint currentBalance = balanceOf[msg.sender];
    balanceOf[msg.sender] = currentBalance.add(amount);
    amountRaised = amountRaised.add(amount);

    // Compute the number of tokens to be rewarded to the sender
    // Note: it's important for this calculation that both wei
    // and PDT have the same number of decimal places (18)
    uint numTokens = amount.mul(rate);

    // Transfer the tokens from the crowdsale supply to the sender
    if (tokenReward.transferFrom(tokenReward.owner(), msg.sender, numTokens)) {
        FundTransfer(msg.sender, amount, true);
        // Check if the funding goal or cap have been reached
        // TODO check impact on gas cost
    else {

The transaction would be reverted if either:

  • contract is paused
  • after deadline
  • before start time
  • sale is closed
  • value is less than minimum contribution
  • funding goal or cap has been reached
  • Thanks Koukotsu ! --Thanks to you, I see the problem more clearly,but this solves the problem partially, I need to do a test. I understand that there is no error ! and a modification of the payable function is needed to make test ? – ROBERT Apr 10 '18 at 8:47
  • Did the token owner authorized your contract to be able to make transfers? ie, token.approve("0x4927f2ad....", amount, { from: "0xOwnerAddress" }); – Ismael Apr 10 '18 at 19:33
  • Hello Ismael, thank you for being interested in my problem. I think the problem lies in the message -gas required exceeds allowance or always failing transaction ,when I try to transfer ether to crowdsale contract here:ropsten.etherscan.io/address/… – ROBERT Apr 11 '18 at 11:57

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.