Sep 29 , 2020
What are Ethereum Transactions?
Transaction Types and Data Model
Understanding the anatomy of a transaction is pivotal for success in Ethereum development.
Transaction Data Model
- Nonce: Transaction counter of the sender
- Gas Price: Price paid per unit of gas
- Gas Limit: Maximum gas provided for the transaction
- To: Recipient address or contract address
- Value: Amount of ether sent in the transaction
- Data: Input data for contract transactions
- v, r, s: Components of the transaction signature
Example:
Types of Transactions
Value Transfer
- Gas Limit: Typically 21,000
- Description: Transfer ether from one account to another.
- Details: Doesn't modify the blockchain's state. Recipients can be Externally Owned Accounts (EOA) or Contracts.
Contract Deployment
- Description: Deploy a new smart contract onto the blockchain.
- Details: Requires transaction data to contain the bytecode of the contract being deployed.
Function Call
- Description: Invoke a function within a deployed contract.
- Details: Can modify the state of the blockchain. These transaction types and their associated data models are crucial for executing different operations on the Ethereum blockchain, managing smart contracts, and transferring ether between accounts.
ABI Encoding
- To encode function calls to send to smart contracts, expecting those smart contract to interpret that message and consequently run the code you want.
- Account to Contract
- Contract to Contract
- Contract can call other contracts in 2 ways: a) A.foo(x, y, z) b) use the low-level call (not recommended)
Caller:
- mutable arguments
- encode arguments
- what are callee's apis?
a) The Function Signature
b) The Function Selector
- first 4 bytes of function signature
- how to get?
- The first 4 bytes returned from abi.encodeWithSignature(....) is the function selector.
Callee:
- immutable calldata
- decode calldata
- how can caller call me? a) The Function Selector b) The Function Arguments