首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >源文件需要不同的编译器版本: Truffle

源文件需要不同的编译器版本: Truffle
EN

Stack Overflow用户
提问于 2018-12-30 15:58:29
回答 5查看 13.2K关注 0票数 6

我写了一个简单的智能合约,并尝试用松露迁移它。

代码语言:javascript
复制
$ truffle migrate
Compiling .\contracts\Election.sol...
Compiling .\contracts\Migrations.sol...

    /D/ethereum/electiondemo/contracts/Migrations.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
    pragma solidity ^0.4.24;
    ^----------------------^

Compilation failed. See above.`enter code here`
Truffle v5.0.0 (core: 5.0.0)
Node v8.11.1

坚实的版本是0.5.0。请查找以下智能合约代码:

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

contract Election {
    // Read/write candidate
    string public candidate;

    // Constructor
    constructor ( ) public {
        candidate = "Candidate 1";
    }
}
EN

回答 5

Stack Overflow用户

发布于 2018-12-30 16:05:25

得到了解决方案:在truffle.js中。您需要指定实度版本

代码语言:javascript
复制
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"** // ex:  "0.4.20". (Default: Truffle's installed solc)
       }
   }
};

在您的智能合同中提供相同的需求

票数 15
EN

Stack Overflow用户

发布于 2019-01-09 04:54:27

将以下行添加到truffle-config.js

代码语言:javascript
复制
{
  compilers: {
    solc: {
      version: "0.4.24" // ex:  "0.4.20". (Default: Truffle's installed solc)
    }
  }
}
票数 7
EN

Stack Overflow用户

发布于 2021-07-11 04:56:57

这就是我在合同上使用的

代码语言:javascript
复制
 pragma solidity >=0.7.0 <0.9.0;

在配置文件中

代码语言:javascript
复制
compilers: {
    solc: {
      // default is 0.5.16
      version: ">=0.7.0 <0.9.0",    // Fetch exact version from solc-bin (default: truffle's version)
    
      }
    }
  },
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53976057

复制
相关文章

相似问题

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