我正在用solcjs和solc测试一些编译器选项,我只是编写合同的基本大纲。我收到警告Function state mutability can be restricted to view,有什么意见吗?
root@ubuntu-s-2vcpu-4gb-lon1-01:/geth/mybc/geth# more AddressContract.sol
pragma solidity ^0.4.19;
contract AddressContract {
string private myAddress;
function getAddress() public returns (string) {
return myAddress;
}
}
root@ubuntu-s-2vcpu-4gb-lon1-01:/geth/mybc/geth# vi AddressContract.sol
root@ubuntu-s-2vcpu-4gb-lon1-01:/geth/mybc/geth# solcjs --bin
AddressContract.sol
AddressContract.sol:5:1: Warning: Function state mutability can be
restricted to view
function getAddress() public returns (string) {
^
Spanning multiple lines.
root@ubuntu-s-2vcpu-4gb-lon1-01:/geth/mybc/geth#发布于 2018-02-14 04:01:33
这是警告而不是错误。你可以忽视它,这样就不会有什么不好的事情发生。
但是,它很有帮助地告诉您,由于您的函数没有更改状态,所以可以将其标记为view。看看这个答案是什么意思,以及为什么它是一个好主意:使用纯函数和视图函数修饰符有什么好处吗?
https://ethereum.stackexchange.com/questions/39561
复制相似问题