[英]Call to super.owner().transfer(msg.value) giving errors
I have a contract that inherits from Open Zeppelin's Ownable contract. 我有一个合同是从Zeppelin的Ownable合同继承的。 There is a method payFees() in my contract that is expected to transfer funds to the owner of the contract.
我的合同中有一个payFees()方法,有望将资金转移给合同的所有者。 The definition of payFees is as follows
payFees的定义如下
function payFees() public payable {
require(students.has(msg.sender), "DOES NOT HAVE STUDENT ROLE");
if(this.areFeesEnough(msg.value))
{
super.owner().transfer(msg.value);
studentFees[msg.sender] = true;
}
}
I expect that a call to super.owner() returns the contract owner given that owner()
is a public view function in the parent Ownable
contract that returns the owner. 我希望对super.owner()的调用会返回合同所有者,因为
owner()
是返回所有者的父Ownable
合同中的公共视图函数。 Unfortunately, the code fails with the error. 不幸的是,代码因错误而失败。
TypeError: Member "transfer" not found or not visible after argument-dependent lookup in address.
super.owner().transfer(msg.value);
Any help is appreciated.Thank you. 感谢您的帮助。谢谢。
Assuming the Ownable
contract you're using is similar to https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ownership/Ownable.sol , the issue is that owner()
returns an address
, but starting in Solidity 0.5, you can only transfer ether to an address payable
. 假设您使用的
Ownable
合同类似于https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ownership/Ownable.sol ,问题在于owner()
返回一个address
,但是开始在Solidity 0.5中,您只能将以太转移到address payable
。
You can convert by casting through uint160
first, something like this: 您可以先通过
uint160
进行转换,例如:
address(uint160(_owner)).transfer(msg.value);
Note that you can just use _owner
directly or just call owner()
. 请注意,您可以直接使用
_owner
或仅调用owner()
。 No need to call super.owner()
unless you've overridden owner
in your contract and need to make sure to call the parent contract. 除非您在合同中覆盖了
owner
并且需要确保调用父合同,否则无需调用super.owner()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.