Can some recommend a way to save gas fees?

  1. a = a + 1;
  2. a++;

I heard about this; Pack struct tightly

Mine looks like this. I am not sure about size of address, ENUM variables and array without length. Please advice me or give me some reference links.

    enum TokenType {A, B, C}

    enum SwapType {AA, BB}

    struct A {
        address[] a;
        uint256[] b;
        TokenType[] c;
        address d;
        uint256 e;

    struct B {
        uint256 a;
        uint256 b;
        bool c;
        uint256 d;
        uint256 e;
        bool f;
        mapping(address => bool) g;
        SwapType h;
        Collection i;
        Collection j;

And what is the best way for accessing struct mapping variables? I am using a lot of gas fees because I have struct B mapping, inside that, I have 2 struct objects, inside that object, I have 2 arrays.

Another question is, I heard functions orders in contract are affecting gas fees. Do function parameter orders affect gas fees as well?


1 Answer 1


With the increased gas price and the increased ETH price nowdays you can see more and more developers trying to optimize their smart contracts as much as they can to reduce tx costs. I wrote this article about saving transactions costs about 2 years ago, but I do still believe it is valid even now. Check it out.

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