简体   繁体   English

Solidity 库 openzeppelin-solidity/contracts/utils/Context.sol:15:1: ParserError: Expected pragma, abstract contract Context { ^------^

[英]Solidity library openzeppelin-solidity/contracts/utils/Context.sol:15:1: ParserError: Expected pragma, abstract contract Context { ^------^

im trying to follow the tutotial BUILDING ROBUST SMART CONTRACTS WITH OPENZEPPELIN from www.trufflesuite.com我正在尝试遵循来自www.trufflesuite.com的 OPENZEPPELIN 的教程 BUILDING ROBUST SMART CONTRACTS

here the link https://www.trufflesuite.com/tutorials/robust-smart-contracts-with-openzeppelin这里的链接https://www.trufflesuite.com/tutorials/robust-smart-contracts-with-openzeppelin

Creating a "TutorialToken" smart contract创建“TutorialToken”智能合约

after installing OpenZeppelin and downloading the project template I tried to compile and get this error, I haven't coded anything of my own yet, it's basically an empty project and it should compile according to the tutorial but fails due to an error from the OpenZeppelinon files.安装 OpenZeppelin 并下载项目模板后,我尝试编译并得到此错误,我还没有编写任何自己的代码,它基本上是一个空项目,它应该根据教程编译,但由于 OpenZeppelinon 的错误而失败文件。

Compilation Failed编译失败

Thank you for your time to read this感谢您花时间阅读本文

TutorialToken.sol

pragma solidity 0.6.0;

import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";

contract TutorialToken is ERC20 {
    
        string public name = "TutorialToken";
        string public symbol = "TT";
        uint8 public decimals = 2;
        uint public INITIAL_SUPPLY = 12000;


        constructor() public {
        _mint(msg.sender, INITIAL_SUPPLY);
    } 
}

truffle-config.js

  module.exports = {   // See <http://truffleframework.com/docs/advanced/configuration>   // for more about customizing your Truffle configuration!  
 networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*" // Match any network id
    }   },
    compilers: {
       solc: {
    version: "0.4.24" //(Default: Truffle's installed    solc)   
    }  
  }

}; };

Fixed !!!!固定的 !!!!

its working now !!它现在工作!

I got the answer from OpenZeppelin Community:我从 OpenZeppelin 社区得到了答案:

It seems like this tutorial use the compiler version is 0.4.x, but now, the newest version is 0.8.x, so I think you should run npm i openzeppelin-solidity@2.0.0 to install.本教程使用的编译器版本似乎是 0.4.x,但现在,最新版本是 0.8.x,所以我认为您应该运行 npm i openzeppelin-solidity@2.0.0 来安装。

BTW, you can have a look at some newer tutorials:顺便说一句,您可以查看一些较新的教程:

OpenZeppelin Upgrades: Step by Step Tutorial for Truffle OpenZeppelin Upgrades: Step by Step Tutorial for Hardhat OpenZeppelin 升级:Truffle 分步教程 OpenZeppelin 升级:Hardhat 分步教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM