is it possbile to get bytecode of already deployed contract on another contract?

example : get bytecode of contract A using contract B (using solidity )


Yes, this is possible using assembly, you can get the code of any contract. The code below do just that (from the docs

function at(address _addr) public view returns (bytes o_code) {
        assembly {
            // retrieve the size of the code, this needs assembly
            let size := extcodesize(_addr)
            // allocate output byte array - this could also be done without assembly
            // by using o_code = new bytes(size)
            o_code := mload(0x40)
            // new "memory end" including padding
            mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f))))
            // store length in memory
            mstore(o_code, size)
            // actually retrieve the code, this needs assembly
            extcodecopy(_addr, add(o_code, 0x20), 0, size)

This can also work:

> eth.getCode("CONTRACT ADDRESS")


After getting the Byte code, remove the "0x" at the beginning and then use this Solidity decompiler, https://ethervm.io/decompile, to decompile the bytecode.

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.