TypeError: “send“ and “transfer“ are only available for objects of type “address payable“, not “addr

编程入门 行业动态 更新时间:2024-10-23 21:29:28

TypeError: “send“ and “<a href=https://www.elefans.com/category/jswz/34/1756457.html style=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

本文发布于:2024-03-05 03:57:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1711251.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:transfer   objects   TypeError   send   payable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!