简体   繁体   English

调用super.owner()。transfer(msg.value)给出错误

[英]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.

相关问题 如何通过 msg.value 将以太币转入智能合约? - How to transfer ether to smart contract by msg.value? 如何在不使用设置 msg.value 的情况下将资金从 msg.sender(amount) 转移到收件人地址 - how to transfer fund from msg.sender(amount) to recipient address without using setting msg.value msg.value 引发错误并且不会将 eth 发送到合同 - msg.value raises error and doesn't send eth to contract solidity中payable function如何通过msg.value方式收款? - How payable function in solidity receives money by msg.value method? TypeError:“msg.value”和“callvalue()”只能用于应付公共函数 - TypeError: "msg.value" and "callvalue()" can only be used in payable public functions 我无法将资金转移给我的 NFT 的所有者 - I am unable to transfer funds to the owner of my NFT Solidity:从另一个具有相同 msg.sender 的合约调用合约函数 - solidity: call contract function from another contract with the same msg.sender 如何使用Golang正确发送RPC调用以获得智能合约所有者? - How to correctly send RPC call using Golang to get smart-contract owner? 返回错误:VM Exception while processing transaction: revert only owner can call this function - Returned error: VM Exception while processing transaction: revert only owner can call this function 估计 ETH 转账和 ERC20 转账 gas 总是返回相同的值 - Estimating ETH transfer and ERC20 transfer gas always returns same value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM