Truffle compile SyntaxError No visibility specified Did you intend to add public

0 votes

When I run truffle compile I am getting this error:

/home/user/truffle/contracts/Hello-world.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/user/truffle/contracts/Hello-world.sol:7:4: SyntaxError: No visibility specified. Did you intend to add "public"?

   function Hello_world() {

   ^ (Relevant source part starts here and spans across multiple lines).

Compilation failed. See above.

I added public keyword and tried again:

pragma solidity ^0.4.15;


contract Hello {


   string public message;


   public function Hello_world() {


   message = "Hello World!";


   }

}

No use

sudo truffle compile

Error parsing /home/user/truffle/contracts/Hello-world.sol: ParsedContract.sol:7:4: ParserError: Function, variable, struct or modifier declaration expected.

   public function Hello_world() {

   ^----^

Compilation failed. See above.

Jan 17, 2019 in Blockchain by slayer
• 29,350 points
3,664 views

2 answers to this question.

0 votes

The solution you thought is right. The solution is to define it as public. But the way you did it is wrong. The right way to define is like this:

public function Hello_world() public {

//function body

}
answered Jan 17, 2019 by Omkar
• 69,230 points
0 votes
You can try another method :

contract HelloWorld{

      function sayHello() public returns(string memory){

        return("Hello world");

      }

}
answered Mar 18, 2019 by anonymous
Hi. Can you explain how returning string memory will specify the visibility?

Related Questions In Blockchain

0 votes
2 answers

Truffle migrate gives “ Error: No network specified. ”

You have to mention on which network ...READ MORE

answered Aug 13, 2018 in Blockchain by Omkar
• 69,230 points
1,494 views
–1 vote
1 answer

Not able to compile truffle project

Hi. If you look at the error ...READ MORE

answered Jan 17, 2019 in Blockchain by Omkar
• 69,230 points
1,674 views
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 1,419 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,763 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
44,424 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,288 views
0 votes
1 answer

Not able to migrate contract in Truffle: Error: No network specified. Cannot determine current network

Make these entries in truffle.js file: module.exports = { ...READ MORE

answered Nov 30, 2018 in Blockchain by Omkar
• 69,230 points
973 views
0 votes
1 answer

Solidity error: SyntaxError: No visibility specified.

As mentioned in the error, you have ...READ MORE

answered Dec 12, 2018 in Blockchain by Omkar
• 69,230 points
6,984 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP