⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip the expensive compute units.
Switch Today →
Skip to main content

eth_estimateL1Fee

Estimates the L1 data fee that would be paid for a given transaction on Optimism Layer 2. This is unique to Optimism's rollup architecture.

When to Use This Method

eth_estimateL1Fee is essential for:

  • Complete Fee Estimation - Calculate total transaction cost (L1 + L2 fees)
  • Cost Optimization - Compare different transaction approaches
  • User Experience - Show accurate fee estimates to users
  • Rollup Economics - Understand L1 data costs for your application

Parameters

  1. Transaction Object
    • from - Sender address (optional)
    • to - Destination address
    • gas - Gas limit (optional)
    • gasPrice - Gas price (optional)
    • value - Value in wei (optional)
    • data - Transaction data (optional)

Implementation Examples

curl -X POST https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_estimateL1Fee",
"params": [{
"from": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"to": "0x4200000000000000000000000000000000000006",
"value": "0xde0b6b3a7640000",
"data": "0xa9059cbb0000000000000000000000008ba1f109551bd432803012645hac136c0000000000000000000000000000000000000000000000000de0b6b3a7640000"
}],
"id": 1
}'

Response Example

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x2386f26fc10000"
}

This represents the L1 data fee in wei. For a typical ERC-20 transfer, this might be around 0.001 ETH.

Understanding Optimism Fee Structure

Total Transaction Cost = L1 Data Fee + L2 Execution Fee

// Complete fee breakdown for Optimism transactions
async function getOptimismFeeBreakdown(txObject) {
// L1 data fee (varies based on calldata size and L1 gas price)
const l1FeeResponse = await fetch('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_estimateL1Fee',
params: [txObject],
id: 1
})
});

const l1Fee = BigInt((await l1FeeResponse.json()).result);

// L2 execution fee (much cheaper than Ethereum mainnet)
const l2GasResponse = await fetch('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_estimateGas',
params: [txObject],
id: 2
})
});

const l2Gas = BigInt((await l2GasResponse.json()).result);

const gasPriceResponse = await fetch('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_gasPrice',
params: [],
id: 3
})
});

const gasPrice = BigInt((await gasPriceResponse.json()).result);
const l2Fee = l2Gas * gasPrice;

console.log('Optimism Fee Breakdown:');
console.log('L1 Data Fee:', Number(l1Fee) / 1e18, 'ETH');
console.log('L2 Execution Fee:', Number(l2Fee) / 1e18, 'ETH');
console.log('Total Fee:', Number(l1Fee + l2Fee) / 1e18, 'ETH');
console.log('L1 Fee %:', (Number(l1Fee) / Number(l1Fee + l2Fee) * 100).toFixed(1) + '%');

return {
l1Fee: l1Fee,
l2Fee: l2Fee,
totalFee: l1Fee + l2Fee
};
}

Optimizing L1 Fees

Reduce Calldata Size

// Techniques to minimize L1 data fees
class OptimismFeeOptimizer {
// Use shorter function selectors when possible
static optimizeCalldata(data) {
// Remove unnecessary zero bytes
// Use packed structs
// Minimize string lengths
return data;
}

// Batch multiple operations to amortize L1 costs
static async batchOperations(operations) {
// Bundle multiple calls into single transaction
const batchCalldata = this.encodeBatch(operations);

return {
to: BATCH_CONTRACT_ADDRESS,
data: batchCalldata
};
}

// Compare costs of different transaction approaches
static async compareFees(txOptions) {
const fees = [];

for (const tx of txOptions) {
const l1Fee = await this.estimateL1Fee(tx);
fees.push({
transaction: tx,
l1Fee: l1Fee,
description: tx.description
});
}

return fees.sort((a, b) => Number(a.l1Fee - b.l1Fee));
}
}

Need help? Contact our support team or check the Optimism documentation.