So I'd need something like the GetCode.at(address) function presented in the official doc: https://solidity.readthedocs.io/en/v0.5.0/assembly.html#example but which allows me to deploy that contract in a new address. Is it possible to get the deploy bytecode or rebuild it from the runtime one with solidity?


You can get the raw bytecode and try to redeploy with a new transaction. Set the "data" part of the transaction to the existing bytecode and submit. You can submit using MetaMask (if you're using web3) or even using the geth console. Lots of articles out there on how to do that.

I'm guessing you have the source code or the ABI somewhere? Otherwise, you won't be able to call the contract's functions.


The .getCode() method only returns you the deployed bytecode. What you want is the data that was sent alongside the transaction that deployed the contract. Etherscan gives you a link to the deploying transaction.

For instance, for this contract, the deployment took place here. So that's the bytecode that will deploy a new contract.

Keep in mind that the longer bytecode also contains the constructor parameters towards the end. So if you want to deploy by hand, don't forget to update those too.

  • Hey thanks, I know, but as I said, I need to do it in solidity. I guess is not possible. – Gonzalo Balabasquer Nov 17 '18 at 0:54
  • There is a way in assembly { to get the deployed code of a contract. To deploy it at another address, you would have to prepend it with the constructor and append it with the constructor arguments. So in effect you need some prior knowledge of how this specific other contract was deployed. – Xavier Leprêtre B9lab Nov 17 '18 at 11:12

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.