【问题标题】:How to declare constants in Solidity如何在 Solidity 中声明常量
【发布时间】:2020-02-24 17:43:13
【问题描述】:

我对 Solidity 和智能合约非常陌生,非常感谢一些帮助。我正在关注一个教程,这是他们使用的确切代码。但是当我编译代码时,我得到了这个错误:

ParserError:预期的主表达式。 地址公共常量​​批准者 = ;

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);
    }
}

【问题讨论】:

    标签: ethereum solidity smartcontracts truffle


    【解决方案1】:

    常量需要初始化

    address public constant approver = YOURADDRESS;
    

    【讨论】:

      猜你喜欢
      • 2022-11-13
      • 2020-12-07
      • 2011-06-23
      • 1970-01-01
      • 2012-09-29
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多