Reputation: 5
I am currently learning solidity.
I have written the code as it appears in "Hands-On Smart Contract Development With Solidity and Ethereum" (O'Reilly/Japanese edition), but when I run TruffleTest, I get the following error
CompileError: project:/contracts/Fundraiser.sol:9:1: ParserError: Function, variable, struct or modifier declaration expected.
Here is the code.
https://github.com/okahijiki/fundraiser
I would appreciate any advice you can give me.
My library's version
Truffle v5.5.31 (core: 5.5.31)/ Ganache v7.4.3/ Solidity v0.5.16 (solc-js)/ Node v16.15.1/ Web3.js v1.7.4
Upvotes: 0
Views: 152
Reputation: 43571
Here's the linked code:
pragma solidity >0.4.23 <0.7.0;
contract Fundraiser{
string public name;
constructor(string memory _name)public{
name = _name;
}
Count the number of opening braces - and the number of closing braces. You are correctly opening and closing the contract
, but the constructor
is missing its closing brace.
The solution is simple - close the constructor
block with a brace as well.
contract Fundraiser{
string public name;
constructor(string memory _name)public{
name = _name;
} // closing the constructor here
}
Upvotes: 0