0

I was trying to fund a campaign created with a funding goal 10000000000000000000 and funding cap 10000000000000000000 by calling the payable method contributeMsgValue with parameter["100000000000000000"] and value 100000000000000000 but I am receiving this error in Remix.

transact to StandardCampaign.contributeMsgValue errored: VM error: revert. revert The transaction has been reverted to the initial state.

contract Campaign is Owned, Campaign {
  enum Stages {
    CrowdfundOperational,
    CrowdfundFailure,
    CrowdfundSuccess
  }
  modifier atStage(Stages _expectedStage) {
    if (stage() != uint256(_expectedStage)) {
      throw;
    } else {
      _;
    }
  }
  modifier validContribution() {
    if (msg.value == 0
      || amountRaised + msg.value > fundingCap
      || amountRaised + msg.value = expiry
      && earlySuccess == false
      && amountRaised = expiry && amountRaised >= fundingGoal)
      || earlySuccess == true
      || amountRaised >= fundingCap) {
      return uint256(Stages.CrowdfundSuccess);
    }
  }
  function contributeMsgValue(uint256[] _amounts)
    public 
    payable 
    atStage(Stages.CrowdfundOperational) 
    validContribution() 
    returns (uint256 contributionID) {
    contributionID = contributions.length++;
    contributions[contributionID] = Contribution({
        sender: msg.sender,
        value: msg.value,
        created: block.number
    });
    contributionsBySender[msg.sender].push(contributionID);
    amountRaised += msg.value;
    ContributionMade(msg.sender);
    if (enhancer.notate(msg.sender, msg.value, block.number, _amounts)) {
      earlySuccess = true;
    }
  }
  function StandardCampaign(string _name,
    uint256 _expiry,
    uint256 _fundingGoal,
    uint256 _fundingCap,
    address _beneficiary,
    address _owner,
    address _enhancer) public {
    name = _name;
    expiry = _expiry;
    fundingGoal = _fundingGoal;
    fundingCap = _fundingCap;
    beneficiary = _beneficiary;
    owner = _owner;
    created = block.number;
    enhancer = Enhancer(_enhancer);
  }
  struct Contribution {
    address sender;
    uint256 value;
    uint256 created;
  }
  uint256[] defaultAmounts;
  Enhancer public enhancer;
  bool public earlySuccess;
  address public owner;
  uint256 public fundingGoal;
  uint256 public fundingCap;
  uint256 public amountRaised;
  uint256 public expiry;
  uint256 public created;
  address public beneficiary;
  Contribution[] public contributions;
  mapping(address => uint256[]) public contributionsBySender;
  mapping(uint256 => address) public refundClaimAddress;
  mapping(uint256 => bool) public refundsClaimed;
  string public name;
}

Am I missing any code here or calling the function in a incorrect way?

0

You can actually debug your transaction in remix and you will figured out why is not working. Somehow the two modifier don't pass and the transaction is reverted.

If you comment this two modifier from the function contributeMsgValue it will work properly.

    atStage(Stages.CrowdfundOperational) 
    validContribution() 

you just need to check the modifier and fix it.

  • Thanks for your answer. I commented the modifiers and tried executing it. I am able to see that the contribution is successfully done but the contributionID remains 0 and also I am getting this 'VM error: revert' in Remix which is reverting the state because of which contributions become 0. – Sumukha Mar 23 '18 at 4:01
  • Solved it! There was an issue with enhancer.notate method. – Sumukha Mar 23 '18 at 4:33

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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