1

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

1 Answer 1

2

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

1
  • 1
    In case you venture beyond Remix, you would want to add the keyword pure which is a way of indicating that the function doesn't interact with the contract state and so there is no need for a client to sign a transaction. Remix conveniently hides that detail. So, ...) pure returns(bool) { May 15, 2018 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.