truffle compile 报错 Could not find a compiler version matching 0.6.3.

报错信息

➜  truffle compile  

Compiling your contracts...
===========================
✖ Fetching solc version list from solc-bin. Attempt #1
✔ Fetching solc version list from solc-bin. Attempt #2
Error: Could not find a compiler version matching 0.6.3. Please ensure you are specifying a valid version, constraint or build in the truffle config. Run `truffle compile --list` to see available versions.
    at VersionRange.errors (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/compilerSupplier/loadingStrategies/LoadingStrategy.js:66:1)
    at VersionRange.getSatisfyingVersionFromCache (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/compilerSupplier/loadingStrategies/VersionRange.js:85:1)
    at VersionRange.load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/compilerSupplier/loadingStrategies/VersionRange.js:201:1)
Truffle v5.1.14 (core: 5.1.14)
Node v13.8.0

解决方案

truffle-config.js 配置文件汇总加入版本控制,比如我修改是这样

module.exports = {
  compilers: {
    solc: {
      version: "^0.5.16" //^代表0.5.16以上版本,这里的^不能去掉,指定版本还是会报错!!!在Gitter里面看到有人解决了指定版本的问题,聊得有点多,没仔细看,一般用上^就可以了
    }
  },
  networks: {
   development: {
     host: "127.0.0.1",
     port: 9545,
     network_id: "*"
   }
  
};

我的合约

pragma solidity >=0.4.25 <0.7.0;

我的环境:

➜ solcjs --version
0.6.3+commit.8dda9521.Emscripten.clang

➜ truffle version
Truffle v5.1.14 (core: 5.1.14)
Solidity - ^0.5.16 (solc-js)
Node v13.8.0
Web3.js v1.2.1

解决过程

  1. 有的说是node权限问题,用sudo truffle compile, 试了下没有用。

  2. 也有说是因为node默认安装路径是/usr/local/... 所以没有权限,但是1不成立,所以2也不成立

  3. 搜到Gitter有人遇到同样的问题,有人回答,这样配置即可

 compilers: {
    solc: {
      version: "^0.4.24"
    }
  },

尝试了一下,SUCCESS!

➜  metacoin truffle compile       

Compiling your contracts...
===========================
✖ Fetching solc version list from solc-bin. Attempt #1
✔ Fetching solc version list from solc-bin. Attempt #2
> Compiling ./contracts/ConvertLib.sol
> Compiling ./contracts/MetaCoin.sol
> Compiling ./contracts/Migrations.sol
✖ Fetching solc version list from solc-bin. Attempt #1
✔ Fetching solc version list from solc-bin. Attempt #2
> Artifacts written to /Users/linfang/workspace/prove/metacoin/build/contracts
> Compiled successfully using:
 - solc: 0.5.16+commit.9c3226ce.Emscripten.clang

你可能感兴趣的:(以太坊)