Can someone please help me in understanding why i am getting this error I am new to solidity and unable to resolve this have tried the way written in documentation too and getting the same error.

ParserError: Expected '{' but got reserved keyword 'override' function currentTime() internal view override returns (uint) { ^------^

I am trying to override Parent contract's currentTime() in Child. like below.


// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract Parent{
    enum State { Ongoing, Failed, Succeeded, PaidOut }

    string public name;
    uint public targetAmount;
    uint public fundingDeadline;
    address public beneficiary;
    State public state;
    mapping(address => uint) public amounts;
    bool public collected;
    uint public totalCollected;

    modifier inState( State expectedState ){
        require(state == expectedState, "Invalid State");

    constructor (
        string memory contractName,
        uint targetAmountEth,
        uint durationInMin,
        address beneficiaryAddress
    )  {
        name = contractName;
        targetAmount = targetAmountEth * 1 ether;
        fundingDeadline = currentTime() + durationInMin * 1 minutes;
        beneficiary = beneficiaryAddress;
        state = State.Ongoing;

    function contribute() public payable inState(State.Ongoing) {
        amounts[msg.sender] += msg.value;
        totalCollected += msg.value;

        if(totalCollected >= targetAmount){
            collected = true;

// ***         THIS IS THE FUNCTION               ***//

    function currentTime() internal virtual view returns(uint) {
        return block.timestamp;

I am trying to import the above contract into child.sol as :-

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

import "./Parent.sol";

contract Child is Parent{
    uint time;

    constructor (
        string memory contractName,
        uint targetAmountEth,
        uint durationInMin,
        address beneficiaryAddress
        Parent(contractName, targetAmountEth, durationInMin, beneficiaryAddress)


    function currentTime() internal view override returns (uint) {
        return time;

    function setCurrentTime(uint newTime) public {
        time = newTime;

I am using truffle with solc version 0.8.4


Just found the solution just need to install previous version of solc in truffle folder.

Use solc version v0.5.16

can change it by adding

compilers: {
       solc: {
           **version: "0.5.16"** 

after the network. or if this doesn't work go to the file where truffle is installed and change the solc version in package.json add it like ^0.5.16.

  • Please indicate which version of solc did you use to fix the problem.
    – Ismael
    Jun 6 at 19:40
  • @Ismael thanks for pointing this out just edited my answer Jun 9 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.