Is there a solution to recover the complete bytecode (init + runtime) of a contract imported in solidity. For example "bytes code = getBytecode (Escrow.sol)" and this would be replaced by bytecode during compilation? thanks a lot for your help


Surely it is immediate using Remix. Just a click on “detail”, then “bytecode”

  • Thank you for your answer. but I'm looking for something automatic in the code of solidity. for example in solidity when you do "new Escrow ()" you do not need to give the bytecode. the problem is that "new" will deploy the contract whereas I just want the bytecode. – Zoulg Jan 12 '19 at 10:07

This is possible at build time, but you will need custom tools for this.

Lets assume you want to use byte code of contract A inside contract B.

At first compile contract A into byte code. So you will have file A.bin. Lets assume contents of this file is 0x6060604052604080519081....

Then you need to write a code that will take this byte code and convert it into Solidity file A_bin.sol looking like this:

pragma solidity 0.5.7;

contract A_bin {
  bytes internal constant A_bytecode = abi.encodePacked(
    uint8 (0x60), uint8 (0x60), uint8 (0x60), uint8 (0x40),
    uint8 (0x52), uint8 (0x60), uint8 (0x40), uint8 (0x80),
    uint8 (0x51), uint8 (0x90), uint8 (0x81), ...);

You may write such code in Javascript of Python or whatever language you prefer.

Now in contract B you may include A_bin.sol, inherit contract B from A_bin and use A_bytecode where needed.

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.