Query editor
-- https://docs.alchemy.com/docs/how-to-build-a-gas-fee-estimator-using-eip-1559#comparing-our-estimate-to-eth_maxpriorityfeepergasWITH latest_block AS (SELECTMAX(number) AS last_bn,24.0*60.0*60.0/2.0 AS t24h_blocks,12.0*60.0*60.0/2.0 AS t12h_blocks,6.0*60.0*60.0/2.0 AS t6h_blocks,1.0*60.0*60.0/2.0 AS t1h_blocks,1.0*60.0*60.0/2.0/60.0 AS t1m_blocks,12.0/6.0 AS l2_blocks_per_l1_blockFROM base.blocks WHERE time < NOW() - interval '144' hour AND time > NOW() - interval '240' hour), blocks AS (SELECT*, 5000000 - gas_used AS gas_used_target_diff, cast(gas_used as double) / cast(gas_limit as double) AS pct_gas_limit_usedFROM (SELECTb.number AS block_number, b.time AS block_time, last_bn - b.number + 1 AS trailing_block_rank -- recency rank, initialized at 1, NOW() - b.time AS block_time_lag_vs_now, DATE_DIFF('second',b.time, NOW()) AS block_time_lag_vs_now_seconds, b.gas_used, b.gas_limit, coalesce(cast(base_fee_per_gas as double)/1e9, 0.001) AS base_fee, cast(l1_gas_price as double)/1e9 AS l1_gas_price, cast( AVG(gas_price) as double) / 1e9 AS avg_gas_price, cast( AVG(gas_price-coalesce(base_fee_per_gas,0)) as double) / 1e9 AS avg_priority_fee, cast(approx_percentile(cast(gas_price as double) - coalesce(base_fee_per_gas,0) , 0.01) as double)/1e9 AS priority_fee_01_percentile, cast(approx_percentile(cast(gas_price as double) - coalesce(base_fee_per_gas,0) , 0.25) as double)/1e9 AS priority_fee_25_percentile, cast(approx_percentile(cast(gas_price as double) - coalesce(base_fee_per_gas,0) , 0.50) as double)/1e9 AS priority_fee_50_percentile, cast(approx_percentile(cast(gas_price as double) - coalesce(base_fee_per_gas,0) , 0.75) as double)/1e9 AS priority_fee_75_percentile, cast(approx_percentile(cast(gas_price as double) - coalesce(base_fee_per_gas,0) , 0.99) as double)/1e9 AS priority_fee_99_percentile, COUNT(*) AS num_txsFROM latest_block lCROSS JOIN base.blocks bINNER JOIN base.transactions tON t.block_number = b.numberAND t.block_time = b.timeAND b.number > last_bn - t6h_blocksWHERE number > last_bn - t6h_blocksAND gas_price > cast(0 as uint256)AND to NOT IN (SELECT address FROM labels.system_addresses WHERE blockchain = 'base')GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9) a)SELECT * FROM blocks