zoukankan      html  css  js  c++  java
  • 以太坊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

  • 相关阅读:
    c# 多线程系列二 自定义线程执行器
    博客人生
    c#实现分组服务器,单一无重复生成ID
    c# 游戏策划配置工具
    tar命令
    maven的一些使用技巧
    FSCapture截图工具
    删除已经跟踪的文件夹的版本控制
    idea模板的设置
    centos安装sublime
  • 原文地址:https://www.cnblogs.com/xiaocongcong888/p/9432155.html
Copyright © 2011-2022 走看看