0

I am trying to compile below mentioned code (taken from Oraclize documents) using TRUFFLE but am getting compilation error saying :

'Cannot parse one.sol: Unexpected token p in JSON at position 0'.

Can someone suggest how to handle this error.

pragma solidity ^0.4.11;
import "./oraclizeAPI.sol"; //Importing Oraclize

contract ExampleContract is usingOraclize {

string public EURGBP;
event updatedPrice(string price);
event newOraclizeQuery(string description);

function ExampleContract() payable {
    updatePrice();
}

function __callback(bytes32 myid, string result) {
    if (msg.sender != oraclize_cbAddress()) throw;
    EURGBP = result;
    updatedPrice(result);
}

function updatePrice() payable {
    if (oraclize_getPrice("URL") > this.balance) {
        newOraclizeQuery("Oraclize query was NOT sent, please add some ETH to cover for the query fee");
    } else {
        newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
        oraclize_query("URL", "json(http://api.fixer.io/latest?symbols=USD,GBP).rates.GBP");
    }
}

}

0

This is a solidity file not a json file, but Truffle is apparently trying to parse it as a json file, so the problem is probably not the content, but the place where you've put the file or the way you're trying to load it.

Make sure your code layout and the way you're calling truffle follows the steps in the tutorial. If that doesn't fix it, try posting a link to your code and the command you're running that's producing the error.

  • Thanks Edmund for your reply. I figured out the issue, somehow a cached version of this solidity code was present in my Visual studio Code which was getting picked up by 'Truffle compile' command and caused the issue. I deleted the file after which the code compiled successfully. – tanmay Jan 17 '18 at 18:42

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.