Mag*_*Man 2 compiler-errors compilation solidity
运行时出现以下 truffle 编译错误truffle compile:
DeclarationError : Identifier not found or not unique.
--> project:/contracts/TestCoin.sol:183:56:
|
183 | function excludeFromRewards(address account) public onlyOwner() {
|
Run Code Online (Sandbox Code Playgroud)
我的代币合约中有以下代码。
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() {
.......
}
.......
}
Run Code Online (Sandbox Code Playgroud)
有谁知道我在这里缺少什么?我似乎无法克服这一点,并且正在导入文件Ownable.sol,所以我很困惑为什么会发生这种情况。我是否需要说使用 Ownable 作为导入的任何内容?我认为它只会继承这些导入。
更新:
如果我调用位于 ownable.sol 中的所有者函数,我会得到相同的错误。
if(owner() == msg.sender)
Undeclared identifier.
if(owner() == msg.sender)
^^^^^
Run Code Online (Sandbox Code Playgroud)
它似乎无法识别该文件。有什么想法吗?
更新#2:
我弄清楚了并在下面发布了我的解决方案。谢谢!
Mag*_*Man 10
好吧,我明白了。我需要将 Ownable 注入到合约本身中,以便它可用。
contract TestCoin is ERC20, Ownable {
*********
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3428 次 |
| 最近记录: |