I have a use case where I want to whitelist some smart contracts in one Base contract.

The condition for whitelisting is that smart contract should have been deployed using the same code that was shared through my system.

Now, to validate this I want to get the entire hex-code that was used to deploy a smart contract, given that we just have the smart contract address. I want to get this information through solidity so that it can be used in a different smart contract.

I tried to get the variable msg.data, during the contract deployment, but it seems like that does not give the full hex-code, rather it gives just the code for the executed function.

1 Answer 1


You can do this with Solidity Assembly. There is also an example for this --> library GetCode


To compare the code, you could hash the bytes and compare the hashes with each other.

  • 3
    Note that this will get you the bytecode that's currently stored at that address. It does not give you the deployment payload (which includes the constructor and its parameters). This may be fine for this particular use case. I just wanted to point it out.
    – user19510
    Commented Feb 11, 2018 at 22:05
  • The posted answer would be incorrect in some cases, as it does not include constructor params. In the end, I changed my application logic to control this by having one Deployer contract, that is just used to deploy contracts. This Deployer contract also marks the newly created contract as "whitelisted" in the Base Contract. Only deployer contract is allowed to add an address to whitelist. This helps me keep track of whitelisted contracts, and I can be sure that wallet contains the expected code.
    – Manu
    Commented Mar 29, 2018 at 10:00
  • @Manu This sounds like a good solution.
    – ivicaa
    Commented Mar 29, 2018 at 10:25

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.