首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用OpenZeppelin 3.0 ERC20编译Truffle时出错

使用OpenZeppelin 3.0 ERC20编译Truffle时出错
EN

Ethereum用户
提问于 2020-06-19 09:27:21
回答 1查看 879关注 0票数 0

我正在尝试使用truffle compile命令编译这段代码

代码语言:javascript
复制
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract GLDToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("Gold", "GLD") public {
        _mint(msg.sender, initialSupply);
    }
}

这基本上是一个复制粘贴从开放的飞艇官方文件。

这段代码在Remix中运行得很好,但是当我尝试使用Trufffle运行它时,我得到了以下错误:

代码语言:javascript
复制
Error parsing @openzeppelin/contracts/token/ERC20/ERC20.sol: ParsedContract.sol:98:40: ParserError: Expected '{' but got reserved keyword 'override'
    function totalSupply() public view override returns (uint256) {
                                       ^------^
Compilation failed. See above.
Truffle v5.0.5 (core: 5.0.5)
Node v10.16.3

有人知道该怎么做吗?

谢谢

编辑:

我更改了solidity编译器的版本,并得到了另一个错误:

代码语言:javascript
复制
TypeError: Error parsing C:/tutorial-token/contracts/Migrations.sol: Cannot read property 'addFunction' of undefined
    at runWithReadCallback (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\solc\wrapper.js:37:1)
    at compileStandard (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\solc\wrapper.js:78:1)
    at Object.compileStandardWrapper (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\solc\wrapper.js:85:1)
    at Object.parseImports (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\parser.js:47:1)
    at Object.getImports (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\profiler.js:374:1)
    at Promise.all.then.results (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\profiler.js:346:1)
Truffle v5.0.5 (core: 5.0.5)
Node v10.16.3```
EN

回答 1

Ethereum用户

回答已采纳

发布于 2020-06-19 10:10:24

松露5.0.5默认使用Solc0.5.x(不确定x的值)。

仅支持Solc0.6中的override关键字。

你应该在你的特弗莱配置文件中添加:

代码语言:javascript
复制
compilers: {
    solc: {
        version: "0.6.0" // or find out what the latest version is and use that instead
    }
}

有关更多详细信息,请参阅这里

票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/84384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档