I am getting error with both latest solc (0.5.2 version) and 0.4.25 too while I am writing Simple contract
I have tried following steps
- uninstalled Solc: npm uninstall solc
- Installed targeted version: npm install --save solc@0.4.25
node compile.js (code given below)
{ contracts: {}, errors: [ ':1:1: ParserError: Expected pragma, import directive or contract /interface/library definition.\nD:\\RND\\BlockChain\\contracts\\Inbox.sol\n^\n' ],sourceList: [ '' ],sources: {} }
Compile.js
const path = require('path');
const fs = require('fs');
const solc = require('solc');
const inPath = path.resolve(__dirname,'contracts','Inbox.sol');
const src = fs.readFileSync(inPath,'UTF-8');
const res = solc.compile(inPath, 1);
console.log(res);
Inbox.sol
pragma solidity ^0.4.25;
contract Inbox {
string message;
function Inbox(string passedName) public {
message = passedName;
}
function setMessage(string newMsg) public {
message = newMsg;
}
function getMessage() public view returns(string){
return message;
}
}
Code worked well on Remix, for version 0.5.2 I have added memory tag to make it compile on Remix.
ex: function setMessage(string **memory** newMsg)