Docs

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

Bash
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:

ConceptDescription
Gas Unit PricePrice per unit of gas in octas (this endpoint provides estimates)
Gas UsedActual gas units consumed during execution (varies by operation)
Max Gas AmountMaximum gas units the sender is willing to pay (set during transaction building)
Total Costgas_used * gas_unit_price in octas (charged after execution)

Typical gas usage by operation:

OperationApproximate Gas Units
Simple APT transfer10-20
Token transfer20-50
Smart contract call (simple)50-200
Smart contract call (complex)200-5,000
Module deployment1,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

  1. Dynamic Transaction Fee Setting: Automatically adjust transaction gas prices based on current network conditions rather than using hardcoded values, ensuring reliable execution without overpaying.

  2. User Experience Optimization: Offer users multiple speed/cost options (fast/normal/economy) by exposing the three gas tier estimates, similar to modern blockchain wallets.

  3. Batch Operation Cost Planning: Estimate total costs for batch operations by multiplying gas estimates by expected gas consumption per transaction, helping optimize batching strategies.

  4. Gas Price Monitoring: Track gas price trends over time to identify network congestion patterns and schedule non-urgent operations during low-fee periods.

  5. 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.

  6. 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.

  • /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