estimate_gas_price
Get suggested gas unit price tiers for Aptos transactions
Overview
Retrieve current gas price estimates for Aptos transactions. This endpoint provides three tiers of gas pricing to help applications choose appropriate fees based on urgency: prioritized (fast), standard, and deprioritized (economy). Gas prices are measured in octas per gas unit (1 APT = 100,000,000 octas).
Endpoint
GET /v1/estimate_gas_price
Code Examples
curl -X GET "https://api-aptos-mainnet.n.dwellir.com/YOUR_API_KEY/v1/estimate_gas_price" \
-H "Accept: application/json"Understanding Aptos Gas
Aptos gas works differently from EVM chains:
| Concept | Description |
|---|---|
| Gas Unit Price | Price per unit of gas in octas (this endpoint provides estimates) |
| Gas Used | Actual gas units consumed during execution (varies by operation) |
| Max Gas Amount | Maximum gas units the sender is willing to pay (set during transaction building) |
| Total Cost | gas_used * gas_unit_price in octas (charged after execution) |
Typical gas usage by operation:
| Operation | Approximate Gas Units |
|---|---|
| Simple APT transfer | 10-20 |
| Token transfer | 20-50 |
| Smart contract call (simple) | 50-200 |
| Smart contract call (complex) | 200-5,000 |
| Module deployment | 1,000-50,000 |
At 100 octas per gas unit, a simple APT transfer costs approximately 0.000002 APT (2,000 octas), making Aptos one of the most cost-effective layer-1 blockchains.
Use Cases
-
Dynamic Transaction Fee Setting: Automatically adjust transaction gas prices based on current network conditions rather than using hardcoded values, ensuring reliable execution without overpaying.
-
User Experience Optimization: Offer users multiple speed/cost options (fast/normal/economy) by exposing the three gas tier estimates, similar to modern blockchain wallets.
-
Batch Operation Cost Planning: Estimate total costs for batch operations by multiplying gas estimates by expected gas consumption per transaction, helping optimize batching strategies.
-
Gas Price Monitoring: Track gas price trends over time to identify network congestion patterns and schedule non-urgent operations during low-fee periods.
-
Multi-Chain Cost Comparison: Compare Aptos gas costs with other blockchains to provide users with informed decisions about which chain to use for specific operations.
-
Smart Contract Budgeting: Applications with gas sponsorship or limited budgets can use deprioritized estimates to maximize transaction throughput within budget constraints.
Best Practices
Query Frequency: Gas prices on Aptos are relatively stable compared to EVM chains due to the Block-STM parallel execution model. Query every 30-60 seconds for normal applications, or more frequently during known high-traffic events.
Price Selection Logic: For user-initiated transactions, use the standard estimate. For urgent operations like liquidations or time-sensitive trades, use prioritized. For background tasks or gas-sponsored operations, use deprioritized.
Safety Margins: Add a 10-20% buffer to estimates to account for price fluctuations between estimation and submission, especially for prioritized transactions during volatile periods.
Transaction Expiration: Set appropriate expiration timestamps (typically 60-120 seconds) that match your gas tier choice. Prioritized transactions should have shorter expirations, while deprioritized can be longer.
Error Recovery: If gas estimation fails (500/503 errors), fall back to conservative hardcoded values. For mainnet, safe fallback values are: prioritized=200, standard=100, deprioritized=100 octas per gas unit.
Combining with Simulation: For precise cost estimates, first call estimate_gas_price for the unit price, then simulate the transaction via POST /v1/transactions/simulate to get the actual gas units consumed. Multiply the two for the total cost.
Performance Considerations
This endpoint is extremely lightweight and typically responds in under 20ms. The estimates are calculated based on recent block gas usage and mempool analysis, updated every block (approximately every 4 seconds on mainnet).
Gas estimates reflect the minimum gas unit price needed for inclusion, but actual transaction costs depend on gas consumption (gas_used * gas_unit_price). A simple transfer might consume 10-20 gas units, while complex smart contract interactions can consume thousands.
The response is under 200 bytes, making it suitable for frequent polling even on bandwidth-constrained connections.
Related Endpoints
/v1/transactions/simulate- Simulate a transaction to get exact gas usage/v1/transactions- Submit transactions using the estimated gas price/v1- Get ledger info (useful for setting expiration timestamps)/v1/transactions/encode_submission- Encode a transaction with gas parameters