3

I'm working on my Udemy course project .. the problem with this course is that been used old version solidity 0.4.17.. I'm trying to update this project to a current version... after updating the code and tried to compile on Remix compiler... it compiles with no any errors or warnings on the specific lines, but when I try to deploy a contract on remix:

it shows:

creation of Campaign errored: Error encoding arguments: Error: invalid BigNumber string (argument="value", value="", code=INVALID_ARGUMENT, version=bignumber/5.1.1)

so I don't really understand what is the problem here?

this is my solidity contract code:

    // SPDX-License-Identifier: GPL-3.0

pragma solidity >0.4.17 <0.8.0;

 contract CampaignFactory {

    address[] public deployedCampaigns;

    function createCampaign(uint minimum) public {
        address newCampaign = address ( new Campaign(minimum, msg.sender));
        deployedCampaigns.push(newCampaign);
    }

    function getDeployedCampaigns() public view returns (address[] memory) {
        return deployedCampaigns;
    }
}

contract Campaign {
    
    struct Request {
        string description;
        uint value;
        address recipient;
        bool complete;
        uint approvalCount;
        mapping(address => bool) approvals;
    }
    
    Request[] public requests;
    address public manager;
    
    uint public minimumContribution;
    
    mapping(address => bool) public approvers;
    
    uint public approversCount;
  
    modifier restricted() {
        require(msg.sender == manager);
        _;
    }
    
    constructor(uint minimum, address creator){
        
        manager = creator;
        minimumContribution = minimum;
    }
    
    function contribute() public payable {
        require(msg.value > minimumContribution);
        
        approvers[msg.sender] = true;
        approversCount++;
    }
    
    uint numRequest;
    
    
    function creatRequest(string memory description, uint value, address recipient) public restricted {
                
        Request storage newRequest = requests[numRequest++];
           newRequest.description = description;
           newRequest.value = value;
           newRequest.recipient = recipient;
           newRequest.complete = false;
           newRequest.approvalCount = 0;
        
    }
    
    function approveRequest(uint index) public {
        Request storage request = requests[index];
        require(approvers[msg.sender]);
        require(!request.approvals[msg.sender]);
        
        request.approvals[msg.sender] = true;
        request.approvalCount++;
    }
    
    
    function finalizeRequest(uint index) public restricted {
        Request storage request = requests[index];
        
        require(request.approvalCount > (approversCount / 2));
        require(!request.complete);
        
        payable(request.recipient).transfer(request.value);
        request.complete = true;
    }
}

thank you in advance for taking your time to look at this problem ...

EDIT:

Ok I manager to pass this error, but now when I try to create my request I get an error:

[vm] from: 0x5B3...eddC4to: Campaign.creatRequest(string,uint256,address) 0x7b9...b6AcEvalue: 0 weidata: 0x83e...00000logs: 0hash: 0x8d9...a5ccb transact to Campaign.creatRequest errored: VM error: invalid opcode. invalid opcode The execution might have thrown. Debug the transaction to get more information.

so the steps I do:

  1. set my minimum contribution to "0" and add a creator address "0x0ABC"

  2. I contribute 1 Ether with same address "0x0ABC"

  3. and I pick a random different address from the remix copy and paste into my "createRequest" I add string "string" amount "uint" address "0x0CCC"

and when I click createRequest I get this error I stated above;

enter image description here

enter image description here

Maifee Ul Asad
  • 3,992
  • 6
  • 38
  • 86
Juodas Baltas
  • 305
  • 1
  • 4
  • 6
  • It's probably caused by the way how you input the constructor values into Remix. Please edit your question and show how you input the values in the "Deploy & Run Transactions" tab. Do you put the `creator` address in quotes, do you separate them by a comma (if you're using the one-line input), ...? – Petr Hejda May 01 '21 at 18:44
  • Hey Petr Hejda this is my edit version please have a look.. – Juodas Baltas May 01 '21 at 19:28

1 Answers1

1

Solidity currently (v0.8) doesn't allow writing a "struct containing a mapping" into a storage array. But you can write it into a mapping.

mapping (uint => Request) public requests;  // changed to mapping

instead of

Request[] public requests;  // original code

You'll lose the ability to retrieve the array length. But you're already keeping it in the numRequest variable, so it's all good.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100