transfer“ are only available for objects of type “address payable“, not “addr"/>
TypeError: “send“ and “transfer“ are only available for objects of type “address payable“, not “addr
TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address".
以下书写方式可以看到编译会报错。
pragma solidity ^0.8.7;contract transferTest{function transfer(address account) payable public{account.transfer(msg.value);}
}TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address".
这个写法在之前版本没有什么问题,但是在 Solidity 0.8
之后,address就不是默认payable类型
了。所以要在address前面加上payable的强制类型转换
,如下:
pragma solidity ^0.8.7;contract transferTest{function transfer(address account) payable public{payable(account).transfer(msg.value);}
}TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address".
然后就可以成功编译啦!
参考链接: 我自己的个人博客.
更多推荐
TypeError: “send“ and “transfer“ are only available for objects of type “address
发布评论