gpt4 book ai didi

compiler-errors - Solidity - 标识符未找到或不唯一 onlyOwner()

转载 作者:行者123 更新时间:2023-12-05 08:46:21 25 4
gpt4 key购买 nike

运行 truffle compile 时出现以下 truffle 编译错误:

DeclarationError : Identifier not found or not unique.
--> project:/contracts/TestCoin.sol:183:56:
|
183 | function excludeFromRewards(address account) public onlyOwner() {
|


我的 token 合约中有以下代码。

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";

contract TestCoin is ERC20 {

constructor(_name, _symbol) {
_name = name();
_symbol = symbol();
}

.......

function excludeFromRewards(address account) public onlyOwner() {
.......
}

.......
}

有谁知道我在这里缺少什么?我似乎无法解决这个问题,我正在导入 Ownable.sol 文件,所以我很困惑为什么会这样。我需要说使用 Ownable 作为进口的任何东西吗?我假设它只会继承那些导入。

更新:

如果我调用位于 ownable.sol 中的所有者函数,我会得到同样的错误。

if(owner() == msg.sender)

Undeclared identifier.
if(owner() == msg.sender)
^^^^^

它似乎无法识别该文件。有什么想法吗?

更新#2:

我想通了并在下面发布了我的解决方案。谢谢!

最佳答案

好的,我想通了。我需要将 Ownable 注入(inject)合约本身,以便它可用。

contract TestCoin is ERC20, Ownable {
*********
}

关于compiler-errors - Solidity - 标识符未找到或不唯一 onlyOwner(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69888515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com