estimate_gas_price
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).
Endpoint#
GET /v1/estimate_gas_price
Request#
Path Parameters#
None.
Query Parameters#
None.
Request Body#
None.
Response#
Success Response (200)#
Returns gas price estimates in octas (1 APT = 100,000,000 octas):
{
"prioritized_gas_estimate": "150",
"gas_estimate": "100",
"deprioritized_gas_estimate": "50"
}
Field Descriptions:
prioritized_gas_estimate: Higher gas price for faster inclusion, typically processed within 1-2 blocksgas_estimate: Standard gas price for normal transaction speed, typically processed within 2-5 blocksdeprioritized_gas_estimate: Lower gas price for cost-sensitive, non-urgent transactions, may take longer to process
All values are returned as string-encoded integers representing gas units in octas.
Error Responses#
| Status | Error Code | Description |
|---|---|---|
| 500 | internal_error | Server error estimating gas |
| 503 | service_unavailable | Gas estimation temporarily unavailable |
Code Examples#
curl -X GET https://api-aptos-mainnet.n.dwellir.com/YOUR_API_KEY/v1/estimate_gas_price \
-H "Accept: application/json"
Python example with SDK:
from aptos_sdk.client import RestClient
client = RestClient("https://api-aptos-mainnet.n.dwellir.com/YOUR_API_KEY/v1")
gas_estimates = client.estimate_gas_price()
print(f"Standard gas price: {gas_estimates['gas_estimate']} octas")
TypeScript example:
const response = await fetch(
"https://api-aptos-mainnet.n.dwellir.com/YOUR_API_KEY/v1/estimate_gas_price",
{ headers: { "Accept": "application/json" } }
);
const estimates = await response.json();
console.log(`Prioritized: ${estimates.prioritized_gas_estimate} octas`);
Use Cases#
This endpoint is critical for building responsive and cost-effective applications:
-
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, helping optimize transaction 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 other 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 MEV, 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.
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 (max_gas_amount × gas_unit_price). A simple transfer might consume 5-10 gas units, while complex smart contract interactions can consume thousands.
For reference, at 100 octas per gas unit, a simple APT transfer costs approximately 0.00001 APT (1000 gas units × 100 octas), making Aptos one of the most cost-effective layer-1 blockchains.