0

I am using Atom together with etheratom and I don't get why this simple code won't run:

pragma solidity ^0.4.19

contract MyFirstContract {
    string private name;
    uint private age;

    function setName(string newName) {
        name = newName;
    }

    function getName() returns (string) {
        return name;
    }
}

It shows me the following error:

:5:5: ParserError: Expected pragma, import directive or contract/interface/library definition. uint private age; ^

Anybody an idea whats wrong?

2

You're missing a ; after declaring what version of solidity you're using. Use this pragma solidity ^0.4.19; in the first line instead. Consider using remix IDE in the future to help solve these small errors.

You can also use view on the getName function, this can be used as the function only reads data and will not cost Ether to run. Here is the updated function

function getName() view returns (string) {
    return name;
}

updated code

pragma solidity ^0.4.19;

contract MyFirstContract {
    string private name;
    uint private age;

function setName(string newName) {
    name = newName;
    }

function getName() view returns (string) {
    return name;
    }
}
  • Remix gives the exact same error message. (This is unsurprising because they both use the same Solidity compiler.) – user19510 Feb 24 '18 at 22:55
  • Are you sure? When I compile it on the online editor I get no errors – JAG Feb 24 '18 at 22:57
  • I pasted the code from the question into Remix and got the same error. – user19510 Feb 24 '18 at 23:07
  • To be clear, I was responding to "Consider using remix IDE in the future to help solve these small errors." I wanted to point out that Remix and etheratom behave the same in this case. – user19510 Feb 24 '18 at 23:08
  • I've updated my answer with my edited code, try putting that in and it should hopefully work – JAG Feb 24 '18 at 23:12

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.