1

I have a factory contract that deploys child contracts, to complete a challenge on Ethernauts. I would like to retrieve the deployment bytecode for one of the child contracts, but I'm having trouble finding it.

I've looked up the child contract address on Etherscan, but it only shows the runtime bytecode. I've also tried using the getCode function in Web3 to retrieve the bytecode, but that also returns the runtime bytecode.

Is there any way to retrieve the deployment bytecode for a contract that was created from a factory? Or is the deployment bytecode lost once the contract is deployed?

2 Answers 2

1

Afaiak the deployment bytecode won't be stored on the blockchain as by deployment only he runtime code will be copied.

I am not 100% sure, but as the factory contract is copying the runtime code of an implementation, I would guess that the deployment code in this case is the runtime code itself.

Please correct me with comments if I am working!

1
  • Thanks, that is generally my thoughts as well, though you could pass constructor arguments into the Factor which would change the deployment bytecode, so it cannot be verbatim in the runtime code. If I have a full archive node, I'm wondering if there are some commands to find it.
    – Danny B
    Feb 26, 2023 at 17:51
0

If you can get the full trace of the transaction from which the child contract was created, it should be the data in the frame where the to address is either the Zero Address or null.

There's also a specific JSON-RPC call for this called getTransactionByHash

Alternatively, you could deploy a contract which fetches type(TARGET_CONTRACT).creationCode and returns it.

This helped me find some of these methods.

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.