What Are Transactions and Messages?
Transactions and messages are two fundamental yet distinct concepts in the Ethereum ecosystem. While they share similarities in structure, their purposes differ significantly. This guide explores transactions, messages, and message calls, clarifying their roles and differences.
Understanding Transactions
A transaction is a signed piece of data from an external actor (e.g., a user) sent to the Ethereum network. It facilitates the transfer of value or data between accounts or triggers contract creation. Ethereum supports two transaction types:
- Message-Calling Transactions: Invoke contract functions.
- Contract-Creation Transactions: Deploy new smart contracts.
Key Components of a Transaction
- Recipient address: Target account or contract.
- Sender signature: Validates the transaction origin.
- Value: Amount of Ether transferred (in wei).
- Optional data field: Additional input for contracts.
- STARTGAS: Gas limit for execution.
- GASPRICE: Fee per gas unit (in wei).
Transaction Fields (Per Ethereum Yellow Paper)
| Field | Description |
|---|---|
nonce | Sender’s transaction counter (prevents replay attacks). |
gasPrice | Price per gas unit. |
gasLimit | Maximum gas allocated. |
to | Recipient address (or null for contract creation). |
value | Ether amount (wei). |
v, r, s | ECDSA signature components (derives sender’s public key). |
For contract-creation transactions:
init: EVM initialization code.data: Unlimited input data.
👉 Learn how gas fees impact Ethereum transactions
Understanding Messages
A message is a virtual object generated by contracts during execution. Unlike transactions, messages exist only within the EVM and aren’t recorded on-chain. Structurally, they resemble transactions but serve internal purposes (e.g., cross-contract function calls).
Message Components
- Sender/Receiver addresses.
- Ether value (wei).
- Optional data payload.
- Gas parameters (
STARTGAS,GASPRICE).
Key Differences: Transactions, Messages, and Calls
| Feature | Transaction | Message | Message Call |
|---|---|---|---|
| Origin | External actor (signed). | Contract-generated. | Local function invocation. |
| Persistence | Recorded on-chain. | EVM-only (transient). | Non-persistent (simulation). |
| Gas Cost | Paid by sender. | Deducted from contract balance. | No Ether spent (read-only). |
Ethereum Yellow Paper Definitions:
- Transaction: Signed data representing a message or new contract (stored in blocks).
- Message: Data/value passed between accounts via contracts or transactions.
- Message Call: A non-persistent action where a contract invokes another contract’s function.
Function Calls: Transaction or Message Call?
Here’s how different invocation methods behave:
- Direct
callto a contract function: Message call (read-only). sendTransactionto a function: On-chain transaction.- Contract-to-contract
call: Message call. - Contract-to-contract
sendTransaction: Message (not a transaction; lacks external signature).
👉 Explore smart contract interaction patterns
FAQs
1. Can a message modify blockchain state?
No. Messages are internal to the EVM and don’t persist. Only transactions alter state.
2. Why does sendTransaction create a transaction but not contract-to-contract calls?
Transactions require external signatures. Contract-initiated actions are messages, even if they use similar methods.
3. How does nonce prevent replay attacks?
Each transaction increments the sender’s nonce. Replayed transactions with outdated nonce values are rejected.
4. What happens if a transaction exceeds its gasLimit?
The EVM reverts all changes, and the sender loses the spent gas.
5. Are messages free to send?
No. Messages consume gas from the sender contract’s balance, though they’re cheaper than transactions.
6. Can I simulate a transaction without broadcasting it?
Yes. Use eth_call for read-only simulations or testnets for dry runs.
Copyright © Luo Yuanhang. Licensed under Attribution-NonCommercial 3.0.