0

I'm trying to figure out how to calculate the size of the bytecode given the string, given that there is a hard limit for contract size of 24kb.

ie. for USDT Token: https://etherscan.io/token/0xdac17f958d2ee523a2206206994597c13d831ec7#code

606060405260008060146101000a81548160ff021916908315150217
9055506000600355600060045534156200003457600080fd5b604051
62002d7c38038062002d7c8339810160405280805190602001909190
80518201919060200180518201919060200180519060200190919050
50336000806101000a81548173ffffffffffffffffffffffffffffff
ffffffffff021916908373ffffffffffffffffffffffffffffffffff
ffffff16021790555083600181905550826007908051906020019062
0000cf9291906200017a565b508160089080519060200190620000e8
9291906200017a565b508060098190555083600260008....

Is it literally byte[] all = new byte[s.length() / 2] - number of characters in the string divided by 2? or it is something more complicated?

3
  • 1
    Does this answer your question? How to check the size of a contract in Solidity? Sep 28, 2022 at 7:23
  • no. I'm asking about the actual string of the bytecode already deployed.
    – zcaudate
    Sep 28, 2022 at 13:18
  • 1
    More details about the limit ethereum.stackexchange.com/a/47556. And you are correct the contract will be deployed as raw bytes, so the deployed size will be hexadecimal lengths / 2. Also be aware that the compiler produces two bytecodes, the runtime and the deployment = runtime + constructor.
    – Ismael
    Oct 5, 2022 at 21:34

1 Answer 1

0

You can take a look at this resource on how to figure out the size of the bytecode from compiler output.

See:

How to check the size of a contract in Solidity?

How to estimate my contract code size? it is too big to deploy now

1
  • I'm looking at a simpler solution if the hex string is already available.
    – zcaudate
    Sep 28, 2022 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.