The Blockchain- Dapps Daily — March 30, 2019 — Different Solidity version 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;
^----------------------^
Image for post
Image for post

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:

Image for post
Image for post

How to check truffle and solc version ?

> truffle version
Image for post
Image for post

Written by

撰寫任何事情,O型水瓶混魔羯,咖啡愛好者,Full stack/blockchain developer,Founder of Blockchain&Dapps meetup and DeFi-Decentralized-Finance-SG meetup,Udemy teacher。

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store