如何在 Truffle 中使用旧的 solc 编译器

How to use older solc compilers with Truffle

我正在尝试重现以太坊上发生的 DAO 攻击,但是,我无法编译 DAO 代码。当前的 truffle 稳定版不支持指定 solc 版本。 truffle我用的是5.0.0 beta 1版本,支持指定一个solc版本。 编译 DAO 代码时,出现此错误。

TypeError: Error parsing E:/Desktop/MetaCoin/contracts/DAO.sol: solc.compileStandard is not a function
    at Object.parseImports (C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\parser.js:49:1)
    at Object.getImports (C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\profiler.js:332:1)
    at Promise.all.then.results (C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\profiler.js:305:1)
    at <anonymous>

伙计们有什么想法吗?

从 Truffle 5.0.0 beta -0 开始,您可以 specify a solcjs version

我刚刚在我的项目中尝试过它并且有效。一定要把版本号设为string,使用下面的代码:

module.exports = {
  networks: {
    ... etc ...
  },
  compilers: {
     solc: {
       version: <string>  // ex:  "0.4.20". (Default: Truffle's installed solc)
     }
  }
};