添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Problem is, this code is from the Solidity docs! I have tried many thing for this error but to no avail. The link where I got the code is: https://solidity.readthedocs.io/en/latest/solidity-by-example.html

I have an image attached with the error:

Can someone explain to me what I'm doing wrong? I have the right version, as per below:

kalyan@kalyan:/usr/bin$ truffle version

Truffle v4.1.13 (core: 4.1.13)

Solidity v0.4.24 (solc-js)

This is running on Ubuntu 18.04. Is there something else I should be doing?

The code before constructor is:

/// Modifiers are a convenient way to validate inputs to
/// functions. `onlyBefore` is applied to `bid` below:
/// The new function body is the modifier's body where
/// `_` is replaced by the old function body.
modifier onlyBefore(uint _time) { require(now < _time); _; }
modifier onlyAfter(uint _time) { require(now > _time); _; }
                Are you compiling via command line? Aside from the shadow declaration of bid (which they should fix), it works in Remix.
– Adam Kipnis
                Aug 3, 2018 at 2:27

I have faced this problem with the constructor in solidity too this can be solved really easily

if you are running your code in VSCODE than you may have installed a extension Solidity Extended

then you have then UNININSTALL it and reload your vscode editor

if you may have uinstalled and not reloaded your vs code than you will face same problem

> also set the pragma solidity version to pragma solidity >=0.4.21 < 0.7.0;

this worked for me

I simply removed the Solidity Extended plugin and it asked the VS Code reload, which i did, and then it worked fine. – ArifMustafa May 19, 2022 at 16:41

See the answer to a similar error here: https://ethereum.stackexchange.com/a/56727/27511 I'm reposting for convenience...

I had a similar problem. In my case it was the system version of solc I had installed. Here's what I had. I had solc installed through Homebrew, and also truffle installed. when I run truffle version:

Truffle v4.1.14 (core: 4.1.14)
Solidity v0.4.24 (solc-js)

So I had the latest version of truffle and seemingly, solc as well. However, when I run solc --version

solc, the solidity compiler commandline interface
Version: 0.4.19+commit.e67f0147.Darwin.appleclang

My system solidty version was different. I found that I had installed solidity through Homebrew (on Mac), so that was different from the version truffle was using. So the fix in my case, was to upgrade solidity using homebrew, it upgraded from 0.4.19 to 0.4.24 and my problem went away. To upgrade solidity using Homebrew:

brew update
brew upgrade
brew tap ethereum/ethereum
brew install solidity
brew linkapps solidity

The first two lines are probably all you need if you already have solidity installed, but added the rest for completeness.

This was on Mac, if you're on Linux, it might be a similar problem, make sure you upgrade the system installation of solidity, not what's installed with truffle.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.