1

I'm new to blockchain and I'm following a tutorial. However, I'm getting problem compiling my first contract on Truffle.

Here's my code :

pragma solidity ^ 0.5.2;

contract ApprovalContract
{
    address public sender;
    address public receiver;
    address public constant approver = 0x6af7A9CFe4D4B938Ff4038Fd0625d18C5D671834;


function deposit(address payable _receiver) external payable{
    require(msg.value>0);
    sender = msg.sender;
    receiver = _receiver;
    }

    function viewApprover() external pure   returns(address)
        {
            return(approver);
        }

    function approve() external {
        require(msg.sender ==  approver);
        receiver.transfer(address(this).balance);
    }
}

Now while I try to compile my code through the terminal, this is the error I get.

SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version pragma solidity ^ 0.5.2; ^----------------------^ ,/C/Users/neonalliance/Desktop/Solidity/contracts/ApprovalContract.sol:22:3: TypeError: Member "transfer" not found or not visible after argument-dependent lookup in address. receiver.transfer(address(this).balance); ^---------------^

Error: Truffle is currently using solc 0.5.0, but one or more of your contracts specify "pragma solidity ^ 0.5.2". Please update your truffle config or pragma statement(s). (See https://truffleframework.com/docs/truffle/reference/configuration#compiler-configuration for information on configuring Truffle to use a specific solc compiler version.)

I think the problem is due to some update or modifications in Solidity as the tutorial I am following is of 2017, but I cannot exactly figure out what I need to do.

So what could possible be the solution ?

Note: Since this is my first Blockchain Learning phase, I request you to please answer in a way I could possibly grasp the information.

0

The solution is in the error message you shared.

Truffle is currently using solc 0.5.0, but one or more of your contracts specify "pragma solidity ^ 0.5.2".

Since your version of truffle uses solc 0.5.0 which can only compile files using a Solidity version up to 0.5.0.

If you want it to work, change pragma solidity ^ 0.5.2; to pragma solidity ^0.5.0;

  • I changed the version as you specified but I still got this error : TypeError: Member "transfer" not found or not visible after argument-dependent lookup in address. receiver.transfer(address(this).balance); What could be the problem? Is the "transfer" keyword not working ? – Sanjay Sanjel Apr 28 at 13:54
  • Eli Drion. Are you there? It's still not working. – Sanjay Sanjel May 5 at 14:48

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.