0

I have a contract deployed both in test and main network and if i execute same method with same parameters, will gas used differ?

Madan
  • 65
  • 5

2 Answers2

1

Yes, generally.

More precisely, there are three variables in play to make sure we don't get overconfident.

The obvious one is the different state. I would stress that a well-designed contract will not have any functions that vary wildly ... that is, the logic should be guaranteed to finish under a certain maximum cost. Unbounded iteration and recursion is an anti-pattern. If one follows that principle, then it shouldn't matter (that much) that are different states on different networks.

The next one is the compiler version. You should get the same bytecode from the same contract and compiler every time, so just be careful not to stray from that as you hop from network to network.

The last one is the gas cost for each operation. Those operations are spelled out in the bytecode, but the cost of each operation so specified is a property of the protocol. In fact, if hardware and other constraints change sufficiently to warrant a change in the price list, then implementation requires a fork. That means it's conceivable for different networks to be running different generations of the protocol and therefore compute slightly different gas costs to run the same transaction when everything else is equal.

Hope it helps.

Rob Hitchens
  • 55,151
  • 11
  • 89
  • 145
0

It's a bit unclear what you're asking but the same contract deployed on a different network will not be identical.

The bytecode will be identical but the state will not be. Depending on the computations your methods are doing it's going to cost different gas.

TLDR; Yes, it will consume different gas