0

The JSON formatted ABI's have data that is not part of standard solidity ABI encoding and not necessary for interaction with contracts (EVM bytecode). The standard ABI just requires the first (left, high-order in big-endian) four bytes of the Keccak-256 hash of the signature of the function.

What is the primary reason for having this additional data, such as return types, events and mutability in the JSON files? (Is it for the UI/wallet to show and compute additional info?)

Example

// -- snippet --

  "outputs": [
    {
      "internalType": "bytes4",
      "name": "",
      "type": "bytes4"
    }
  ],
  "stateMutability": "nonpayable",
  "type": "function"
1

All the fields in the ABI are needed to generate contract bindings automatically. After you deploy your contract you would need to interact with it. How would you do this if you don't have a full description of the contract? That's why the ABI file is needed with all its property fields.

Official Ethereum sources have automatic contract bindings generation, a tool that will automatically produce a (sort of) "client" for your contract, it is called abigen , you can find more info about here:

https://github.com/ethereum/go-ethereum/tree/master/cmd/abigen

So for example the type property is used distinguish which signature belongs to function and which to event , so abigen generates event listening client code for the events declarted in your contract.

5
  • Thanks. So why can't I interact with the contract if I dont know the return value? The return value is used on-chain, but not used in a web3-frontend. I can see that a client like geth needs to know how to deal with events, but what about the frontend?
    – Marcellvs
    Aug 14 '21 at 21:36
  • @Marcellvs to interact with the contract you don't need the return value, you need the input value, i.e. the tx.Data() assembled for the contract so it can understand what to do. One example when the return value is used it is in debug.traceTransaction() RPC method, I am not sure about javascript's web3 , I am not using it at all. I am using RPC methods via HTTP or Webservice
    – Nulik
    Aug 14 '21 at 22:25
  • Yes so my question revolved around why the return values are part of the JSON ABI but not part of the solidity ABI. Is that for frontends to have more information than is required by the bytecode?
    – Marcellvs
    Aug 15 '21 at 9:14
  • @Marcellvs there is no two ABI standards, the ABI standard is single.
    – Nulik
    Aug 15 '21 at 13:01
  • There is not one single ABI. > Note: the ABI is an abstraction that is not part of the core Ethereum protocol. Anyone can define their own ABI for their contracts, and any callers of such contracts would have to comply with that ABI to get meaningful results.
    – Marcellvs
    Aug 18 '21 at 10:09

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.