abhinna1 / EHR-Contract

0 stars 0 forks source link

ProviderError: VM Exception while processing transaction: code size to deposit exceeds maximum code size #2

Open abhinna1 opened 1 year ago

abhinna1 commented 1 year ago

image

Cause: This error is caused because smart-contracts have a size-limit to be deployed into the blockchain network.

abhinna1 commented 1 year ago

Solution: This issue can be fixed by enabling the optimizer in the hardhat config file as follows:

module.exports = {
  solidity: {
    version: "0.8.18",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
  },
  networks: {
    ganache: {
      url: "HTTP://127.0.0.1:7545",
      accounts: [
        "0x44ebc40400900aa60d9c00cefd03fc0a5254b33ce8ae2db055bd0ae6f2d58a08",
      ],
    },
  },
};

Alternatively, splitting the contract into multiple contracts may also help and make them more readable to the developer as well.