Understanding Ethereum Transaction Architecture
Ethereum transactions form the backbone of blockchain operations, enabling value transfers and smart contract interactions. Let's dissect their core components.
Transaction Structure Breakdown
1. Transaction Object Anatomy
Defined in core/types/transaction.go, the Transaction struct contains:
type Transaction struct {
data txdata // Core transaction data
hash atomic.Value // Cryptographic hash cache
size atomic.Value // Size measurement cache
from atomic.Value // Sender address cache
}Key elements:
- data: Core payload (txdata type)
- hash: Keccak256 hash of RLP-encoded transaction data
- from: Derived sender address
2. txdata Composition
type txdata struct {
AccountNonce uint64 // Transaction sequence number
Price *big.Int // Gas price (wei)
GasLimit uint64 // Maximum gas allowance
Recipient *common.Address // Recipient address (nil for contract creation)
Amount *big.Int // Ether value (wei)
Payload []byte // Smart contract data
V, R, S *big.Int // ECDSA signature components
Hash *common.Hash // Transaction hash cache
}Critical fields:
- Nonce: Anti-replay counter
- GasPrice: Willingness to pay per computation
- GasLimit: Maximum computational budget
- Payload: Contains contract bytecode or method calls
Transaction Types Demystified
1. Value Transfer Transactions
Basic ETH transfers between accounts:
- Requires
toaddress andvalue - Empty
datafield
2. Contract Creation Transactions
Deploys new smart contracts:
tofield remains empty- Contract bytecode in
datafield
3. Contract Execution Transactions
Invokes existing contract methods:
tofield specifies contract addressdataencodes method calls and parameters
๐ Master Ethereum transaction types
Transaction Lifecycle
Creation Process
SendTxArgs struct (in internal/ethapi/api.go) defines submission parameters:
type SendTxArgs struct {
From common.Address // Sender address
To *common.Address // Optional recipient
Gas *hexutil.Uint64 // Gas limit
GasPrice *hexutil.Big // Gas price
Value *hexutil.Big // Ether amount
Nonce *hexutil.Uint64 // Sequence number
Data *hexutil.Bytes // Contract payload
}Execution Phases
Virtual Machine Externals
Pre-Checks:
- Nonce validation
- Gas requirements verification
Gas Handling:
- Deduct gas costs from sender
- Calculate intrinsic gas costs
EVM Processing:
- Contract creation (
Create()) - Method execution (
Call())
- Contract creation (
Post-Execution:
- Gas refund calculations
- Miner rewards distribution
Virtual Machine Internals
EVM processes:
- Value transfers through
Context.Transfer() Smart contract operations via:
Interpreterfor bytecode executionStateDBfor state management
Transaction Storage Mechanism
Database Operations
- Storage Function:
WriteTXLookupEntries()incore/database_util.go - Key Structure:
txPrefix + transactionHash Value Structure: RLP-encoded
txLookupEntrycontaining:- Block hash
- Block number
- Transaction index
Storage Triggers
- Activated during
WriteBlockAndState() - Processed by miner's worker routine
๐ Explore Ethereum storage deep-dive
Frequently Asked Questions
What determines Ethereum transaction costs?
Transaction costs = GasUsed ร GasPrice. GasUsed depends on computation complexity, while GasPrice reflects market demand.
Why are nonces important in transactions?
Nonces prevent:
- Transaction replays
- Double-spending attempts
- Out-of-order execution
How are contract creation transactions different?
They:
- Have empty recipient fields
- Contain bytecode in payload
- Result in new contract addresses
What's the maximum data size per transaction?
Ethereum enforces a 44KB data limit per transaction.
How are sender addresses verified?
Through ECDSA signature recovery from V, R, S components, converting the public key to an Ethereum address.
Why do transactions include gas limits?
To:
- Prevent infinite loops
- Cap computation costs
- Protect against malformed contracts