blockchain - truffle - config 配置truffle truffle.config.js

访问量: 781

refer to: https://ethereum.stackexchange.com/questions/15749/how-do-i-specify-a-different-solidity-version-in-a-truffle-contract/130441#130441

https://trufflesuite.com/docs/truffle/reference/configuration/

一个拿来就用的精简版

# .env 文件
INFURA_API_URL = "wss://goerli.infura.io/ws/v3/427a8f460d514ebfadf0d6c60b09ef27"
MNEMONIC = "margin blouse tenant chat hub chef addict club rather prize strategy joy"
$ cat truffle-config.js
require('dotenv').config();
const HDWalletProvider = require('@truffle/hdwallet-provider');
const { INFURA_API_URL, MNEMONIC } = process.env;

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*"
    },
    goerli: {
      provider: () => new HDWalletProvider(MNEMONIC, INFURA_API_URL),
      network_id: '5',
      gas: 5500000,
//      gasPrice: 50000000000, // 50 gwei
      networkCheckTimeout: 1000000,
      timeoutBlocks: 200,
      addressIndex: 2
    }
  },
  compilers: {
    solc: {
      version: "0.8.15",   // 这样的话能快速的运行
    }
  }
};

配置compiler version  默认居然是 0.4.x

module.exports = {
  compilers: {
    solc: {
      version: <string>, // A version or constraint - Ex. "^0.5.0"
                         // Can be set to "native" to use a native solc or
                         // "pragma" which attempts to autodetect compiler versions
      docker: <boolean>, // Use a version obtained through docker
      parser: "solcjs",  // Leverages solc-js purely for speedy parsing
      settings: {
        optimizer: {
          enabled: <boolean>,
          runs: <number>   // Optimize for how many times you intend to run the code
        },
        evmVersion: <string> // Default: "istanbul"
      },
      modelCheckerSettings: {
        // contains options for SMTChecker
      }
    }
  }
}

每次卡在了 truffle compile 怎么办?

$ truffle compile

Compiling your contracts...
===========================
✖ Fetching solc version list from solc-bin. Attempt #1
✖ Fetching solc version list from solc-bin. Attempt #2
✖ Fetching solc version list from solc-bin. Attempt #3
✖ Fetching solc version list from solc-bin. Attempt #1
✖ Fetching solc version list from solc-bin. Attempt #2
✖ Fetching solc version list from solc-bin. Attempt #3
> Compiling ./contracts/MyTestNft.sol

运行命令 $ truffle compile --list

✖ Fetching solc version list from solc-bin. Attempt #1
✓ Fetching solc version list from solc-bin. Attempt #2
[
 "0.8.15",
 "0.8.14",
 "0.8.13",
 "0.8.12",
 "0.8.11",
 "0.8.10",
 "0.8.9",
 "0.8.8",
 "0.8.7",
 "0.8.6"
]

所以,修改 truffle-config.js

  compilers: {
    solc: {
      // version: "^0.8.0",   不要这样
      version: "0.8.15",    // 要这样
    }
  },

订阅/RSS Feed

Subscribe