Given an address (in server-side javascript), is there a way to check that the address is an instance of a specific smart contract?

I've tried using


for a recently deployed contract, but this gives me slightly different bytecode (ie same prefix and postfix with some similar stuff in between) than what was used to deploy it. Am I missing something, or is there another way to do this?

  • 1
    But presumably if you deploy the contract again and call getCode on that address, you get the same bytecode as the first deployment. – user19510 Apr 23 '18 at 15:35

If you want you solidity compiler solc to return the bytecode that will be placed on an address, you need to compile using the argument --bin-runtime instead of --bin.

So to check that the code placed on an address represents the source code in question, you need to compare what is returned by web3.eth.getCode(addr) with the output of solc -o outputDirectory --bin-runtime sourceFile.sol.

The reason for this is that --bin-runtime will contain the bytecode that is placed on the blockchain whereas --bin will contain the bytecode that is placed on the blockchain plus the code that is needed to actually place the code on the blockchain, i.e. the constructor. For an in-depth explanation, have a look at: solc bin vs. bin-runtime


If you use a factory to deploy instances of the contract, then the factory can be an authoritative registry and remove all doubt.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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