6

I just tried to set up a truffle project and tried to compile a contract I have already written.

When I do so I get the following error message:

/usr/lib/node_modules/truffle/node_modules/solidity-parser/index.js:39
      throw e;
      ^
SyntaxError: Expected "contract", "import", "library", comment, end of input, end of line or whitespace but "p" found. Line: 1, Column: 1
    at peg$buildException (/usr/lib/node_modules/truffle/node_modules/solidity-parser/build/imports_parser.js:423:14)
    at Object.peg$parse [as parse] (/usr/lib/node_modules/truffle/node_modules/solidity-parser/build/imports_parser.js:3355:13)
    at Object.module.exports.parse (/usr/lib/node_modules/truffle/node_modules/solidity-parser/index.js:34:23)
    at /usr/lib/node_modules/truffle/lib/profiler.js:134:36
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)

The first line the compiler is complaining about is:

pragma solidity ^0.4.0;

As far as I know there is no way I could let that line out. Is there a solution that lets me use Truffle with the most recent version of solidity?

Thank you in advance.

  • 1
    What is your contract? Would help if you could post it here – zyam Sep 11 '16 at 21:44
  • 1
    I think it will work without that pragma line, please try once without that line. – Aniket Sep 12 '16 at 6:09
  • 1
    It does not work without it. If I use Solidity 0.4 the compiler complains about the _; – Bot X Sep 12 '16 at 9:40
  • 1
    What does solc --version give? If I use v0.3.6, I get the same error on the pragma line. – Xavier Leprêtre B9lab Sep 12 '16 at 10:52
  • 1
    My solc was still 0.3 but now i updated it to Version: 0.4.1-develop.2016.09.09+commit.79867f4.Linux.g++ and still get the same error – Bot X Sep 12 '16 at 11:06
2

I just added support solidity 0.4.x and released a new version of Truffle. You can read the announcement here: https://www.reddit.com/r/ethereum/comments/574rvr/truffle_v210_now_with_solc_04x_support/

Cheers!

4

I had the same problem, so I asked on Truffle's Gitter channel, and this is the answer I received:

Truffle will not support solc 0.4.x until Truffle 3.0 is released, as significant changes to Truffle are required.

Hope this helps!

2

I can't know without the code for context, but I would bet that this is in a function modifier and the line above it is _.

In Solidity >= 0.4, the _ must have a semicolon after it.

i.e. _;

You should also add the suggested pragma line at the top of your files, just so it stops complaining.

See the Release notes for details

  • 1
    Exactly that's the problem. My code is written in Solidity 0.4 and I have the _; in the modifiers. The compiler complains that my code begins with "pragma" and not with "contract" or "library" – Bot X Sep 12 '16 at 9:41
  • 1
    Oh, I see. I think Truffle just compiles using your local solc, so as long as that's up to date, I don't know why it would complain – Tjaden Hess Sep 12 '16 at 14:33
  • 1
    As I have already mentioned above: My solc was still 0.3 but now i updated it to Version: 0.4.1-develop.2016.09.09+commit.79867f4.Linux.g++ and still get the same error – Bot X Sep 12 '16 at 16:44
1

EDIT: The shortest working solution is using Browser Solidity ( https://ethereum.github.io/browser-solidity/ ) and just tell it to use Solidity 0.3.6, then things will work out again in truffle.

I'm struggling under the same problem, and eventually, there is a workaround - I havn't tried it myself yet:

  1. compile and deploy your contract "the hard way" via solidity and geth.
  2. run truffle migrate and truffle build on your truffle project without the pragma solidity ^0.4.0; in your contract
  3. take the adress of your "manually deployed" contract, open the app.js built by truffle under /build/app.js, find Contract.all_networks and change the address to the of your manually deployed contract.

This way you possibly could trick your truffle build to use the previously well compiled contract. Absolutely no warranty, maybe someone with deeper understanding of all this can tell, if this is completely nonesense or a viable solution.

PS: compiling and deploying the hard way: 1. $ sudo apt-get install -y solc 2. Remove all line breaks from your contract code (online tools might help) 3. In geth: > var myContractSource = *paste contract source without linebreaks here* 4. > var myContractCompiled = eth.compile.solidity(myContractSource) 5. > var myContract = eth.contract(myContractCompiled.theContractNameInTheSolidityCode.info.abiDefinition); 6. again without linebreaks and with mining turned on:

var myContractTransaction = myContract.new({
    from: eth.coinbase, 
    data: myContractCompiled.theContractNameInTheSolidityCode.code, 
    value: 1000000000000000000,
    gas: 1000000
  },
  function(err, contract) {
      if (err) {
        console.error(err); 
      } else {
        console.log(contract); 
        console.log(contract.address);
      }
});

the last returned address is the address of your contract.

PPS: Again, I'm not sure, but maybe in the bespoke app.js you might also have to replace the unlinked_binary (under contract.all_networks) with what you find as code: when doing just > myContractCompiled in geth after defining this var. those values look somehow related to the identification of contracts to me.

I hope I could be of help. Let's wait for the update of truffle..

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.