How can I get solidity file bytecode similar to etherscan? #2318
-
I'm trying to use a tool that takes in the bytecode of the smart contract by pulling it from etherscan.io using its address. slither = Slither(contract_file)
for contract in slither.contracts:
if contract.functions:
print(contract.name)
bytecode_init = contract.file_scope.bytecode_init(contract.compilation_unit.crytic_compile_compilation_unit, contract.name)
print(bytecode_init)
bytecode_runtime = contract.file_scope.bytecode_runtime(contract.compilation_unit.crytic_compile_compilation_unit, contract.name)
print(bytecode_runtime) This is all I could find after looking at the source code, the problem is the functions bytecode_init and bytecode_runtime are only available to output the bytecode of a single contract/component at a time.
I assumed it might have been some sort of concatenation with minor differences for metadata at the start (e.g.: https://ethereum.stackexchange.com/questions/94115/cannot-verify-contract-bytecode-has-small-difference), but searching random bytecode strings and trying to find them (from my output to etherscan and vice versa) it seems like they're just different. I also just tried using solc (I realize Slither uses solc),
Ownable.bin
For the Slither and solc attempts I made sure to use the same solc version 0.8.23, and querying the version after setting it confirmed the same commit as the one on etherscan (though with the addition of This isn't really a Slither issue, but I'm out of my depth here, and was hoping I could get some help on how I can get a similar bytecode output to etherscan by asking here. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I overlooked the fact that the example I picked on etherscan had |
Beta Was this translation helpful? Give feedback.
I overlooked the fact that the example I picked on etherscan had
Optimization Enabled: Yes with 200 runs
, once I did thatsolc --optimize --optimize-runs=200 --bin contract.sol -o contract_out
, I got my SORA contract output to match (mostly, excluding what I assume is metadata) the bytecode on etherscan. It's also clear now the bytecode shown is of the specific contract that was deployed (of which there can only be one), which is also shown byContract Name: SORA
on etherscan. That's it, answer found.