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.
//Parent.solc
// 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 ***//
// *** I NEED TO OVERRIDE IN MY CHILD CONTRACT ***//
function currentTime() internal virtual view returns(uint) {
return block.timestamp;
}
}
I am trying to import the above contract into child.sol as :-
//Child.sol
// 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)
{
}
// *** HERE I AM TRYING TO OVERRIDE *** //
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