0

My Code below ( Following an Online Course, absolute beginner here ^_^)

pragma solidity >=0.4.17 <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));
        //recipient.transfer(request.value);
        // above is one of the ways i got to know for implementation but sticking to the course 
        payable(request.recipient).transfer(request.value);
        request.complete = true;

    }

}

NO ERROR but NO transfer of ether (last two lines), tried in REMIX everything works fine, except no ether is transferred

A Beginner here, following an online course, making a DApp , also after compiling the contract through Compile.js, no build=> .json file is build, which i guess is because of faulty solidity contract above, works fine for the course instructor, i guess its because the code is outdated?

is there a solution for this or i have to find a alternative for this?

goodvibration
  • 26,003
  • 5
  • 46
  • 86
utsav pandey
  • 133
  • 1
  • 4
  • Works for me: https://rinkeby.etherscan.io/tx/0x4c1e375ea5918076ffa4da0f2f9e4f4675ad04b2fea8af715646e38c1628ea0b. Maybe you are setting a value that is too high in createRequest? The contract can only send out ETH it previously received via contribute. On another note, please be aware that usage of .transfer is discouraged: https://diligence.consensys.net/blog/2019/09/stop-using-soliditys-transfer-now/. – Markus - soliditydeveloper.com Apr 12 '20 at 04:54
  • so should i use below one instead ? :- address payable recipient = address(uint160(request.recipient)); recipient.transfer(request.value); – utsav pandey Apr 12 '20 at 05:37
  • That is the way that is described in the documentation at least: https://solidity.readthedocs.io/en/v0.6.0/050-breaking-changes.html. 'Converting address to address payable is possible via conversion through uint160', but like I said the other way worked for me as well. – Markus - soliditydeveloper.com Apr 12 '20 at 05:54
  • can you please paste the line of code for call.value() since it is displaying error regarding it is depricated and thank you for the help! – utsav pandey Apr 12 '20 at 12:23
  • I have posted on your follow-up question: https://ethereum.stackexchange.com/questions/82412/using-value-is-deprecated-use-value-instead. – Markus - soliditydeveloper.com Apr 13 '20 at 04:13

0 Answers0