I started creating a solidity smart contract to serve almost as both BD and Backend service. Everything was ok until I got a warning saying my contract had too many bytes.. was too big (refering to this EIP). I didn't even had half of my contract done. So I started thinking of a way I could avoid this.. and had the idea to store all my requirements data structure in one single variable (string I suppose) in the form of base64. Meaning that on my contract, there would always just be store the full object in a base64 string form. On a front end I would have to guarantee that my variable gets decoded to read, and coded again to write/update. My question is... is this a bad idea? Is this a thing people often do?
1 Answer
Too many bytes means that the bytecode (compilation output) of your contract is too large.
Ethereum specifically, it means larger than 24K bytes (48K hexadecimal characters).
The size of your global data structure does not affect the size of your bytecode (let alone the fact that you're only changing its format, which wouldn't make it any smaller anyway).
My suggestion for you would be to split the contract into several contracts.
-
that was definitively helpful. So, If I split the contract in many, doesn't it affect my outputted Bytecode? Say I have a Contract Main, that imports Contract A,B,C,D and uses them like if they were "objects". Bytecode generated from Main compilation wouldn't vary according to the contracts it imports/uses? Commented Mar 1, 2020 at 20:22
-
@tp_maiste: Only if you do
x = new A(...)
inside the main contract. If you instantiateA
outside the main contract, and then just pass its address to the constructor of the main contract, then the bytecode of the main contract does not include the bytecode ofA
. Commented Mar 1, 2020 at 21:27