3
    I'am building a local blockchain using etherium.I wrote a smart contract   "Hello" that allows to display a phrase. when I execute truffle.compile an error occurs:  No visibility specified. Did you intend to add "public"?

    pragma solidity ^0.4.15;
    contract Hello{
       string public message;
       function Hello() {
       message = "Hello, World : This is a Solidity Smart Contract on the Private Ethereum Blockchain ";
       }
    }

Compiling your contracts...

Compiling ./contracts/Hello.sol
Compiling ./contracts/Migrations.sol

/home/mohamed/Projects/Stage/Truffle/contracts/Hello.sol:1:1: 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.15;
^----------------------^
,/home/mohamed/Projects/Stage/Truffle/contracts/Hello.sol:4:4: SyntaxError: No visibility specified. Did you intend to add "public"?
   function Hello1() {
   ^ (Relevant source part starts here and spans across multiple lines).

Error: Truffle is currently using solc 0.5.0, but one or more of your contracts specify "pragma solidity ^0.4.15".
Please update your truffle config or pragma statement(s).
(See https://truffleframework.com/docs/truffle/reference/configuration#compiler-configuration for information on
configuring Truffle to use a specific solc compiler version.)

Compilation failed. See above.
Truffle v5.0.12 (core: 5.0.12)

Node v8.9.4

Joseph Cho
  • 4,033
  • 4
  • 26
  • 33
MS B
  • 199
  • 3
  • 14
  • What is it that you're confused about? Your code says it needs version 0.4.x of the compiler, but Truffle is using 0.5.x. Either update your code to use 0.5.x, or downgrade Truffle to use 0.4.x. – user94559 Apr 11 '19 at 17:52

1 Answers1

10

Add the following in your truffle config file:

module.exports = {
  // your existing config goes here
  // don't forget to put comma on the last element before proceeding to next line

  compilers: {
    solc: {
      version: "0.4.25"
    }
  }
}

Read more about the configuration here. All Solidity versions can be found here.

Zulhilmi Zainudin
  • 9,017
  • 12
  • 62
  • 98