• 以太坊solidity编程常见错误(不定期更新)


    1、报错:

    Expected token Semicolon got 'eth_compileSolidity' funtion setFunder(uint _u,uint _amount){

    解决:

    funtion关键字错了,需要用function;

    2、报错:

    Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning. Funder f = funders[_u]; ------

    解决:

    Funder f,定义指针需要加关键字storage ;修改为Funder storage f = funders[_u];

    3、报错:

    Invoking events without "emit" prefix is deprecated. e("newFunder",_add,_amount); -------------------------

    解决:

    调用事件需要在前面加上emit关键字,修改为emit e("newFunder",_add,_amount);

    4、报错:

    No visibility specified. Defaulting to "public". function newFunder(address _add,uint _amount) returns (uint){ ^ (Relevant source part starts here and spans across multiple lines).

    解决:

    定义函数必须加上public关键字,修改为function newFunder(address _add,uint _amount) public returns (uint){

    5、报错:

    "msg.gas" has been deprecated in favor of "gasleft()" uint public _gas = msg.gas; -----

    解决:msg.gas已经被gasleft()替换了。修改为uint public _gas = gasleft();

    6、报错:

    "throw" is deprecated in favour of "revert()", "require()" and "assert()". throw ;

    解决:solidity已经不支持thorw了,需要使用require,用法require()

    throw 写法:

    if(msg.sender !=chairperson ||voters[_voter].voted ){

    throw ;

    }

    require写法:

    require(msg.sender !=chairperson ||voters[_voter].voted);

    7、报错:

    This declaration shadows an existing declaration. Voter delegate = voters[to]; ------------

    解决:变量重复定义,变量名和函数名不能相同。

    8、报错:

    error: Function state mutability can be restricted to pure

    解决:以前版本是可以不指定类型internal pure(外部不可调用),public pure(外部可调用)(如不指定表示函数为可变行,需要限制)

    9、报错:

    "sha3" has been deprecated in favour of "keccak256"
    解决:sha3已经替换为keccak256

  • 相关阅读:
    GP服务之IDW GIS空间插值密度分布图
    Cesium添加标注
    arcgis时间滑块time slider工具
    ArcObjects和ArcEngine的区别
    Android 多媒体 1.1 获取多媒体信息[原创]
    Android 获取root权限 实现重启
    Android GIF 编解码
    中国的程序员只能支撑到30岁么。
    Android通过摇晃手机的频率来控制声音的频率
    Android ListView 下拉刷新 上拉更多[实例]
  • 原文地址:https://www.cnblogs.com/xiaocongcong888/p/9432155.html
Copyright © 2020-2023  润新知