2

I am trying to deploy an upgradeable smart contract on bsc testnet using hardhat. But after running npx hardhat run --network testnet scripts/deploy.js it gives me the following error.

ProviderError: max code size exceeded
    at HttpProvider.request (D:\rarible-hardhat\protocol-contracts\tokens\node_modules\hardhat\src\internal\core\providers\http.ts:46:19)ts:46:19)                                                                                                                       ccounts.ts:142:34)
    at HDWalletProvider.request (D:\rarible-hardhat\protocol-contracts\tokens\node_modules\hardhat\src\internal\core\providers\accounts.ts:142:34)                                                                                                              nal\ethers-provider-wrapper.ts:13:20)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at EthersProviderWrapper.send (D:\rarible-hardhat\protocol-contracts\tokens\node_modules\@nomiclabs\hardhat-ethers\src\internal\ethers-provider-wrapper.ts:13:20)

How can I adjust the code size or any other method to resolve this error.

3

How can I adjust the code size or any other method to resolve this error.

The contract code size limit is 24kB (24,576 bytes).

You'll need to reduce the size of the contract before deploying, or split it into several smaller contracts and libraries.

Low hanging fruits would be any string literals (e.g. error strings in require() statements), and removing any unnecessary functions or variables.

2
  • I reduced the optimization runs from 200 to 1 and its working fine now
    – mzaidi
    May 5 at 12:01
  • Yep, that's another way. However, that will increase the gas costs for the users when they execute the functions at a later date. If that's not a consideration, then changing the optimisation is probably the way to go. May 5 at 12:10
0

you can try Above mentioned steps but before doing any of that, Please try compilerOptimization setting in hardhat.config.js.

module.exports = {
  solidity: {
    version: "0.8.6",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },
  networks: {
    hardhat: {
    },
    localhost: {
    },
    fuji: {
     
    }
  },
  paths: {
    sources: "./contracts",
    tests: "./test",
    cache: "./cache",
    artifacts: "./artifacts"
  }

};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.