【问题标题】:Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify “pragma solidity ^0.8.0”错误:Truffle 当前使用的是 solc 0.5.16,但您的一个或多个合约指定“pragma solidity ^0.8.0”
【发布时间】:2021-09-05 06:18:18
【问题描述】:

错误:Truffle 当前使用的是 solc 0.5.16,但您的一个或多个合约指定“pragma solidity ^0.8.0”

这是错误的照片 - https://gyazo.com/2f5ea2f50cc1d4ef5eea2f21d0e04fe7

我所有的合约都使用 ^0.8.0 pragma。我的 truffle-config 也使用与您在此处看到的相同的版本 - https://gyazo.com/1ec8b28ca48902c091004f8659cf678d

请帮忙。非常感谢。

【问题讨论】:

    标签: blockchain solidity truffle erc20 openzeppelin


    【解决方案1】:

    省略“^”。不是version:"^0.8.0"

    compilers: {
           solc: {
               version: "0.8.0"  
           }
    }
    

    【讨论】:

    • 谢谢,明确的版本声明成功了!
    【解决方案2】:

    @Yilmaz 是正确的,需要修改版本。将 truffle-config.js 文件更改为正确的编译器版本。确保您有一个版本集。我有同样的错误,因为没有设置版本。如果您的文件如下所示:

    compilers: {
      solc: {
        // version: "0.5.1",    // Fetch exact version from solc-bin (default: truffle's version)
        // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
        // settings: {          // See the solidity docs for advice about optimization and evmVersion
        //  optimizer: {
        //    enabled: false,
        //    runs: 200
        //  },
        //  evmVersion: "Byzantium"
        // }
    }
    

    把它改成这样:

    compilers: {
      solc: {
        version: "^0.8.0"
    }
    

    【讨论】:

      【解决方案3】:

      从 truffle-config.js 中取消注释这一行:

      compilers: {
        solc: {
          version: "0.8.10",  // <-- this one
          .
          .
          ...
      

      【讨论】:

        猜你喜欢
        • 2021-08-02
        • 1970-01-01
        • 2021-07-11
        • 2021-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-16
        • 2022-09-23
        相关资源
        最近更新 更多