I am looking to get some already deployed code working for myself.

With ethers.js I can get the bytecode in the following way

ethers.getCode("CONTRACT ADDRESS")

However, this is a deployedBytecode and some code is missing, such as the constructor. This means that you cannot run it by yourself.

i )Is there any way to get the creation bytecode?

ii)If not, is there any way to run getContractFactory with deployedBytecode?


1 Answer 1


Unfortunately, there's no straightforward way to get the creation bytecode of a contract through an RPC call or similar. But:

  • Verified contracts have the creation bytecode on Etherscan https://etherscan.io/token/0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85#code

  • If the contract deployed by an EOA and not a factory, you can look at the input data of the transaction that created the contract. For example you can see on Etherscan the contract 0xcc7bb2d219a0fc08033e130629c2b854b7ba9195 on Goerli was created with the tx 0xa1762c05ddc58e0164bec6c270cc0f69d8d4d27e78d714b9c40bfa130c88a7a3. If you look at the "Input Data" field, you'll see the creation code (starting with 0x608060) and the constructor arguments. Executing this code will result in deploying the contract with the runtime bytecode. There's no RPC call to get the tx that created a contract, you'll need a block explorer or a different index.

  • If you have the source code of the contract and the compiler settings, you can recompile the code and access the creation bytecode from the compiler outputs.

Your Answer

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

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