The reason why geth refuses to send the transaction is because the block gas limit varies. On a private testnet, it can be anything, but by default it'll be 5.5 million. On the mainnet, it's currently only 2 million--so a 3 million gas transaction just wouldn't fit at all. This is because of the recent spam attacks on the network--the developers asked miners to reduce the limit, and they did. Hopefully, the miners will increase it back to the default after the incoming hardfork. (I say "hopefully" because it's the miners' decision, the devs can only suggest.)
The only things that use gas at creation time are what happens in the constructor, and the size of the compiled code itself. You might be able to reduce the size by turning on the optimizer, but it's quite possible it's already on.
I'm not that surprised at the figure it's giving, though. 264 LoC is actually a lot in Ethereum. I have a 400~ LoC contract that is 3~ million gas optimized.
There's three ways of reducing gas cost:
- Simplify the contract. This might be impossible, depending on what exactly you're doing.
- Split it into multiple contracts.
- Refactor it to use libraries. If you're using lots of structs and mappings, this may make your code remarkably more readable.
The simplest way may be just to wait. You're not the only one who is stuck with big contracts, so the miners have an incentive to raise the gas limit again, and soon.
Best Answer
The most optimized version:
Update for Solidity 0.6.x: