固体类型“发送”和“转移”仅适用于类型的“应付款项”的对象。使用应付的地址
因此,我正在写一份关于坚固性的智能合同,我认为我的编译器是错误的,但是我尝试使用混音,松露和硬汉,他们都会给出同样的错误,我不知道我做错了,因为我将“受益人”变量宣布为应付款项,即使在构造函数中,任何人都可以帮助我吗?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
//This contract uses a "Timelock" function, please note that if you actually use it, you CANNOT withdraw funds until the set date!!!!
contract Banking {
address public Beneficiary;
uint256 public givenTime;
constructor(address payable _Beneficiary, uint256 _givenTime) {
require(_givenTime > block.timestamp); //Make sure the time is in the future.
Beneficiary = _Beneficiary;
givenTime = _givenTime;
}
function Withdraw() public {
require(block.timestamp >= givenTime);
address(Beneficiary).transfer(address(this).balance);
}
}
So, i am writing a smart contract on Solidity, and i thought my compiler was wrong or something, but i tried using Remix, Truffle and Hardhat, and them all give the same error, i don't know that i am doing wrong because i explicit declared the "Beneficiary" variable as payable, even in the constructor, can anyone help me?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
//This contract uses a "Timelock" function, please note that if you actually use it, you CANNOT withdraw funds until the set date!!!!
contract Banking {
address public Beneficiary;
uint256 public givenTime;
constructor(address payable _Beneficiary, uint256 _givenTime) {
require(_givenTime > block.timestamp); //Make sure the time is in the future.
Beneficiary = _Beneficiary;
givenTime = _givenTime;
}
function Withdraw() public {
require(block.timestamp >= givenTime);
address(Beneficiary).transfer(address(this).balance);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
2件事是错误的:
当您启动受益人时,您不应该像这样付款时启动他:
在
fort()
中,您应该将地址投入到应付款中:也不建议使用由于气体限制而再转移,我建议您这样使用呼叫:
2 Things are wrong:
When you init Beneficiary you didn't init him as payable like this:
And in the
Withdraw()
you should cast the address into payable like this:Also it is not recommended to use transfer anymore because of gas restrictions, I recommend that you use call instead like this: