0

I can't compile my smart contract that I'm trying to deploy:

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

contract DepositContract { // The amount of time (in hours) that the contract will run for const uint256 DURATION_HOURS = 24; // The payout rate (in percentage per hour) const uint256 PAYOUT_RATE = 4.16666666667;

// Mapping from user address to their deposit balance
mapping(address => uint256) public deposits;

// The total amount of deposits in the contract
uint256 public totalDeposits;

// The start time of the contract (in seconds)
uint256 public startTime;

// The end time of the contract (in seconds)
uint256 public endTime;

// Flag to indicate whether the contract is active
bool public isActive;

constructor() public {
    // Set the start and end times of the contract
    startTime = now;
    endTime = startTime + DURATION * 3600;
    // Set the contract to be active
    isActive = true;
}

// Function to deposit FTM into the contract
function deposit() public payable {
    // Check that the contract is still active
    require(isActive, "The contract is no longer active.");
    // Check that the deposit is not zero
    require(msg.value > 0, "Deposit

It keeps giving me this error:

    contracts/DepositContract.sol:6:11: ParserError: Expected identifier but got 'uint256'
    const uint256 DURATION_HOURS = 24;
    ^-----^
Jeremy Then
  • 4,599
  • 3
  • 5
  • 28
  • 3
    const is not solidity, try constant instead and after the type, like this: uint256 constant DURATION = 24; – DrGorilla.eth Jan 05 '23 at 23:05
  • Thank you, I corrected it but now it's giving me this error: contracts/DepositContract.sol:38:32: ParserError: Expected string end-quote. require(msg.value > 0, "Deposit ^------^ – Strong Thrust Jan 06 '23 at 09:58

1 Answers1

2

You are missing an end quote, parenthesis, and semicolon in your final require statement along with a few other syntax issues. You will also need a closing bracket to close out the deposit() function, along with a second closing bracket to close out your contract. Try this:

// Function to deposit FTM into the contract
    function deposit() public payable {
        // Check that the contract is still active
        require(isActive, "The contract is no longer active.");
        // Check that the deposit is not zero
        require(msg.value > 0, "Deposit");
        }
    }

You also declare a constant DURATION_HOURS but then go on to use an undeclared variable DURATION in your constructor. I assume they are meant to be the same, so in your constructor, try this:

endTime = startTime + DURATION_HOURS * 3600;

Lastly solidity does not support fixed point numbers so your declaration of:

uint256 constant PAYOUT_RATE = 4.16666666667;

will need to change to:

uint256 constant PAYOUT_RATE = 416666666667;

For more information please refer to this How can I represent decimal values in Solidity?

Solidity by Example may be helpful when running into syntax problems in the future: https://solidity-by-example.org/