hardhat同时编译不同版本的智能合约

    hardhat可以同时编译不同版本的.sol智能合约,只需要在hardhat.config.ts或hardhat.config.js配置文件的compilers/version字段添加对应的版本号即可。比如,同时编译 solc-v0.4.26、v0.5.12、v0.6.12的sol智能合约,则新增一个compilers/version字段,在该字段里添加版本号即可。这里以hardhat v2.6.5为例进行说明。

    配置文件hardhat.config.js 或 hardhat.config.ts

修改前

 require("@nomiclabs/hardhat-waffle");

 module.exports = {
    
    
   solidity: "0.6.12", //修改此处

   networks: {
    
    
    localhost: {
    
    
        url: "http://127.0.0.1:8545"
     },
 
     // ropsten: {
    
    
     //   url: `https://eth-ropsten.alchemyapi.io/v2/${
    
    ALCHEMY_API_KEY}`,
     //   accounts: [`0x${
    
    ROPSTEN_PRIVATE_KEY}`]
     // },
   }
 };
 

修改后

require("@nomiclabs/hardhat-waffle");

module.exports = {
    
    
 solidity: {
    
    
        compilers: [    //可指定多个sol版本
            {
    
    version: "0.4.26"},
            {
    
    version: "0.5.12"},
            {
    
    version: "0.6.12"}
        ]
  },

  networks: {
    
    
   localhost: {
    
    
       url: "http://127.0.0.1:8545"
    },

    // ropsten: {
    
    
    //   url: `https://eth-ropsten.alchemyapi.io/v2/${
    
    ALCHEMY_API_KEY}`,
    //   accounts: [`0x${
    
    ROPSTEN_PRIVATE_KEY}`]
    // },
  }
};

Guess you like

Origin blog.csdn.net/sanqima/article/details/121781340