I have two questions regarding the ABI.
1. When does it happen?
A digital signature is made by creating a transaction data structure, RLP-encoded serializing the data, hashing it through keccak-256, and signing it with ECDSA using a private key. At which point does ABI-encoding happen?
2. What does it encode?
Does ABI-encoding only happen for the contract method invoking data or also for things like the value, nonce, etc? If latter, does that mean the transaction parameters get RLP-encoded AND ABI-encoded?
Best Answer
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 thedata
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 rawbytes
which are then put into thedata
field of the transaction.The whole flow :
Sender :
data
field of transactionto
,value
andnonce
After travelling through some wires...
Receiver/Node :
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.