2

Suppose I have a contract like

pragma solidity ^0.8.17;

contract MyContract {
    constructor(string arg1, uint arg2) {
        ...
    }    
    ...
}

When I compile the solidity contract (actually I'm using hardhat), we get an artifact file like artifacts/contracts/MyContract.sol/MyContract.json, which includes bytecode and deployedBytecode fields. What are the differences?

I've googled and found some docs but its not yet clear, especially because bytecode and deployedBytecode are generated without constructor parameters.

  • the concatenation of bytecode and consctuctor parameters are send in the deployed transaction?
  • the byte code of the deployed stored on Ethereum is deployedBytecode and constructor parameters?

2 Answers 2

4

According to hardhat document : deployedBytecode: A "0x"-prefixed hex string of the unlinked runtime/deployed bytecode. If the contract is not deployable, this has the string "0x". It means deployed bytecode is runtime bytecode.

  1. What is the difference : the initialize code and its parameters: and boostrap the contract runtime bytecode and its initial environment (e.g. state storages, including running the constructor logic).
  2. Yes encoded params are appended to the end of bytecode. Read more: https://docs.blockscout.com/for-users/abi-encoded-constructor-arguments
  3. deployedBytecode or runtime bytecode is what you see on etherscan or when you query eth_getCode using ethereum node's RPC: Does "eth_getCode" return the init bytecode or the deployed bytecode?

Hope the above helps, you can read more about that here Difference between bytecode and runtime bytecode

0

After reading the answers and links, now I understand better.

  • Input data of deploy transaction = bytecode + constructor params
  • runtime bytecode = deployedBytecode = return of getCode

(where bytecode and deployedBytecode are found in the artifact JSON file)

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.