My smart contract has pragma solidity 0.4.18;
According to Solidity: Best practices – Which compiler version should I use? Advantages / Disadvantages, this pragma will work on any compiler from 0.4.18 and upwards.
$ truffle version
Truffle v5.1.65 (core: 5.1.65)
Solidity v0.5.16 (solc-js)
Node v14.15.4
Web3.js v1.2.9
$ truffle compile
Compiling your contracts...
===========================
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\Wrestling.sol
CompileError: /F/hackernoon/contracts/Wrestling.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.5.16+commit.9c3226ce.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity 0.4.18;
^---------------------^
Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity 0.4.18".
Please update your truffle config or pragma statement(s).
(See https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration for information on
configuring Truffle to use a specific solc compiler version.)
My compiler version is 0.5.16, which I think is greater than 0.4.18. But truffle fails to compile my file.
I checked https://github.com/ethereum/solc-bin/blob/gh-pages/bin/soljson-v0.5.16%2Bcommit.9c3226ce.js, it doesn't look like a nightly build.
What caused the error?
Best Answer
If you want to compile from one version and upwards, you need to include symbol
^
:However, this will only take up to version 0.4.26, which is the latest from 0.4, but not versions above (0.5, 0.6...). As described in the official documentation:
You have two options:
truffle-config.js
)