When I deploy a contract from node.js using the web3 JavaScript API (connected to a locally running geth), and then check the deployed bytecode using eth.getCode(address) (either from the JS console or in node, both connected to a locally running geth), the deployed code sometimes differs from the code that was used when deploying (the former is a trailing substring of the latter, i.e. missing some data at the beginning).

Is this normal? Why does this happen?

The deployed contract works as expected though.

The script used for deploying is something like this:

web3.eth.contract(abi).new({from: addr, data: originalBin, gas: 4700000})

I am deploying a ETH/ETC splitter contract similar to this.

Eg. this bytecode:


got deployed at 0xde8e581f96707add7ebbeb678a0ba36778b96540 as:


Edit: added bytcode examples

  • Can you add examples of bytecodes to the question? Commented Aug 4, 2016 at 14:34

1 Answer 1


Yes, it is normal and the code on the blockchain is always a subset of the compiled (byte)code, because the compiled code includes initialization code. The compiled code is/executes a function which returns the blockchain code, but as part of the execution also initializes the contract being deployed.

For your contract, look at its transaction 1 and you can see the invocation data, the payload and the return value. The compiled code is the payload, and executing it produces the return value.

enter image description here

Related: How can I verify that a contract on the blockchain matches the source code?

To help explain above, the following is for illustration purposes only. Imagine that the blockchain stored JavaScript and that we want to deploy this function:

function hi() { return "hi" }

(Recall that a contract is created by sending a transaction to address 0.) We may think that to do this we would send a transaction with the basic details:

to: 0
data: `function hi() { return "hi" }`

However, that's not how the EVM is specified and the transaction needs to look more like this:

to: 0
`(function() {
    return 'function hi() { return "hi" }';

This shows what's meant by the return bolded above, but to see initialization, it may be clearer to study actual bytecode.

For reference, the specification from the Yellow Paper https://ethereum.github.io/yellowpaper/paper.pdf explains it as:

init: An unlimited size byte array specifying the EVM-code for the account initialisation procedure, formally Ti. init is an EVM-code fragment; it returns the body, a second fragment of code that executes each time the account receives a message call (either through a transaction or due to the internal execution of code). init is executed only once at account creation and gets discarded immediately thereafter.

  • It seems redeploying a contract using bytecode on the blockchain is not possible (assuming ABI is known). If it is possible to reconstruct and redeploy with information already extant on the chain, let me know and I'll open a new question. Commented Oct 5, 2018 at 3:59
  • 1
    @Gviz: I added an illustration to help explain the idea more to others. I think it is worthwhile to ask your question anew.
    – eth
    Commented Oct 6, 2018 at 6:24

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.