类型地址不是隐式转换为预期类型地址应付的

发布于 2025-01-21 13:50:06 字数 485 浏览 0 评论 0原文

我正在使用Cryptozombies Solidity教程,并且有一个问题:

Type address is not implicitly convertible to expected type address payable.

这是代码:

function withdraw() external onlyOwner {
        address payable _owner = address(uint160(owner()));
        _owner.transfer(address(this).balance);
    }

我使用VSCODE和固体扩展。 IDE以红色突出显示这一行:

address payable _owner = address(uint160(owner()));

并显示上述错误。我应该怎么做才能避免此错误?

I am taking CryptoZombies Solidity tutorial and I have got such a problem:

Type address is not implicitly convertible to expected type address payable.

Here is the code:

function withdraw() external onlyOwner {
        address payable _owner = address(uint160(owner()));
        _owner.transfer(address(this).balance);
    }

I use VSCode and a Solidity extension. The IDE highlights this line in red:

address payable _owner = address(uint160(owner()));

and displays the above error. What should I do to avoid this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木有鱼丸 2025-01-28 13:50:06

您可以使用付款() Typecast函数将地址>地址>的类型更改为 地址应付

// assuming `owner()` returns an `address`
// it's redundant to convert it to `uint160` and then back to `address`
address payable _owner = payable(owner());

You can use the payable() typecast function to change the type of an address to address payable.

// assuming `owner()` returns an `address`
// it's redundant to convert it to `uint160` and then back to `address`
address payable _owner = payable(owner());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文