Force Hero
Force Hero

Reputation: 3222

How do I uniformly select the solidity version I want to use in my Ethereum project?

I'm creating a new Ethereum project, using VScode (with Solidity extension) and hardhat. I want to use Solidity 0.8.1. I've done the following:

  1. Created a new directory for the project
  2. Run npm init -y to initialise the directory as an npm project
  3. Run npm i -D hardhat to install hardhat in the local directory (-D to save as a dev dependency in the package.json)
  4. Run npx hardhat and select the option to create the hardhat.config.js file
  5. Edit the hardhat.config.js file to target 0.8.1:
/**
 * @type import('hardhat/config').HardhatUserConfig
 */
module.exports = {
  solidity: "0.8.1",
};
  1. Created a contracts folder and created the following file Token.sol:
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.1;

contract doStuff {

}

But the Solidity extension in VSCode complains with Source file requires different compiler version (current compiler is 0.7.3+commit.9bfce1f6.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version.

I think it's picking up the solc version installed in node_modules (0.7.3) - this must have been installed as part of hardhat.

How do I line up "everything" in the project so it uses 0.8.1?

Presumably you're not forced to use whatever version hardhat downloads of solc upon installation?

UPDATE: I ran npx hardhat compile which appears to have downloaded the 0.8.1 compiler:

✔ Help us improve Hardhat with anonymous crash reports & basic usage data? (Y/n) · true
Downloading compiler 0.8.1
Compiling 1 file with 0.8.1
Compilation finished successfully

But the VSCode Solidity extension is still looking at the solc version in node_modules. How do I point the vscode extension at the latest version?

Upvotes: 1

Views: 2534

Answers (1)

Force Hero
Force Hero

Reputation: 3222

I had Enable Local Node Compiler set to true in my vscode extension config.

Disabling this (through the File -> Preferences GUI) and adding the following to .vscode/settings.json sorted the problem:

{
    "solidity.compileUsingRemoteVersion": "v0.8.1+commit.df193b15"
}

Upvotes: 2

Related Questions