Fixing Parse Error: Expected Pragma in Solidity Remix

errorremixsolidity

I am a beginner trying to run the following code on remix.ethereum.org

 pragma solidity ^0.4.19;
function processData(uint num) returns (bool) {

    uint _number = num;
    if(num == _number)
    {
        return true;
    }
    else
    {
        return false;
    }
}

But i am getting the Error

browser/code1.sol:2:1: ParserError: Expected pragma, import directive or contract/interface/library definition.
function processData(uint num) returns (bool) {
^

How can i get past this Error?

Secondly, even if I ignore the above Error, the code is expected to have one of the following Errors that I want to catch but apparently the code seems to not have any of the following Errors. Do you agree?

  1. Unmatched Recursion
  2. Missing parenthesis
  3. Incompatible types
  4. Wrong typecasting
  5. Undeclared variable or function
  6. Missing semicolon
  7. Wrong Use of if conditional

Best Answer

A few things were missing, but mainly, You need to use the keyword contract here is the example using your code:

pragma solidity ^0.4.23;

contract YourContractName {

    constructor(){
    }

    function processData(uint num) public pure returns (bool) {

        uint _number = num;
        if(num == _number) {
            return true;
        } else {
            return false;
        }
    }
}

Notice that this will always return true.

Hope it helps

Related Topic