4

This works fine in Remix but when trying to work in VSCode (for compiling purposes; DApp course, trying to build .json through compile.js ) it throws the error

  1. Using ".value(...)" is deprecated. Use "{value: ...}" instead.

  2. security/no-call-value: Consider using 'transfer' in place of 'call.value()'.
    from this line :-
    (bool success,) = recipient.call.value(request.value)(""); //Third last line below

pragma solidity >=0.5.16 <0.7.0;

contract CampaignFactory{
   Campaign[] public deployedCampaigns;

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

    }

    function getDeployedCampaigns() public view returns ( Campaign[] 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 contributersCount;                           

    modifier restricted(){
        require(msg.sender == manager);
        _;
    }

  // constructor************************************************  
    constructor(uint minimum,address creator) public {
        manager = creator;
        minimumContribution = minimum;

    }


    function contribute() public payable{
        require(msg.value > minimumContribution);

        approvers[msg.sender] = true;
        contributersCount++;

    }



    function createRequest(string memory description, uint value, address recipient ) public restricted() {
        Request memory newRequest = Request({
            description: description,
            value: value,
            recipient: recipient,
            complete: false,
            approvalCount: 0

        });

        requests.push(newRequest);

    }

    function approveRequest( uint index) public{
        Request storage request_index = requests[index];

        require(approvers[msg.sender]);

        require(!request_index.approvals[msg.sender]);

        request_index.approvals[msg.sender] = true;

        request_index.approvalCount++;

    }

    function finalizeRequest(uint  index) public payable restricted {
        Request storage  request = requests[index];
        require(request.approvalCount > (contributersCount / 2));
        require(!request.complete);

        address payable recipient = address(uint160(request.recipient));
        (bool success,) = recipient.call.value(request.value)("");
        (success, "Transfer failed.");
        request.complete = true;

    }  

}
1
  • What version of solidity are you using? Perhaps you have one version configured in Remix and a different one in VSCode. I'd recommend to specify what version you want to use: pragma solidity 0.5.16 (or use 0.6.5 if you want to target new version). – Ismael Apr 13 '20 at 6:54
2

That is an outdated error message. I assume you are using ethlint as linter which means you can silence this warning by creating a .soliumrc.json in your repository with the following content:

{
  "extends": "solium:recommended",
  "plugins": ["security"],
  "rules": {
    "no-call-value": "off"
  }
}

See the Github issue and further explanations on how to use call.value.

1
  • all went good ( gets compiled and i can build the .json files)and while i was running mocha test before deploying my contract ( DApp tutorial), i can clearly see that ether is not being transferred from the last function, the main issue related from the start to call.value().................. – utsav pandey Apr 13 '20 at 15:22
6

With respect to the ".value(...)" is deprecated. Use "{value: ...}" warning:

You can use the following pattern to remove the warning:

(bool success, ) = recipient.call{value:amt}("");
require(success, "Transfer failed.");

solidity.readthedocs.io , solidity dotsyntax 0.7.0 =>

The following syntax is deprecated: 
f.gas(...)(), f.value(...)() and (new C).value(...)().  

Replace these calls by
f{gas: ..., value: ...}() and (new C){value: ...}(). 

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.