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 in Blockchain by slayer
• 29,040 points
203 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 by Omkar
• 65,850 points
0 votes
You can try another method :

contract HelloWorld{

      function sayHello() public returns(string memory){

        return("Hello world");

      }

}
answered Mar 18 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
• 65,850 points
145 views
0 votes
1 answer

Not able to compile truffle project

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

answered Jan 17 in Blockchain by Omkar
• 65,850 points
106 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 57 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
63 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
• 27,620 points
1,531 views
0 votes
1 answer
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 29, 2018 in Blockchain by Omkar
• 65,850 points
78 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
• 65,850 points
276 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.