solidity(solc)智能合约升级到0.5*遇到的问题

Functions are not allowed to have the same name as the contract. If you intend this to be a constructor, use "constructor(...) { ... }" to define it

函数名与合约名称不能重复,如果构造函数的话用以下方式:

function Token(uint256 initialSupply) ==> constructor(uint256 initialSupply)

 

No visibility specified. Defaulting to "public"

定义函数必须加上public关键字,例如:

function newFunder(address to) returns (uint)

==>

function newFunder(address to) public returns (uint)

 

Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning

定义指针需要加关键字storage,例如:

Funder f = funders[_u]; ==> Funder storage f = funders[_u];

 

Data location must be "memory" for parameter in function, but none was given

函数中的数据位置必须是"memory",例如:

function receiveApproval(address _from, bytes _extraData) public;

==>

function receiveApproval(address _from, bytes memory _extraData) public;

 

Data location can only be specified for array, struct or mapping types, but "memory" was given

array, struct or mapping类型的参数不需要加memory

 

Invalid type for argument in function call. Invalid implicit conversion from contract TokenERC20 to address requested

使用address(this)替代this,例如:

receiveApproval(msg.sender, _value, this, _extraData);

===>

receiveApproval(msg.sender, _value, address(this), _extraData);

 

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

msg.gas已经被gasleft()替换了,例如:

uint public _gas ==> gasleft()

 

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

thorw已经不支持了,需要使用require,例如:

if(_to != 0x0){ throw ; } ==> require(_to != address(0x0))

 

Event invocations have to be prefixed by "emit"

调用事件需要在前面加上emit关键字,例如:

Burn(msg.sender, _value)==>emit Burn(msg.sender, _value)

 

Operator != not compatible with types address and int_const 0

地址变量不能和0x0进行比较,需要改为address(0x0),例如:

require(_to != 0x0) ==> require(_to != address(0x0))

 

Member "transfer" not found or not visible after argument-dependent lookup in address

solidity 0.5,address地址类型细分为 address和 address payable,只有 address payable可以使用 transfer(), send()函数,例如:

address public owner ==> address payable public owner

 

Functions in interfaces must be declared external

接口必须定义为外部函数(回退函数(fallback function)同理),例如:

interface tokenRecipient { function receiveApproval(address _from, bytes _extraData) public; }

==>

interface tokenRecipient { function receiveApproval(address _from, bytes _extraData) external; }

 

Data location must be "calldata" for parameter in external function, but none was given

外部函数中的数据位置必须是"calldata",例如:

interface tokenRecipient { function receiveApproval(address _from, bytes _extraData) external; }

==>

interface tokenRecipient { function receiveApproval(address _from, bytes calldata _extraData) external; }

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值