I'm working on a Dapp for voting in a municipality and national election. There is a lot of code, and I've met the max limit of the contract size many times but have been able to keep it under the limit by cutting down functions, compress requires error text, move internal functions inline, and other small fixes to reduce size. But now, even if I do everything as efficiently as possible, I still go over the limit, and I'm not done with the Dapp yet. I've used this doc to reduce size: "https://ethereum.org/en/developers/tutorials/downsizing-contracts-to-fight-the-contract-size-limit/#remove-functions" I'm now looking into splitting the contracts into smaller contracts or making a library, but splitting the contracts into smaller ones OR creating a library, still gives the same problem when migrating in truffle. I've read that when using a library, I should avoid internal functions because they are included in the main contract instead of being used from the outside.

If you want to look at my code, check out our repo here: "https://github.com/voljumet/ChainVote/tree/libbie-1" (we have commented out some of the functions to be able to migrate)

Edit: The question: how to use a library, and if I'm doing it correctly, is there something with testing it in truffle that causes the contract to exceed the maximum size?

  • What's the question? – Ismael Apr 8 at 22:59
  • 1
    added the question at the end – Rune Alexander Laursen Apr 9 at 11:58
  • A few tips for space reduction: 1/ Replace string with bytes32 (for small or constant strings), 2/ Use SafeMath only with user input, for small numbers under your control it adds gas unnecessarily. To ensure a function from a library wont be inline mark them as external. – Ismael Apr 13 at 13:34
  • Thanks, but I still cant lower the cost even if I make them external. But removed some SafeMath and got a little bit of reduction – Rune Alexander Laursen Apr 14 at 20:09

Your Answer

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

Browse other questions tagged or ask your own question.