Not able to compile truffle project

–1 vote

When I try to compile, I am getting some error regarding smart contract. But I am not understanding what it is because I dont know smart contract programming. Please help. I have mentioned the details below:

$ truffle compile

Compiling ./contracts/Hello-world.sol...
Compiling ./contracts/Migrations.sol...
Compilation warnings encountered:
/home/user/truffle/contracts/Hello-world.sol:7:4: SyntaxError: Functions are not allowed to have the same name as the contract. If you intend this to be a constructor, use "constructor(...) { ... }" to define it.
/home/user/truffle/contracts/Hello-world.sol:7:4: Warning: This declaration shadows an existing declaration.
   function Hello() {
   ^ (Relevant source part starts here and spans across multiple lines).
Compilation failed. See above.
Jan 17, 2019 in Blockchain by digger
• 26,740 points
1,828 views

1 answer to this question.

0 votes

Hi. If you look at the error logs, you will see the reason behind this error:

Functions are not allowed to have the same name as the contract.

So, change the contract name or the function name. If you don't wish to do this, then you will want to define this function as a constructor. 

contract abc {
...
...
...
function abc() public {
...
...
...
}
}
answered Jan 17, 2019 by Omkar
• 69,220 points

Related Questions In Blockchain

0 votes
1 answer

Not able to install truffle using npm install -g truffle

You need root access to install truffle, ...READ MORE

answered Nov 29, 2018 in Blockchain by Omkar
• 69,220 points
4,466 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,220 points
1,211 views
0 votes
1 answer

Not able to create contracts in truffle

It seems like you have files missing that ...READ MORE

answered Dec 11, 2018 in Blockchain by Omkar
• 69,220 points
906 views
0 votes
1 answer

Not able to unbox truffle drizzle

It could be due to a broken ...READ MORE

answered Jan 9, 2019 in Blockchain by Omkar
• 69,220 points
1,646 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,944 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,469 views
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,220 points
1,484 views
0 votes
1 answer
0 votes
1 answer

Not able to migrate truffle project even after running testrpc

Maybe you forgot to compile the project ...READ MORE

answered Dec 11, 2018 in Blockchain by Omkar
• 69,220 points
893 views
0 votes
1 answer

Not able to start testrpc for Ethereum truffle

Hey. It seems like you already have ...READ MORE

answered Nov 28, 2018 in Blockchain by Omkar
• 69,220 points
1,004 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