The ABI or the Application Binary Interface is the standard to interact with the contracts. EVM uses the ABI encoded data to understand which part of the bytecode to execute.
When does it happen?
A contract interaction is just another transaction on ethereum. The payload/what-to-do is in the
data field of the transaction. ABI encoding encodes the user's parameters and function signature. Then you put this in the
data field of the transaction. And then you sign the transaction as proof of ownership. Then the whole transaction data is RLP encoded.
What does it encode?
ABI encoding is used only in contract interactions. It is used to compute the
keccak256 hash of the target function selector and then the arguments you want to supply. The process returns raw
bytes which are then put into the
data field of the transaction.
The whole flow :
- Decide which function to execute at a contract address
- ABI encode function selector and arguments
- Put the ABI encoder's output raw bytes in the
data field of transaction
- Put all the other values,
- RLP encode these fields
- Sign the transaction
- Again RLP encode it and send
After travelling through some wires...
- RLP decode the received transaction
- Verify if valid by checking the signature
- RLP decode
- Execute! (EVM internally handles the ABI decode and execution)
RLP encoding is the protocol used to communicate over channels i.e your mobile's data or Ethernet or etc.., it is the low level method used to convert data before sending through transmission. Aside from Ethereum, you can also use RLP encoding for something like Mobile communication. It's just another protocol.