I'm trying to compile a smart contract, truffle cannot find the solc when using this compiler configuration. It cannot autodetect the solc version from the source files.
module.exports = {
compilers: {
solc: {
version: 'pragma',
optimizer: {
enabled: true,
runs: 200,
},
},
},
};
Result of truffle compile
execution
Error: Could not find a compiler version matching pragma. compilers.solc.version option must be a string specifying:
- a path to a locally installed solcjs
- a solc version or range (ex: '0.4.22' or '^0.5.0')
- a docker image name (ex: 'stable')
- 'native' to use natively installed solc
truffle solc documentation
solc¶
Solidity compiler settings. Supports optimizer settings for solc, as well as other settings such as debug and metadata settings.
You may specify...
+ any solc-js version (using semver) listed at solc-bin. Specify the one you want and Truffle will get it for you.
+ "native" to use a natively compiled solc binary (you'll need to install this yourself, links to help below).
+ a dockerized solc tag from one of images published here.
+ a path to a locally available solc
+ "pragma" to have Truffle autodetect solc versions from your source files. This can be used to compile using multiple versions of solc.
+ a solc-js parser for faster docker and native compilations
In general, I decided to investigate what the problem might be and found out that if you have different versions of files in your project, you can specify pragma
and compile files with different versions. I found out about it from here
As I understand it, this functionality is available from truffle version 5.2.0 and higher. I also found a great repository with an example that will most likely be able to help - v5.2-example-box. Most likely if you compare your project with this one you will surely be able to find the error.
I would suggest installing a specific version of solc
as suggested in the documentation to check if there are any other issues.
For my work I use the following settings in truffle-config.js
:
module.exports = {
compilers: {
solc: {
version: '0.8.3',
parser: 'solcjs'
}
}
}
You also need to install a specific version of the package. Which will match the version from truffle-config.js
, in this case, this version is 0.8.3
.
To install the package, you need to call one of these commands for npm or yarn, depending on what you are using.
npm i [email protected]
yarn add [email protected]
Also in my case, there is such a version in the contract:
pragma solidity >=0.8.0;