I couldn't find a way to upgrade a version of truffle solidity compiler.
Also curious how to see that information for deployed contracts in truffle console
15 Answers
You can force truffle to use a specific solc version by installing that version directly in the truffle directory.
For example on Ubuntu the following with force truffle to use 0.4.15
$ cd /usr/local/lib/node_modules/truffle
$ npm install [email protected]
truffle version
will still show the default version but it will in fact utilize the updated version.
You can verify inside: /usr/local/lib/node_modules/truffle/package.json
...
"bundleDependencies": false,
"dependencies": {
...
"solc": "^0.4.15"
},
Locations on Windows
%AppData%\npm\node_modules\truffle
%AppData%\npm\node_modules\truffle\package.json
-
6
-
-
1I had pragma 0.4.19 in my files, and truffle complained even after I followed your instructions. Had to change it back to 0.4.18. package.json has .19.– uluCommented Jan 14, 2018 at 16:30
-
I'm trying the latest development version of solc, but I like the truffle testing framework. Is there a way to force truffle to use that one? Obviously the npm install path won't work -- it doesn't know about 0.4.20 at all. Commented Jan 23, 2018 at 15:24
-
PS. I see the comment in solcjs README about using the latest development snapshot. That seems to be what I want, but I don't know how to integrate that with truffle -- it seems better suited to a standalone js app that invokes a contract via solcjs. Commented Jan 23, 2018 at 15:33
If you're using ^v5.0.0 (including beta releases), you can bring your own compiler by adding this in your truffle config file (in this example it's set to 0.4.25
):
module.exports = {
...
compilers: {
solc: {
version: "0.4.25",
},
},
...
};
You can query the list of available compiler versions by running this:
truffle compile --list
-
1Only be aware that when using this method, if you run the
truffle version
cmd in the same dir where config file resides, it will show the solc version specified in the truffle config file. But when you run the same command in another directory, it will default to its internal solc version.– behkodCommented Jul 19, 2020 at 16:33 -
Problem with this is downloads the specified version for each compile rather than store it once and reuse - any ide how to fix this? Note: I installed the version into the global npm directory but truffle doesn't seem to use that version in my project. Commented Aug 17, 2021 at 15:53
-
1Hey @johnblair, I recommend you switch to Hardhat, which caches the compilers. Commented Aug 18, 2021 at 8:42
After a couple of attempts, I've made it by uninstalling and installing truffle, exactly as described in here:
npm uninstall -g truffle
npm install -g truffle
That updated Truffle itself though, along with the compiler.
You need to upgrade your truffle to do that.
npm install -g truffle@X
For example, to get solc 0.4.11 support, install truffle 3.2.2 or above.
npm install -g [email protected]
or
npm update -g [email protected]
Check your solc compiler version using the following command -
solc --version
Then you can use following commands to uninstall solc(solidity) compiler and install it again. It shall give you latest version(0.4.11) -
npm uninstall solc -g
npm install [email protected]
Check the solc version after installing it again.
In order to see the information of contracts, once you login to truffle console and run "compile" and "migrate" one by one. After that, You just need to type your ContractName or ContractName.abi to get the contract information.
-
it doesn't provide information on
solidity
version. how do you know that it will start using global solidity compiler. also, you need to prove in your response to show what was the version of solidity compiler and the new one when you installed it globally. Did you try it? How did you verify the new bumped version? You are saying thatabi
compiled JSON contract should have a version. I've looked into it and I don't see where is the version of the compiler.– rstormsfCommented Jun 9, 2017 at 17:12 -
Edited the answer to check solc compiler version, you can check it before uninstalling it and then install it either globally or in the project directory as per your requirement. I did not try it again, but it should work this way. Let me know if this doesn't work for you? Also for contract information, I did not say that abi would have solc compiler version, please read carefully. I said typing contract name or contractname.abi in truffle console would give you information about the contract - like available functions, attributes etc.– SanchitCommented Jun 9, 2017 at 17:32
-
Ok, My question is how to know which compiler version is being used in truffle. How to change it, how to read it. That's the exact question I'm asking. Please read my original question carefully– rstormsfCommented Jun 9, 2017 at 17:33
-
1Truffle has solc compiler in it. and my question is how to figure out which solc version is being used in truffle. simple as that– rstormsfCommented Jun 9, 2017 at 18:26
-
1@rstormsf Your question is about changing the version, not figuring it out. To figure it out, try
truffle version
or look in build/contracts/YourContract.json and scroll to the bottom to look at the "compiler" object which should say"name": "solc", "version": <the version>
.– WBTCommented Mar 8, 2018 at 17:21
On your project root directory, there's a file named "truffle-config.js"
Inside this file, you can find a solc config, and uncomment version line, and then put your prefer version. (ex: 0.5.7)
compilers: {
solc: {
version: "0.5.7", // Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
// settings: { // See the solidity docs for advice about optimization and evmVersion
// optimizer: {
// enabled: false,
// runs: 200
// },
// evmVersion: "byzantium"
// }
}
}
After this, just compile and truffle will download that version of solc automatically!
$ truffle compile
-
Didn't work. It didn't download the new version and kept using the old one, despite de setting in the config file. Commented Nov 20, 2019 at 1:55
Run uninstall
and then install
commands to get your Truffle and solc compiler upgraded to the latest version:
npm uninstall -g truffle
npm install -g truffle
Important: you may need to close the terminal and open it again to use the latest version.
Note: to check your current version execute:
truffle version
In the latest truffle after 5.x.x, it is possible to specify compiler version in truffle-config.js
:
module.exports = {
networks: {
... etc ...
},
compilers: {
solc: {
version: <string> // ex: "0.4.20". (Default: Truffle's installed solc)
}
}
};
Reference: https://github.com/trufflesuite/truffle/releases/tag/v5.0.0-beta.0#specify-a-solcjs-version
-
Is it possibl to just get it to download the compiler once instead of with each compile? Thanks. Note: Installing into the global npm directory for truffle did not work. Commented Aug 17, 2021 at 16:15
just responding as faced this issue in July 2020 and it took me quite a while to fix it as there aren't many resources for Solidity v0.6
So, here are things that I did to get my code compiled successfully.
Update Truffle, if you installed truffle before a significant amount of time to your development(I used it for a gig 6 months after I installed it as I was just playing around at the time and didn't started learning "actively" until recently).
Set compiler version for in "truffle-config.js" (make sure to use the current version as if you are using a library like OpenZeppelin-Contracts as there might be contracts in there using a different version of solidity than yours.
- Usually, the second solution should be enough for you to get up and running. But In my case, I had to manually install "Solc" with "npm install solc" (inside your project directory). This installed solidity compiler 0.6.10 for me.
Yes, it required me to do all three steps to get my code to compile successfully. I hope this helps someone
You need not to uninstall truffle just install your required version by these commands. For Ubuntu 16.04(suppose I want truffle v4.1.7):
sudo npm install -g [email protected]
Check truffle version:
truffle version
For any help with truffle commands:
truffle --help
If you just installed Truffle and want to use older version of Solidity, you can simply specifying the compiler version in the truffle-config.js
file:
...
// Configure your compilers
compilers: {
solc: {
version: "0.5.11", // Fetch exact version from solc-bin (default: truffle's version)
...
}
}
...
If this doesn't work for you and you are compiling your contracts using VS Code extension, most likely you will have to change the compiler version of the extension. Check this answer to find out more.
If you want to use newer version, you will have to upgrade or re-install Truffle itself. To check the latest version of the compiler, type truffle compile --list
As @Adam Lemmon suggested, you can hardcode the version that the global truffle
installation is using, or you can just update the version in the pragma solidity ^0.4.15;
statement of your contract.
Note: This will only work if you are not inheriting from any other contracts. If the parent contracts use a higher solidity version, you'll get the compilation errors.
You can't specify version, but we can specify some params as well: http://truffleframework.com/docs/advanced/configuration#solidity-compiler-configuration
solc: {
optimizer: {
enabled: true,
runs: 200
}
}
https://github.com/poanetwork/poa-bridge-contracts/blob/master/truffle.js#L49
I used next commands upgrade truffle when I want to compile solidity version: pragma solidity ^0.4.25;
npm uninstall -g truffle
npm install -g truffle@beta
I messed around with manually changing the installed truffle
package's solc
dependency, however the versions weren't compatible, it wouldn't run my tests properly and it felt very hacky.
Instead I just installed the truffle package that naturally had a dependency on the solc version I wanted. In my case I wanted solc": "0.4.24"
so I installed "truffle": "4.1.14"
.