Technical Deep Dive: What Happens When You Send 1 DAI

ยท

This article traces the journey of a DAI transaction from initiation to confirmation, examining how wallets construct transaction data, set gas fees, sign transactions, and how nodes validate and execute the corresponding Solidity bytecode.

Author: tincho
Translation: Chainlink Translation Team
Proofreading: Tiny Bear

Transaction Construction

When you send 1 DAI to Vitalik's address (0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045) via MetaMask, your wallet constructs a transaction object:

{
  "to": "0x6b175474e89094c44da98b954eedeac495271d0f", // DAI contract address
  "amount": 0,
  "chainId": 1, // Mainnet
  "nonce": 0,
  "data": "0xa9059cbb000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000de0b6b3a7640000"
}

Key Components:

  1. Recipient Address: The DAI smart contract (not Vitalik's address directly)
  2. Value: 0 ETH (since we're sending ERC-20 tokens)
  3. Data Field: ABI-encoded transfer(address,uint256) call with:

    • Recipient: Vitalik's address
    • Amount: 1 DAI (1000000000000000000 wei)

Gas Fee Calculation

Wallets determine optimal gas fees by:

  1. Querying nodes via JSON-RPC (eth_feeHistory)
  2. Using third-party services like Infura/Alchemy
  3. Simulating transactions via eth_estimateGas

The finalized transaction includes:

{
  "maxPriorityFeePerGas": 2 Gwei,
  "maxFeePerGas": 120 Gwei,
  "gasLimit": 40000
}

Transaction Signing

Using ECDSA with your private key, the wallet:

  1. Computes the transaction hash
  2. Generates signature values (v, r, s)
  3. Serializes the signed transaction via RLP encoding

Node Processing

Upon receiving the transaction via eth_sendRawTransaction, nodes:

  1. Deserialize and validate the transaction
  2. Verify ECDSA signatures
  3. Check gas fees against network conditions
  4. Add to mempool (if valid)

Execution Phase

When mined, the EVM:

  1. Initializes execution environment
  2. Validates calldata (minimum 4 bytes for function selector)
  3. Matches the function selector (0xa9059cbb) to DAI's transfer function
  4. Executes in stages:

    • Verifies sender balance
    • Updates sender/receiver balances via SSTORE
    • Emits Transfer event (LOG3 opcode)
    • Returns success status

Key EVM Operations

OpcodePurpose
CALLDATALOADRead calldata
SLOADRead storage
SSTOREUpdate balances
LOG3Emit event
RETURNEnd execution

Transaction Receipt

Successful execution produces a receipt with:

{
  "status": 1,
  "gasUsed": 34706,
  "logs": [{
    "topics": [
      "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
      "0x000000000000000000000000[YOUR_ADDRESS]",
      "0x000000000000000000000000[VITALIK_ADDRESS]"
    ],
    "data": "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000"
  }]
}

FAQs

Why does the transaction target the DAI contract instead of Vitalik's address?
ERC-20 transfers require interacting with the token contract to update internal balance mappings.

How is 1 DAI represented in the data field?
As 1000000000000000000 wei (18 decimal places), encoded as 0x0de0b6b3a7640000.

What prevents transaction replay attacks?
The chainId and nonce fields ensure transactions are only valid on specified networks and in sequence.

Why do wallets estimate gas before sending?
To prevent failed transactions and calculate appropriate fees based on network congestion.

For deeper exploration of EVM mechanics, check out EVM opcode references.

๐Ÿ‘‰ Understanding Ethereum Gas Fees
๐Ÿ‘‰ ERC-20 Token Standards Explained

This concludes our 5,000+ word journey through the technical stack powering a simple DAI transfer. The Ethereum blockchain combines cryptography, economics, and distributed systems to enable secure value transfer without intermediaries.