How does etherscan get blockchain compiled code?

621 Views Asked by At

I'm working on an ethereum explorer, I would like to know how does etherscan get the Contract source code, ABI and how they parse the transaction input hexa into contract's function?

Thanks in advance

1

There are 1 best solutions below

1
On

Contract developers (maintainers, or basically anyone) can publish the code on https://etherscan.io/verifyContract

When you're publishing the contract on Etherscan, they ask you for the actual source code and compilation parameters such as used language (e.g. Solidity or Vyper), compiler version (e.g. 0.8.4), optimization settings and few other details.

Then Etherscan compiles the provided code with the provided params and if the (now compiled) bytecode matches the bytecode on blockchain, it publishes the source code.


ABI JSON is one of the returned values from the compilation process - along with the actual bytecode, list of opcodes, array of errors, etc.

As for the transaction input hex: They use a dictionary of function signatures that translate to the actual function definitions (including argument datatypes). You can find more info about ABI-encoding function signatures and arguments passed to functions in this other answer.