From f3bdfb3f131295112c06af2e0814861d726a2162 Mon Sep 17 00:00:00 2001 From: khang8473 Date: Wed, 3 Jun 2026 13:28:07 +0700 Subject: [PATCH 1/2] add gas optimization --- .../network-information/gas-optimizatio | 74 +++++++++++++++++++ .../network-information/gas-optimization | 74 +++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 docs/base-chain/network-information/gas-optimizatio create mode 100644 docs/base-chain/network-information/gas-optimization diff --git a/docs/base-chain/network-information/gas-optimizatio b/docs/base-chain/network-information/gas-optimizatio new file mode 100644 index 000000000..dfe8cafe8 --- /dev/null +++ b/docs/base-chain/network-information/gas-optimizatio @@ -0,0 +1,74 @@ +--- +title: Gas Optimization on Base +description: Practical techniques to minimize costs and improve UX when building on Base. +--- + +# Gas Optimization on Base + +Base offers significantly lower fees than Ethereum L1, but optimizing further improves user experience, especially for high-volume apps, agents, or mini-apps. Focus on happy-path patterns with real examples. + +## Core Principles + +- **Batch where possible**: Reduce per-transaction overhead. +- **Use efficient data types and patterns**: Avoid unnecessary storage writes. +- **Leverage Base-specific features**: Flashblocks for faster/previewable inclusion, accurate fee estimation. +- **Client-side estimation**: Always simulate before sending. + +Fees are dynamic. Always estimate on-chain; Base's block production differs from L1. See [Network Fees](/base-chain/network-information/network-fees). + +## Step-by-Step Techniques + +### 1. Accurate Gas Estimation + +Use `eth_estimateGas` or libraries with Base RPCs. Prefer `base` public endpoints or providers. + +```typescript +// filename: estimate-gas.ts +import { createPublicClient, http, parseEther } from 'viem' +import { base } from 'viem/chains' + +const client = createPublicClient({ + chain: base, + transport: http() +}) + +async function estimateTransfer(to: `0x${string}`, value: bigint) { + const gas = await client.estimateGas({ + account: '0xYourAddress', + to, + value + }) + console.log(`Estimated gas: ${gas}`) + return gas +} +``` + +Combine with `eth_feeHistory` for priority fees. See [RPC API](/base-chain/api-reference/rpc-overview) + +### 2. Batching Transactions + +Use multicall or account abstractions (Base Account / Smart Wallets) for batched ops. + +**Example with viem + Base Account patterns** (link to sub-accounts/spend permissions docs). + +### 3. Contract-Level Optimizations + +- Use `immutable`/`constant` where possible. + +- Minimize storage slots (pack variables). + +- Prefer events over storage for offchain indexing. + +- For agents: Use efficient loops and avoid reverts in hot paths. + +### 4. Flashblocks-Aware Patterns + +Preview transactions or react to partial blocks for better UX in high-throughput scenarios. (Link to Flashblocks section). + +## Common Pitfalls & Troubleshooting + +- **Nonce gaps**: Handle carefully with replacements. See [Troubleshooting Transactions](/base-chain/network-information/troubleshooting-transactions). + +- **Over-estimation**: Add small buffer but avoid excess. + +- **Legacy vs EIP-1559**: Base supports modern types; use `maxFeePerGas`/`maxPriorityFeePerGas`. diff --git a/docs/base-chain/network-information/gas-optimization b/docs/base-chain/network-information/gas-optimization new file mode 100644 index 000000000..dfe8cafe8 --- /dev/null +++ b/docs/base-chain/network-information/gas-optimization @@ -0,0 +1,74 @@ +--- +title: Gas Optimization on Base +description: Practical techniques to minimize costs and improve UX when building on Base. +--- + +# Gas Optimization on Base + +Base offers significantly lower fees than Ethereum L1, but optimizing further improves user experience, especially for high-volume apps, agents, or mini-apps. Focus on happy-path patterns with real examples. + +## Core Principles + +- **Batch where possible**: Reduce per-transaction overhead. +- **Use efficient data types and patterns**: Avoid unnecessary storage writes. +- **Leverage Base-specific features**: Flashblocks for faster/previewable inclusion, accurate fee estimation. +- **Client-side estimation**: Always simulate before sending. + +Fees are dynamic. Always estimate on-chain; Base's block production differs from L1. See [Network Fees](/base-chain/network-information/network-fees). + +## Step-by-Step Techniques + +### 1. Accurate Gas Estimation + +Use `eth_estimateGas` or libraries with Base RPCs. Prefer `base` public endpoints or providers. + +```typescript +// filename: estimate-gas.ts +import { createPublicClient, http, parseEther } from 'viem' +import { base } from 'viem/chains' + +const client = createPublicClient({ + chain: base, + transport: http() +}) + +async function estimateTransfer(to: `0x${string}`, value: bigint) { + const gas = await client.estimateGas({ + account: '0xYourAddress', + to, + value + }) + console.log(`Estimated gas: ${gas}`) + return gas +} +``` + +Combine with `eth_feeHistory` for priority fees. See [RPC API](/base-chain/api-reference/rpc-overview) + +### 2. Batching Transactions + +Use multicall or account abstractions (Base Account / Smart Wallets) for batched ops. + +**Example with viem + Base Account patterns** (link to sub-accounts/spend permissions docs). + +### 3. Contract-Level Optimizations + +- Use `immutable`/`constant` where possible. + +- Minimize storage slots (pack variables). + +- Prefer events over storage for offchain indexing. + +- For agents: Use efficient loops and avoid reverts in hot paths. + +### 4. Flashblocks-Aware Patterns + +Preview transactions or react to partial blocks for better UX in high-throughput scenarios. (Link to Flashblocks section). + +## Common Pitfalls & Troubleshooting + +- **Nonce gaps**: Handle carefully with replacements. See [Troubleshooting Transactions](/base-chain/network-information/troubleshooting-transactions). + +- **Over-estimation**: Add small buffer but avoid excess. + +- **Legacy vs EIP-1559**: Base supports modern types; use `maxFeePerGas`/`maxPriorityFeePerGas`. From 9dc2e9b2a9bc621d76b3c63b22244417feaabe8c Mon Sep 17 00:00:00 2001 From: khang8473 Date: Wed, 3 Jun 2026 13:33:49 +0700 Subject: [PATCH 2/2] add gas optimization --- .../network-information/gas-optimizatio | 74 ------------------- 1 file changed, 74 deletions(-) delete mode 100644 docs/base-chain/network-information/gas-optimizatio diff --git a/docs/base-chain/network-information/gas-optimizatio b/docs/base-chain/network-information/gas-optimizatio deleted file mode 100644 index dfe8cafe8..000000000 --- a/docs/base-chain/network-information/gas-optimizatio +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: Gas Optimization on Base -description: Practical techniques to minimize costs and improve UX when building on Base. ---- - -# Gas Optimization on Base - -Base offers significantly lower fees than Ethereum L1, but optimizing further improves user experience, especially for high-volume apps, agents, or mini-apps. Focus on happy-path patterns with real examples. - -## Core Principles - -- **Batch where possible**: Reduce per-transaction overhead. -- **Use efficient data types and patterns**: Avoid unnecessary storage writes. -- **Leverage Base-specific features**: Flashblocks for faster/previewable inclusion, accurate fee estimation. -- **Client-side estimation**: Always simulate before sending. - -Fees are dynamic. Always estimate on-chain; Base's block production differs from L1. See [Network Fees](/base-chain/network-information/network-fees). - -## Step-by-Step Techniques - -### 1. Accurate Gas Estimation - -Use `eth_estimateGas` or libraries with Base RPCs. Prefer `base` public endpoints or providers. - -```typescript -// filename: estimate-gas.ts -import { createPublicClient, http, parseEther } from 'viem' -import { base } from 'viem/chains' - -const client = createPublicClient({ - chain: base, - transport: http() -}) - -async function estimateTransfer(to: `0x${string}`, value: bigint) { - const gas = await client.estimateGas({ - account: '0xYourAddress', - to, - value - }) - console.log(`Estimated gas: ${gas}`) - return gas -} -``` - -Combine with `eth_feeHistory` for priority fees. See [RPC API](/base-chain/api-reference/rpc-overview) - -### 2. Batching Transactions - -Use multicall or account abstractions (Base Account / Smart Wallets) for batched ops. - -**Example with viem + Base Account patterns** (link to sub-accounts/spend permissions docs). - -### 3. Contract-Level Optimizations - -- Use `immutable`/`constant` where possible. - -- Minimize storage slots (pack variables). - -- Prefer events over storage for offchain indexing. - -- For agents: Use efficient loops and avoid reverts in hot paths. - -### 4. Flashblocks-Aware Patterns - -Preview transactions or react to partial blocks for better UX in high-throughput scenarios. (Link to Flashblocks section). - -## Common Pitfalls & Troubleshooting - -- **Nonce gaps**: Handle carefully with replacements. See [Troubleshooting Transactions](/base-chain/network-information/troubleshooting-transactions). - -- **Over-estimation**: Add small buffer but avoid excess. - -- **Legacy vs EIP-1559**: Base supports modern types; use `maxFeePerGas`/`maxPriorityFeePerGas`.