ethereumsoliditysmartcontractstruffle

How to declare constants in Solidity


I am really new to Solidity and smart contracts and would really appreciate some help. I am following a tutorial and this is the exact code they use. But when I compile the code I get this error:

ParserError: Expected primary expression. address public constant approver = ;

pragma solidity ^0.6.0;

contract ApprovalContract {

    address public sender;
    address public receiver;
    address public constant approver = ;

    function deposit(address _receiver) external payable {
        require(msg.value > 0);
        sender = msg.sender;
        receiver = _receiver;
    }

    function viewApprover() external pure returns(address) {
        return(approver);
    }

    function approve() external {
        require(msg.sender == approver);
        receiver.transfer(address(this).balance);
    }
}

Solution

  • The constant needs to be initialized

    address public constant approver = YOURADDRESS;