Skip to content

Commit 622c071

Browse files
committed
extra info
1 parent b9addfe commit 622c071

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

docs/sdk-and-tools/rest-api/transactions.mdx

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,36 @@ Example response for cross-shard transactions:
347347

348348
`https://gateway.multiversx.com/transaction/cost`
349349

350+
This endpoint is used to estimate the gas cost of a given transaction.
350351

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

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

357-
:::warning
358-
As the transaction is executed in a simulated environment, `providing the correct nonce is mandatory`.
359-
:::
360380

361381
<Tabs
362382
defaultValue="Request"

0 commit comments

Comments
 (0)