0

I use the command "solcjs --bin mycontract.sol" to get the "Binary of the contracts in hex" and it looks like:

enter image description here

It can be used as a parameter of evm in geth after the command "evm --code".

When I use Remix, I get the bytecode in JSON of my contract:

enter image description here

So, what are differences between binary in hex and bytecode of a contract ? What are they used for ?

1

Solc-JS isn't showing you all of the possible outputs of the Solidity compiler.

If instead you install Solc directly and you run:

solc --combined-json bin,opcodes,srcmap basic.sol

You will get an output similar to Remix:

{
    "contracts": {
        "basic.sol:basic": {
            "bin": "60606040523415600e57600080fd5b60848061001c6000396000f300606060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063448f30a3146044575b600080fd5b3415604e57600080fd5b60546056565b005b5600a165627a7a72305820d96f7bce11153f261332a16e2ff0d97fa63117029f5d89bc1bd337a45bf6c7dc0029",
            "opcodes": "PUSH1 0x60 PUSH1 0x40 MSTORE CALLVALUE ISZERO PUSH1 0xE JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH1 0x84 DUP1 PUSH2 0x1C PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN STOP PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0x4 CALLDATASIZE LT PUSH1 0x3F JUMPI PUSH1 0x0 CALLDATALOAD PUSH29 0x100000000000000000000000000000000000000000000000000000000 SWAP1 DIV PUSH4 0xFFFFFFFF AND DUP1 PUSH4 0x448F30A3 EQ PUSH1 0x44 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST CALLVALUE ISZERO PUSH1 0x4E JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH1 0x54 PUSH1 0x56 JUMP JUMPDEST STOP JUMPDEST JUMP STOP LOG1 PUSH6 0x627A7A723058 KECCAK256 0xd9 PUSH16 0x7BCE11153F261332A16E2FF0D97FA631 OR MUL SWAP16 0x5d DUP10 0xbc SHL 0xd3 CALLDATACOPY LOG4 JUMPDEST 0xf6 0xc7 0xdc STOP 0x29 ",
            "srcmap": "28:53:0:-;;;;;;;;;;;;;;;;;"
        }
    },
    "sourceList": [
        "basic.sol"
    ],
    "version": "0.4.21+commit.dfe3193c.Windows.msvc"
}

bin is compiled binary of the contract, same as the --bin output from solcjs. There may be some differences based on the compiler version, compiler settings, and contract metadata, but otherwise you should get an exact match.

The binary can also be represented by a more "human readable" set of instructions which is called the opcode. The bin and the opcode contain the exact same data, just parsed in two different ways.

I am less familiar with the Source Mappings (srcmap), but it looks like it is mostly used for analysis and debugging purposes.

Ultimately, when you deploy a contract, only the bin is used. The other outputs from Remix are made available for convenience, but do not actually represent anything happening on the blockchain.

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.