0

error: transact to CampaignFactory.createCampaign errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The constructor should be payable if you send value. Debug the transaction to get more information.

code:

 function createCampaign(uint deposit, address ll) public payable{
   // dpst = deposit;
    require(msg.value > (40*deposit)/100 wei);
    address newCampaign = address((new Campaign).value(msg.value)(deposit, ll, token_address, 1));
    token_instance.setAllowance(deposit, token_holder, newCampaign);

    deployedCampaigns.push(newCampaign);


} 

Campaign constructor declaration:

    constructor (uint depositInWei, address ll, address addressOfTokenUsed, uint weiCostOfEachToken) public payable{
  • Comment out require statements until you find out which one causes the problem. The text about "payable constructor" is just a guess and usually you can ignore that part. – Lauri Peltonen Jan 28 at 12:53
  • @LauriPeltonen I already tried removing require statement. Although not able to send ether/wei to the createCampaign function. – Rahul Savsani Jan 28 at 12:56
  • Well then just remove code lines and see which one causes the error. – Lauri Peltonen Jan 28 at 13:01
0

As I do not have token address, ABI or setAllowance functions, I have removed them and it worked perfectly. The problem is raised due to setAllowance function. I shared code below, you can test it on Remix IDE.

pragma solidity ^0.4.24;

contract CampaignFactory{

address [] deployedCampaigns;
function createCampaign(uint deposit, address ll) public payable{
    require(msg.value > (40*deposit)/100 wei);
    address newCampaign = address((new Campaign).value(msg.value)(deposit, ll, 1));

    deployedCampaigns.push(newCampaign);
    } 

}
contract Campaign {
    constructor (uint depositInWei, address ll, uint weiCostOfEachToken) public payable{
    }

}

Hope it helps,

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.