Click here to Skip to main content
15,888,320 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Truffle v5.1.34 (core: 5.1.34)
Solidity v0.5.16 (solc-js)
Node v12.18.2
Web3.js v1.2.1node index.js
Using npm install solc --save command I insatalled solc: + solc@0.6.11

  errors:
      component: 'general',
      errorCode: '5333',
      formattedMessage: 'HelloWorld.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.6.11+commit.5ef660b1.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version\n' +
        'pragma solidity ^0.5.10;\n' +


What I have tried:

I have tried below code of Node.js
const fs = require('fs'); // Built-in dependency for file streaming.
const solc = require('solc'); // Our Solidity compiler

const content = fs.readFileSync('HelloWorld.sol', 'utf-8'); // Read the file...

// Format the input for solc compiler:
const input = {
  language: 'Solidity',
  sources: {
    'HelloWorld.sol' : {
      content, // The imported content
    }
  },
  settings: {
    outputSelection: {
      '*': {
        '*': ['*']
      }
    }
  }
}; 

const output = JSON.parse(solc.compile(JSON.stringify(input)));

console.log(output); // Log the result

And

Solidity code

pragma solidity ^0.5.10;

contract HelloWorld {
  string myName = "Tristan";
  
  // Add this function:
  function getMyName() public view returns(string memory) {
    return myName;
  }
  
  function changeMyName(string memory _newName) public {
    myName = _newName;
  }
}
Posted
Updated 3-Feb-22 6:13am
Comments
Richard MacCutchan 15-Jul-20 11:28am    
Go to the website for the compiler and find the correct version. Alternatively, check the documentation to see what is incorrect in your code.

1 solution

If you don't understand an error message, google it.
This was the top of my list: solidity - Source File requires different compiler version - Ethereum Stack Exchange[^]
 
Share this answer
 
Comments
Richard MacCutchan 3-Feb-22 12:17pm    
A little late methinks. :)
OriginalGriff 3-Feb-22 12:45pm    
Oh c*ck.
I must remember to check the damn dates ... it just popped up in the QA list, so ... :sigh:
Richard MacCutchan 3-Feb-22 12:54pm    
There was a non-answer posted about an hour ago, which has now disappeared.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900