以太坊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
總結
以上是生活随笔為你收集整理的以太坊solidity编程常见错误(不定期更新)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《深入理解Java虚拟机》读书笔记八
- 下一篇: Effective Java(1)-创建