The maximum number of bytes smart contract
In the Solidity, EIP 170 to contract the maximum size is limited to 24 KB. Therefore, if the smart contract terms too much will lead to not publish operation.
The method of reducing the number of compressed bytes
Method and variable naming
To a certain extent, method or variable length will affect how much the number of bytes, and therefore can be compressed by reducing the contents of name or variable name, but the effect is generally small, after all method and variable names themselves footprint limited.
Reduce variable definitions members
If a value is used only once or twice, then minimize and then create a separate variable, the more variable, compiled more Number of Bytes, this can reduce the size of the lot compiled.
Variable initialization
Variables explicitly initialized only consumes Gas, will increase the compiled byte code, it is possible to use the default value that is the default value.
Avoid duplication check
Some values in the business around and do the appropriate checks, and there is no need to repeat the examination, such code to reduce the number of bytes compiled effectively reduced.
Define constants
1e18 such values such as, multiple use, must define constants, write directly cause the compiled byte code becomes long, this way can effectively reduce the number of byte codes.
Reduce public property
Calling methods provides the corresponding default attributes after compiling public therefore unnecessary to set the interior of the public property, the method can be reduced corresponding to bytes.
Use short string of reasons
Revert or other reason require simplified description string.
Single-line exchange
Solidity variable value can be exchanged in a single statement. Thereby avoiding temporary definition of intermediate variables.
(result[i], result[j]) = (result[j], result[i])
Typical applications of the above scenario is written bubble sort, the position needs to be exchanged when two values in the array, can be obtained by writing the above, the definition of intermediate variables reduced.
Using the event with mention storage
Some data do not need to be stored on the block chain, waste of resources, information can be logged by the event.
Using the library to save some of the bytecode
Public library function will not be part of a smart contract, so you can calculate the number of write operations to a public library inside, and then make the appropriate access by authorized.