You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/sdk-and-tools/rest-api/transactions.mdx
+27-7Lines changed: 27 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -347,16 +347,36 @@ Example response for cross-shard transactions:
347
347
348
348
`https://gateway.multiversx.com/transaction/cost`
349
349
350
+
This endpoint is used to estimate the gas cost of a given transaction.
350
351
351
-
:::note
352
-
This endpoint estimates the **gas cost** of a transaction. Use this value to determine the appropriate `gasLimit` before sending a transaction.
352
+
It performs a read-only simulation of the transaction against the current on-chain state, returning the number of gas units the transaction would consume if executed in that exact state.
353
353
354
-
In the background, this endpoint simulates the transaction in a read-only environment to estimate its gas cost. Any resulting smart contract results and events will also be returned.
355
-
:::
354
+
💬 How it works:
355
+
- The endpoint takes all transaction input fields (value, sender, receiver, data, chainID, etc.).
356
+
- It executes the transaction in a sandboxed, non-persistent environment, meaning it simulates execution without affecting the actual blockchain.
357
+
- It uses the current state of the network (including smart contract storage, balances, etc.).
358
+
- It returns the estimated gas (txGasUnits) and may also return smart contract results and events triggered by the simulation.
359
+
360
+
❓ How does it apply to smart contracts?
361
+
362
+
For smart contracts, the endpoint simulates the contract call exactly as if it were executed live, including processing all logic, branches, and emitted events.
363
+
The gas estimate reflects the computation and storage impact that would occur if the state remained unchanged at the time of actual execution.
364
+
365
+
❓ How does it approximate the cost if the contract logic has variable gas usage?
366
+
367
+
If a smart contract’s logic has branches or conditional execution that result in variable gas usage (e.g., depending on internal storage state, previous executions, etc.),
368
+
the estimation will only reflect the gas used by the path taken during this particular simulation.
369
+
370
+
❗ Why is providing the correct nonce important?
371
+
372
+
Because the simulation engine mirrors real transaction behavior, it requires a valid and correct nonce to properly simulate the transaction. Using an outdated or incorrect
373
+
nonce may lead to simulation failure.
374
+
375
+
⚠️ Can the estimated gas differ from the actual cost?
376
+
377
+
Yes. Since the blockchain state may change between the moment you call /transaction/cost and when the transaction is actually sent to the network, the real gas usage can differ.
378
+
This is especially true for smart contract calls that depend on dynamic or mutable state.
356
379
357
-
:::warning
358
-
As the transaction is executed in a simulated environment, `providing the correct nonce is mandatory`.
0 commit comments