sunwarr10r
sunwarr10r

Reputation: 4787

Ethereum: How to deploy slightly bigger smart contracts?

How can I deploy large smart contracts? I tried it on Kovan and Ropsten and have issues with both. I have 250 lines of code + all the ERCBasic and Standard files imported.

The size of the compiled bin file is 23kB. Did anybody experience similar problems with this size of contracts?

UPDATE:

It is possible to decrease the compiled contract size by doing the compilation as follows:

solc filename.sol --optimize

In my case it turned 23kB in about 10kB

Upvotes: 2

Views: 1200

Answers (2)

mudgen
mudgen

Reputation: 7403

It is possible to get around the max contract size limitation by implementing the Transparent Contract Standard: https://github.com/ethereum/EIPs/issues/1538

Upvotes: 1

Adam Kipnis
Adam Kipnis

Reputation: 10981

Like everything else in Ethereum, limits are imposed by the gas consumed for your transaction. While there is no exact size limit there is a block gas limit and the amount of gas you provide has to be within that limit.

When you deploy a contract, there is an intrinsic gas cost, the cost of the constructor execution, and the cost of storing the bytecode. The intrinsic gas cost is static, but the other two are not. The more gas consumed in your constructor, the less is available for storage. Usually, there is not a lot of logic within a constructor and the vast majority of gas consumed will be based on the size of the contract. I'm just adding that point here to illustrate that it is not an exact contract size limit.

Easily, the bulk of the gas consumption comes from storing your contract bytecode on the blockchain. The Ethereum Yellowpaper (see page 9) dictates that the cost for storing the contract is

cost = Gcodedeposit * o

where o is the size (in bytes) of the optimized contract bytecode and Gcodedeposit is 200 gas/byte.

If your bytecode is 23kB, then your cost will be ~4.6M gas. Add that to the intrinsic gas costs and the cost of the constructor execution, you are probably getting close the block gas size limits.

To avoid this problem, you need to break down your contracts into libraries/split contracts, remove duplicate logic, remove non-critical functions, etc.

For some more low level examples of deployment cost, see this answer and review this useful article on Hackernoon.

Upvotes: 3

Related Questions