cgewecke / hardhat-gas-reporter

Gas Usage Analytics for Hardhat
MIT License
404 stars 55 forks source link

HH201 error when using with hardhat-toolbox #229

Open StephanGerbeth opened 2 months ago

StephanGerbeth commented 2 months ago

Hi,

i get the following error, after required the package

require('hardhat-gas-reporter');

in my hardhat config. No additional config.

Error HH201: Could not set param output for task gas-reporter:merge because its name is already used.

It seems the legacy tasks in your index file create those problem.

Or am I doing something wrong?

Cheers

cgewecke commented 2 months ago

@StephanGerbeth Could you provide additional details:

StephanGerbeth commented 2 months ago

@cgewecke i use hardhat@2.22.3 and this is my hardhat.config.cjs

require('@nomicfoundation/hardhat-toolbox');
require('@nomicfoundation/hardhat-ethers');
require('@nomicfoundation/hardhat-chai-matchers');
require('@unlock-protocol/hardhat-plugin');
require('hardhat-contract-sizer');
require('hardhat-gas-reporter');

const dotenv = require('dotenv-mono');

dotenv.config();

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: {
    version: '0.8.23',
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
        // details: {
        //   yulDetails: {
        //     optimizerSteps: 'u'
        //   }
        // }
      },
      viaIR: true
    }
  },

  contractSizer: {
    alphaSort: true,
    disambiguatePaths: false,
    runOnCompile: true,
    strict: true
  },

  gasReporter: {
    enabled: false,
    currency: 'EUR',
    L2: 'base',
    coinmarketcap: '...'
  },

  paths: {
    cache: './cache/'
  },

  networks: {
    hardhat: {
      loggingEnabled: false,
      allowUnlimitedContractSize: true
    },
    // for mainnet
    'base-mainnet': {
      url: 'https://mainnet.base.org',
      accounts: [process.env.MASTER_PRIVATE_KEY],
      gasPrice: 1000000000
    },
    // for Sepolia testnet
    'base-sepolia': {
      url: 'https://sepolia.base.org',
      accounts: [process.env.MASTER_PRIVATE_KEY],
      gasPrice: 1000000000
    },
    // for local dev environment
    'base-local': {
      url: 'http://localhost:8545',
      gasPrice: 1000000000
    }
  },
  defaultNetwork: 'base-local'
};

i don't actively run the merge task.

cgewecke commented 2 months ago

@StephanGerbeth I think the problem is that hardhat-toolbox (at the top of your config) includes an earlier version (v1) of the gas reporter, so the plugin is being loaded twice.

Would it be possible to see if things work without the toolbox? The complete list of plugins it comes with is at the link below,

https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-toolbox

cgewecke commented 2 months ago

Another option would be to coerce the version of hardhat-gas-reporter used by the toolbox to the latest version using something like yarn resolutions and let the toolbox load the plugin itself.

StephanGerbeth commented 2 months ago

@cgewecke thanks for the fast response. i didn't realized that hardhat-toolbox is loading an older version of hardhat-gas-reporter.

I use npm so I have to make an override

"overrides": {
    "hardhat-gas-reporter": "2.1.1"
  }

And it works perfectly. Thanks :)

cgewecke commented 2 months ago

@StephanGerbeth Oh good, Am going to reopen this issue for visibility so people can see your workaround.

The error message is very confusing and I suspect other people will run into this until the toolbox upgrades.