gpt4 book ai didi

ethereum - 如何在 Solidity 中声明常量

转载 作者:行者123 更新时间:2023-12-03 08:48:31 25 4
gpt4 key购买 nike

我对 Solidity 和智能合约非常陌生,非常感谢一些帮助。我正在遵循教程,这就是他们使用的确切代码。但是当我编译代码时出现此错误:

解析器错误:预期的主表达式。 地址公共(public)常量​​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);
}
}

最佳答案

常量需要初始化

address public constant approver = YOURADDRESS;

关于ethereum - 如何在 Solidity 中声明常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60381305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com