I have trouble deploying a contract to the main network and I believe this is due to high gas consumption.
An earlier version of the contract worked on the main network. The current version works in my private testnet (created with geth --dev
).
On the testnet these contract creations use about 2.4 million units of gas. I tried to deploy it on the main net with 2 million gas at first and got an out of gas exception (TA got mined though, contract creation just was not successful).
After that I tried it with 3 million and got this (not mined):
"{"jsonrpc":"2.0","error":{"code":-32010,"message":"Transaction cost exceeds current gas limit. Limit: 2200000, got: 3000000. Try decreasing supplied gas.","data":null},"id":1}[\n]"
I am completely stuck and have no idea how I can deploy my contract now. Mainly I have two questions:
- Why can I send a TA with 2.4 million gas to the testnet but not to the main-net. I know they are different chains, but shouldn't it use the same logic for TA-validation? How can I send TAs with 3mill gas limit to the main network?
- I don't understand why my contract requires this much gas. It's only 264 lines of code. It's three mappings, two structs, five enums, one event and a few relatively simple functions. How can I figure out which part of my contract is using up so much gas? Is there a tool for that?