Batch Operations
Batch operations allow multiple transactions to be bundled and executed atomically in a single meta transaction, reducing gas costs and improving user experience.
Overview
Batch operations enable:
Multiple actions in one transaction
Atomic execution (all succeed or all fail)
Significant gas savings
Complex multi-step workflows
Supported Operations
Trading Operations
const batchTrade = [
{ action: 'swap', from: 'DI', to: 'DUSD', amount: '100' },
{ action: 'addLiquidity', tokenA: 'DUSD', tokenB: 'ETH', amountA: '50' },
{ action: 'stake', token: 'DI', amount: '200' }
]Cross-Chain Operations
Batch Execution
Creating Batches
Conditional Operations
Gas Optimization
Batch Benefits
Reduced Overhead: Single transaction setup cost
Shared Context: Reuse of loaded contract state
Optimized Routing: Smart order execution
Gas Savings Examples
3 Swaps
450,000
320,000
29%
Stake + Claim
180,000
140,000
22%
Bridge + Swap
280,000
220,000
21%
Advanced Features
Slippage Protection
Deadline Management
Error Handling
Batch Types
Sequential Batches
Operations execute in order, with each depending on the previous:
Parallel Batches
Independent operations that can execute simultaneously:
Integration Patterns
DeFi Strategies
Portfolio Rebalancing
Limitations
Size Limits
Maximum 10 operations per batch
Total gas limit: 8M gas units
Maximum execution time: 5 minutes
Supported Contracts
Not all contracts support batch operations:
Must implement
IBatchableinterfaceRequire explicit batch operation support
Some operations may be restricted
Failure Modes
All-or-nothing: Entire batch fails if any operation fails
Partial execution: Some operations may succeed before failure
Gas estimation: May be inaccurate for complex batches
Best Practices
Batch Design
Group related operations together
Consider operation dependencies
Test with small amounts first
Monitor gas usage patterns
Error Prevention
Validate inputs before batching
Set appropriate slippage tolerances
Use reasonable deadlines
Handle partial failures gracefully
Last updated