Truffle issue :Different Solidity version in truffle

胡家維 Hu Kenneth
Singapore Blockchain-Dapps
2 min readMar 30, 2019

I cannot compiler my old smart contract in truffle.

I tried to use my old smart contract in solidity and trying migrate it with truffle but it failed because the solidity version is different from that I installed.

SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.17;
^----------------------^

Solution : specify solc version in truffle configuration file.

Solidity compiler settings. Supports optimizer settings for solc.

You may specify…

  • any solc-js version listed at solc-bin. Specify the one you want and Truffle will get it for you.
  • a natively compiled solc binary (you’ll need to install this yourself, links to help below).
  • a dockerized solc from one of images published here.
  • a path to a locally available solc

Truffle config example:

How to check truffle and solc version ?

> truffle version

--

--

胡家維 Hu Kenneth
Singapore Blockchain-Dapps

撰寫任何事情,O型水瓶混魔羯,咖啡愛好者,Full stack/blockchain Web3 developer,Founder of Blockchain&Dapps meetup ,Udemy teacher。 My Linktree: https://linktr.ee/kennethhutw