I am running truffle test with the following simple test contract, however it seems that it doesn't understand the view modifier.


pragma solidity ^0.4.18;

contract MetaCoin {
    function getBlockNumber()
    returns (uint)
        return block.number;

The output looks like:

$ truffle test
Compiling ./contracts/MetaCoin.sol...
Compiling ./test/TestMetacoin.sol...
Compiling truffle/Assert.sol...
Compiling truffle/DeployedAddresses.sol...

/contracts/MetaCoin.sol:7:5: ParserError: Expected token LBrace got 'View'

The view works in Remix, what is missing in my truffle environment that is throwing this error?

The Remix compilation version is (0.4.18+commit.9cf6e910.Emscripten.clang)

1 Answer 1


Do $ truffle version

Unless I miss my guess, it's not compiling with 0.4.18 so it's confused.

Truffle comes with its own JS compiler that lags behind solc, so it usually works best to lock that version in Remix so you have consistency through the whole process. For example, Truffle 3.4.11 gave us solidity 0.4.15. It that's the case, then it makes sense to select 0.4.15 in Remix.

Hope it helps.

  • Thank you Rob. truffle version returns Truffle v3.4.11 (core: 3.4.11) Solidity v0.4.15 (solc-js) changing the setting to 0.4.15 in Remix gives the same error as truffle. So i think your assessment that truffle lags solc is correct.
    – Victory
    Commented Oct 23, 2017 at 23:58
  • 1
    In case it isn't clear or helps someone else, view is new. In 0.4.15 you'll be fine with constant. Thanks for the "accept". Commented Oct 24, 2017 at 0:06

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.