Implementing EIP-1559 Fee Mechanism in Mobile Wallet
Before EIP-1559, wallets guessed gasPrice—often overpaid or transactions hung. EIP-1559, activated at Ethereum block 12,965,000 (August 2021), introduced predictable fee structure. Supporting it correctly means more than using new fields—it means explaining them to the user.
Type 2 Transaction Structure (EIP-1559)
Type 2 transactions contain three key parameters instead of one gasPrice:
-
baseFee — automatically calculated by the protocol, burned (doesn't go to miner). Increases 12.5% on full blocks, decreases on empty. Get current:
eth_getBlockByNumber("pending", false)→baseFeePerGasfield. - maxPriorityFeePerGas (tip) — miner/validator reward. Minimum tip for block inclusion—usually 0.1–2 Gwei.
-
maxFeePerGas — absolute maximum the user will pay. Actually charged:
min(maxFeePerGas, baseFee + maxPriorityFeePerGas). Difference refunds.
// iOS — web3swift: build EIP-1559 transaction
var transaction = CodableTransaction(
type: .eip1559,
to: recipientAddress,
value: amount,
data: Data()
)
transaction.maxFeePerGas = baseFee + maxPriorityFee + buffer
transaction.maxPriorityFeePerGas = maxPriorityFee
transaction.chainID = BigUInt(1) // Ethereum Mainnet
Why maxFeePerGas Matters More Than gasPrice
User sees maxFeePerGas = 50 Gwei, but if baseFee at mining is 20 Gwei and tip is 2 Gwei, they pay 22 Gwei. The remaining 28 Gwei refund. Key difference from legacy where the full amount went to the miner.
In the UI, show not maxFeePerGas but expected fee (baseFee + tip) and max possible (maxFeePerGas * gasLimit). Reduces user anxiety from seeing a big max.
Dynamic Recommendations
Update recommended values every 12 seconds (Ethereum block time). Sources:
-
eth_feeHistory— calculate percentile priority fee yourself -
eth_maxPriorityFeePerGas— MetaMask method, supported by Infura, Alchemy, QuickNode - Blocknative Gas API — paid, very accurate for Mainnet
// Android — get recommended priority fee
val maxPriorityFeeResponse = web3j.send(
Request("eth_maxPriorityFeePerGas", emptyList<Any>(), web3jService, EthMaxPriorityFeePerGas::class.java)
)
val priorityFeeWei = maxPriorityFeeResponse.maxPriorityFeePerGas
Networks Without EIP-1559
BNB Chain uses legacy format with fixed gasPrice (default 3 Gwei). Polygon supports EIP-1559 since version 26.x. Arbitrum and Optimism have custom mechanisms on top of EIP-1559.
The app must detect network type and choose the right transaction format automatically. Sending type-2 transaction to a non-EIP-1559 network returns unsupported transaction type.
Timeline: 2–3 days: network type detection, type-2 transaction building, dynamic fee recommendations, display expected and max cost, automatic legacy fallback for incompatible networks.







