0

once a contract is compiled and deployed to the blockchain, it stores the 'runtime bytecode' in the blockchain (as I understand). but to invoke the functions of a contract by an EOA, it requires ABI as an interface. Can anyone please tell me where exactly is the ABI definitions stored? is it also part of the runtime bytecode stored in blockchain?

1

The Abi is not stored in the blockchain, the code should be provided to the users to be able to interact with it. Services like Etherscan allow to verify the code and also allows to download the ABI of a contract trough their API if the contract was verified.

So you need the code or at least the functions names and parameters types of each function. However, If a contract was deployed and the full code is not publically available you should not trust it.

Hope this helps.

  • what about when we call a function of a deployed contract from an EOA ? the bytecode is only a series of bytes-like data. how does it recognize the function signature and what paremeters are passed? – Kombo Jan 6 at 14:01
  • If you are calling this from an app, the app has the ABI. For instance, the wallets that support ERC20 have the ABI of the standard ERC20. Also for instance, in mist, when you call contract functions that you deployed you have previously added the ABI (is a requirement). Without knowledge of the functions definitions, you won't be able to do calls to the contract (unless you are able to read bytecode) – Jaime Jan 6 at 14:16
  • I'm not asking about calling the contract function from another contract leveraging the abi of the called contract. That is pretty obvious that we need to have an abi for it. I'm asking for an EOA to contract function call. how is the function signature of such call deciphered and read from the bytecode ? – Kombo Jan 6 at 14:41
  • For calling a contract from an EOA you need to know the ABI of the contract (function definition). The network doesn't do this for you because the network can't know what function you want to execute unless you specify it, and the way to specify the function that you are targetting is to provide the selector and the parameters of the function. So you need to know this to build a transaction and this can be obtained from the ABI. – Jaime Jan 6 at 15:25
  • Note that my comment about the apps, mist, web3js, etc. is that those tools will help you to build the transaction and then you broadcast it from your EOA. Those tools need to know the function definition of the contract you are targetting to generate the code to be inserted in the field "data" of your transaction. Hope this is clear now. – Jaime Jan 6 at 15:36
0

The ABI is a readable encoded form that describe the smart contract interface behavior.

What in the reality happens is that the EVM manage the calls to the contract using, let’s say, an equivalent of a “mapping” mechanism: you enter one hash key (the famous first four bytes of the true hash of function name and type of parameters) and found the jump to the code to be executed next.

So there is no ABI stored in the contract. At least there is one hash table functionally equivalent to the ABI, but not readable in human language.

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.