17

enter image description here Hi may I know how to change my Solidity linter compiler version in Visual Studio Code(vscode)? OR Visual studio code how to specify solidity compiler version?

The only Solidity related extensions I have installed are solidity 0.0.38 by Juan Blanco, and Solidity Extended 3.0.2 by beaugunderson.

I have applied the User Settings in VS Code as the following but still get error:

{"files.autoSave": "afterDelay",
  "files.autoSaveDelay": 1000,
  "editor.minimap.enabled": false,
  "editor.tabSize": 2,
  "editor.detectIndentation": false,
  "editor.wordWrap": "on",
  "files.associations": {
    "*.sol": "solidity"
  },
  "workbench.iconTheme": "material-icon-theme",
  "material-icon-theme.showUpdateMessage": false,

  "solidity.compileUsingRemoteVersion" : "latest",
  "solidity.linter":"solium",
  "solidity.packageDefaultDependenciesContractsDirectory": "contracts",
  "solidity.packageDefaultDependenciesDirectory": "node_modules",
  "solidity.soliumRules": {
    "imports-on-top": 0,
    "variable-declarations": 0,
    "no-inline-assembly": 5,
    "indentation": ["error",2],
    "quotes": ["error","double"]
  },
  "solidity.validationDelay": 1000,

  if in Windows system:
  "terminal.integrated.shell.windows":"C:\\WINDOWS\\System32\\cmd.exe",
  "window.zoomLevel":1

Now I've also install Solidity globally in my Linux: $ sudo npm install -g solc Then I've got this from the terminal: /home/userXYZ/.npm-global/bin/solcjs -> /home/userXYZ/.npm-global/lib/node_modules/solc/solcjs + [email protected]

Then changed User Setting: "solidity.compileUsingRemoteVersion" : "latest"

Then re-started VS Code, still I am getting this error... Please help. Thank you

1
  • 1
    This is not off-topic!!! It is about upgrading a plugin to use the most recent version of the solidity compiler. It surely will help others solidity developers trying to do the same thing!
    – Ismael
    Commented Apr 20, 2018 at 18:54

8 Answers 8

4

If you still have a problem with the version in VS Code, this worked for me:

Install specific solc version locally or globally: npm i -g solc or npm i solc.

Add this setting in local VSCode settings: .vscode/settings.json

{
    "solidity.compileUsingRemoteVersion": "v0.7.4+commit.3f05b770",
    "solidity.enableLocalNodeCompiler": false
}

In my case I am using solidity v0.7.4. Note also the other config: "solidity.enableLocalNodeCompiler": false

2
  • How do you find what commit it should be? I.e. how did you know you needed +commit.3f05b770 Commented Dec 9, 2022 at 8:09
  • @thatguyintech I don't remember, but I think there is a list here will all the details: etherscan.io/solcversions
    – drab
    Commented Jul 18, 2023 at 9:10
9

Assuming your using VS code and have the official solidity extension maintained by Juan Blanco (found here). The extension is official in the sense that it is the only extension recommended by ethereum.org.

The extension provides a very easy way of toggling compilers:

  1. In any *.sol file, right click and press "change workspace compiler version (Remote)".

  2. Choose your compiler.

Thats it.

enter image description here

1
  • This answer works perfectly. Also remember each workspace can have different compiler versions.
    – Rax
    Commented Jan 10, 2022 at 9:57
6

[Solved] Thank you Juan Blanco for his advice. So the main issue is that the forked extension(Solidity Extended by beaugunderson) was highjacking this one(solidity by Juan Blanco) hence I had the old version of the compiler 0.4.17 but not the latest version 0.4.23.

Set it by opening your VS Code setting at /home/userXYZ/.config/Code/User/settings.json in Linux, then change the compiler version like below

"solidity.compileUsingLocalVersion": "null",

"solidity.compileUsingRemoteVersion" : "v0.8.0+commit.c7dfd78e",

2
  • How did you change the version? I removed other extensions and it does not work
    – Ender
    Commented Dec 4, 2019 at 10:02
  • 1
    by installing solc in your system
    – Russo
    Commented Dec 22, 2019 at 3:34
4

Go to node_modules -> solc -> package.json -> version of your compiler can be found at the bottom.

Never edit the package.json file

To fix the problem

-Copy the version number at the bottom ex:-"version": "0.5.1"

-go to your contract and paste on pragma. ex:- pragma solidity ^0.5.1;

This should fix your issue.

1
  • I don't have Go to node_modules on the VSC
    – Ender
    Commented Dec 4, 2019 at 10:03
3

I tried sooooooooo many things to fix this in Nov 2021 and this is finally what did it for me....btw, many thanks to Russo for his insight about Blanco's extension vs Beaugunderson's! While his quick fix didn't immediately fix, I was able to find the needle in the haystack, finally:

  • Open VSCode
  • On left side, open Extensions (Now here, check what Solidity extensions you installed! I happened to have had BOTH Blanco's and Beaugunderson's extension installed - You only need Blanco's! So make sure HIS is installed and if you have Beaugunderson's then uninstall it! Should only have Blanco's..) Done. This worked at least for me. Hope it works for you.
2
  • I tried sooooo many things too and this resolved my issue completely!! Commented Jan 11, 2022 at 1:33
  • Omg dude ! I was so piss off by Visual studio and this fix all my problems ! Yeees !! I don't know how to thank you enough ^-^
    – Arthur
    Commented Jan 27, 2022 at 13:38
1

This is what helped me. In the file named .solhint.json, I replaced

{
  "extends": "solhint:recommended",
  "rules": {
    "compiler-version": ["error", "^0.8.0"],
    "func-visibility": ["warn", { "ignoreConstructors": true }]
  }
}

with this

{
  "extends": "solhint:recommended",
  "rules": {
    "compiler-version": "^0.6.0",
    "func-visibility": ["warn", { "ignoreConstructors": true }]
  }
}
1

In my case I had to npm install solc@specific-version-number

This resolved the error for me

1

I've noticed this question was answered, but just in case others are using Hardhat, you can edit the hardhat.config.js with an entry for the Solidity compilers you want. If a version isn't installed, hardhat will install it for you. Here's an example:

solidity: {
    compilers: [
     
      {
        version: "0.6.0",
      }, 
      {
        version: "0.8.10",
      },
    ],
  },

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.