From fd873b11cb89e30023da162e9a2442516930f218 Mon Sep 17 00:00:00 2001 From: Mahsa Moosavi Date: Wed, 18 Oct 2023 09:34:10 -0400 Subject: [PATCH 1/6] Refactor the how-to gas estimation --- .../devs-how-tos/how-to-estimate-gas.mdx | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx b/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx index b1101fc3e..8747543e6 100644 --- a/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx +++ b/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx @@ -10,14 +10,24 @@ import PublicPreviewBannerPartial from '../partials/_public-preview-banner-parti -This how-to is intended for users and developers who want to understand how gas is calculated in Arbitrum, and how it can be estimated before submitting transactions. More information about the theory behind these calculations can be found in this [Medium article](https://medium.com/offchainlabs/understanding-arbitrum-2-dimensional-fees-fd1d582596c9) and the [Gas and Fees](/arbos/gas.mdx) page. +This how-to is intended for users and developers interested in understanding how gas operates in Arbitrum, how it's calculated, and how to estimate it before submitting transactions. More detailed information about these calculations can be found in this [Medium article](https://medium.com/offchainlabs/understanding-arbitrum-2-dimensional-fees-fd1d582596c9) and the [Gas and Fees](/arbos/gas.mdx) page. -We'll first break down the formula mentioned in the Medium article, moving then to where to get the information of each variable, and finally seeing an example of how to apply the formula in your code as well as other practical ways of estimating gas costs. +## Skip the formula, focus on practical know-how + +Before diving into the specifics and the formula, if you're looking for a practical way to estimate gas for your transaction, you can rely on the standard gas estimation process. This can be achieved by calling an Arbitrum Node's `eth_estimateGas`, which provides a value (gas limit) that should sufficiently cover the entire transaction fee at the specified L2 gas price. +Multiplying the value obtained from `eth_estimateGas` by the L2 gas price will give you the total amount of Ether required for the transaction to be successful. It's important to note that, for a specific operation, the result of `eth_estimateGas` value may vary over time due to fluctuations in the L1 calldata price, see below to learn why! + +Alternatively, to obtain the gas limit for your transaction, you can call `NodeInterface.gasEstimateComponents()` and then use the first result, which is `gasEstimate`. Next, to find the total cost, you need to multiply this amount by the L2 gas price, which is available in the third result, `baseFee`. + +Note that when working with L1 to L2 messages (also known as [retryable tickets](/arbos/l1-to-l2-messaging.mdx)), you can use the function [L1ToL2MessageGasEstimator.estimateAll()](https://github.com/OffchainLabs/arbitrum-sdk/blob/main/src/lib/message/L1ToL2MessageGasEstimator.ts#L215) of the Arbitrum SDK or [NodeInterface.estimateRetryableTicket()](https://github.com/OffchainLabs/nitro/blob/master/nodeInterface/NodeInterface.go#L120) to get all the gas information needed to send a succesful transaction. -However, if you want to jump straight to the code, we have created [this script in our tutorials repository](https://github.com/OffchainLabs/arbitrum-tutorials/tree/master/packages/gas-estimation) that goes through all the calculations explained in this how-to. ## Breaking down the formula +We'll first break down the formula mentioned in the Medium article, moving then to where to get the information of each variable, and finally seeing an example of how to apply the formula in your code as well as other practical ways of estimating gas costs. + +However, if you want to jump straight to the code, we have created [this script in our tutorials repository](https://github.com/OffchainLabs/arbitrum-tutorials/tree/master/packages/gas-estimation) that goes through all the calculations explained in this how-to. + As explained in the Medium article, the transaction fees to pay at any given moment are the result of the following product: ``` @@ -143,13 +153,6 @@ const TXFEES = P.mul(G); Refer to [our tutorials repository](https://github.com/OffchainLabs/arbitrum-tutorials/tree/master/packages/gas-estimation) for a working example of this code. -## Other practical ways of estimating gas costs in your code - -Instead of going through the formula, we can also use the following methods to easily estimate gas costs: - -- We can call `NodeInterface.gasEstimateComponents()` and obtain the first result, `gasEstimate`, to get the gas limit of the transaction. We would then need to multiply that amount by the L2 gas price, which we can get in the third result, `baseFee`. -- We can call an Arbitrum node’s `eth_estimateGas` to get the gas limit of the transaction. We would then need to multiply that amount by the L2 gas price, which we can get by calling `eth_gasPrice`. -- When working with L1 to L2 messages (also known as [Retryable tickets](/arbos/l1-to-l2-messaging.mdx)), we can use the function [L1ToL2MessageGasEstimator.estimateAll()](https://github.com/OffchainLabs/arbitrum-sdk/blob/main/src/lib/message/L1ToL2MessageGasEstimator.ts#L215) of the SDK or [NodeInterface.estimateRetryableTicket()](https://github.com/OffchainLabs/nitro/blob/master/nodeInterface/NodeInterface.go#L120) to get all the gas information needed to send the transaction. ## Final note From 409b35d1125e0d4b5a2cbb70a9508e6ecd6681e3 Mon Sep 17 00:00:00 2001 From: Mahsa Moosavi Date: Wed, 18 Oct 2023 09:36:59 -0400 Subject: [PATCH 2/6] yarn format --- arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx b/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx index 8747543e6..d2dc5c5c1 100644 --- a/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx +++ b/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx @@ -14,14 +14,13 @@ This how-to is intended for users and developers interested in understanding how ## Skip the formula, focus on practical know-how -Before diving into the specifics and the formula, if you're looking for a practical way to estimate gas for your transaction, you can rely on the standard gas estimation process. This can be achieved by calling an Arbitrum Node's `eth_estimateGas`, which provides a value (gas limit) that should sufficiently cover the entire transaction fee at the specified L2 gas price. +Before diving into the specifics and the formula, if you're looking for a practical way to estimate gas for your transaction, you can rely on the standard gas estimation process. This can be achieved by calling an Arbitrum Node's `eth_estimateGas`, which provides a value (gas limit) that should sufficiently cover the entire transaction fee at the specified L2 gas price. Multiplying the value obtained from `eth_estimateGas` by the L2 gas price will give you the total amount of Ether required for the transaction to be successful. It's important to note that, for a specific operation, the result of `eth_estimateGas` value may vary over time due to fluctuations in the L1 calldata price, see below to learn why! Alternatively, to obtain the gas limit for your transaction, you can call `NodeInterface.gasEstimateComponents()` and then use the first result, which is `gasEstimate`. Next, to find the total cost, you need to multiply this amount by the L2 gas price, which is available in the third result, `baseFee`. Note that when working with L1 to L2 messages (also known as [retryable tickets](/arbos/l1-to-l2-messaging.mdx)), you can use the function [L1ToL2MessageGasEstimator.estimateAll()](https://github.com/OffchainLabs/arbitrum-sdk/blob/main/src/lib/message/L1ToL2MessageGasEstimator.ts#L215) of the Arbitrum SDK or [NodeInterface.estimateRetryableTicket()](https://github.com/OffchainLabs/nitro/blob/master/nodeInterface/NodeInterface.go#L120) to get all the gas information needed to send a succesful transaction. - ## Breaking down the formula We'll first break down the formula mentioned in the Medium article, moving then to where to get the information of each variable, and finally seeing an example of how to apply the formula in your code as well as other practical ways of estimating gas costs. @@ -153,7 +152,6 @@ const TXFEES = P.mul(G); Refer to [our tutorials repository](https://github.com/OffchainLabs/arbitrum-tutorials/tree/master/packages/gas-estimation) for a working example of this code. - ## Final note Note that gas estimations from the above techniques are approximate and the actual gas fees may differ. We encourage developers to set this expectation explicitly wherever this information is shared with end-users. From 94cebc165441defa202cf81c5f9d7bcf2e00d2ef Mon Sep 17 00:00:00 2001 From: Mahsa Moosavi Date: Wed, 18 Oct 2023 14:37:54 -0400 Subject: [PATCH 3/6] Update arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx Co-authored-by: Tuckson <105675159+TucksonDev@users.noreply.github.com> --- arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx b/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx index d2dc5c5c1..ca9c1ffb7 100644 --- a/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx +++ b/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx @@ -14,7 +14,7 @@ This how-to is intended for users and developers interested in understanding how ## Skip the formula, focus on practical know-how -Before diving into the specifics and the formula, if you're looking for a practical way to estimate gas for your transaction, you can rely on the standard gas estimation process. This can be achieved by calling an Arbitrum Node's `eth_estimateGas`, which provides a value (gas limit) that should sufficiently cover the entire transaction fee at the specified L2 gas price. +Before diving into the specifics and the formula, if you're looking for a practical way to estimate gas for your transaction, you can rely on the standard gas estimation process. This can be achieved by calling an Arbitrum node's `eth_estimateGas`, which provides a value (gas limit) that should sufficiently cover the entire transaction fee at the specified L2 gas price. Multiplying the value obtained from `eth_estimateGas` by the L2 gas price will give you the total amount of Ether required for the transaction to be successful. It's important to note that, for a specific operation, the result of `eth_estimateGas` value may vary over time due to fluctuations in the L1 calldata price, see below to learn why! Alternatively, to obtain the gas limit for your transaction, you can call `NodeInterface.gasEstimateComponents()` and then use the first result, which is `gasEstimate`. Next, to find the total cost, you need to multiply this amount by the L2 gas price, which is available in the third result, `baseFee`. From 63f715f5cea45a9fac9d8552689f0a24e31e35b4 Mon Sep 17 00:00:00 2001 From: Mahsa Moosavi Date: Wed, 18 Oct 2023 14:44:50 -0400 Subject: [PATCH 4/6] Update arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx Co-authored-by: Tuckson <105675159+TucksonDev@users.noreply.github.com> --- arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx b/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx index ca9c1ffb7..95f4f342d 100644 --- a/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx +++ b/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx @@ -23,7 +23,7 @@ Note that when working with L1 to L2 messages (also known as [retryable tickets] ## Breaking down the formula -We'll first break down the formula mentioned in the Medium article, moving then to where to get the information of each variable, and finally seeing an example of how to apply the formula in your code as well as other practical ways of estimating gas costs. +We'll now break down the formula mentioned in the Medium article, moving then to where to get the information of each variable, and finally seeing an example of how to apply the formula in your code as well as other practical ways of estimating gas costs. However, if you want to jump straight to the code, we have created [this script in our tutorials repository](https://github.com/OffchainLabs/arbitrum-tutorials/tree/master/packages/gas-estimation) that goes through all the calculations explained in this how-to. From 780c97c57bd1161a2e2da24d70bc06e406f08415 Mon Sep 17 00:00:00 2001 From: Mahsa Moosavi Date: Wed, 18 Oct 2023 14:46:21 -0400 Subject: [PATCH 5/6] replace links with vars --- arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx b/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx index 95f4f342d..a6af709d7 100644 --- a/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx +++ b/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx @@ -19,7 +19,8 @@ Multiplying the value obtained from `eth_estimateGas` by the L2 gas price will g Alternatively, to obtain the gas limit for your transaction, you can call `NodeInterface.gasEstimateComponents()` and then use the first result, which is `gasEstimate`. Next, to find the total cost, you need to multiply this amount by the L2 gas price, which is available in the third result, `baseFee`. -Note that when working with L1 to L2 messages (also known as [retryable tickets](/arbos/l1-to-l2-messaging.mdx)), you can use the function [L1ToL2MessageGasEstimator.estimateAll()](https://github.com/OffchainLabs/arbitrum-sdk/blob/main/src/lib/message/L1ToL2MessageGasEstimator.ts#L215) of the Arbitrum SDK or [NodeInterface.estimateRetryableTicket()](https://github.com/OffchainLabs/nitro/blob/master/nodeInterface/NodeInterface.go#L120) to get all the gas information needed to send a succesful transaction. +Note that when working with L1 to L2 messages (also known as [retryable tickets](/arbos/l1-to-l2-messaging.mdx)), you can use the function [L1ToL2MessageGasEstimator.estimateAll()](https://github.com/OffchainLabs/arbitrum-sdk/blob/main/src/lib/message/L1ToL2MessageGasEstimator.ts#L215) of the Arbitrum SDK +or [NodeInterface.estimateRetryableTicket()](https://github.com/OffchainLabs/${globalVars.nitroRepositorySlug}/blob/${globalVars.nitroVersionTag}/nodeInterface/NodeInterface.go#L120) to get all the gas information needed to send a succesful transaction. ## Breaking down the formula From b771fc2beb7e5e34474eb256c89a1a20b304264b Mon Sep 17 00:00:00 2001 From: Mahsa Moosavi Date: Wed, 18 Oct 2023 14:55:32 -0400 Subject: [PATCH 6/6] fix the broken link --- arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx b/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx index a6af709d7..d8f537bc6 100644 --- a/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx +++ b/arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx @@ -19,8 +19,7 @@ Multiplying the value obtained from `eth_estimateGas` by the L2 gas price will g Alternatively, to obtain the gas limit for your transaction, you can call `NodeInterface.gasEstimateComponents()` and then use the first result, which is `gasEstimate`. Next, to find the total cost, you need to multiply this amount by the L2 gas price, which is available in the third result, `baseFee`. -Note that when working with L1 to L2 messages (also known as [retryable tickets](/arbos/l1-to-l2-messaging.mdx)), you can use the function [L1ToL2MessageGasEstimator.estimateAll()](https://github.com/OffchainLabs/arbitrum-sdk/blob/main/src/lib/message/L1ToL2MessageGasEstimator.ts#L215) of the Arbitrum SDK -or [NodeInterface.estimateRetryableTicket()](https://github.com/OffchainLabs/${globalVars.nitroRepositorySlug}/blob/${globalVars.nitroVersionTag}/nodeInterface/NodeInterface.go#L120) to get all the gas information needed to send a succesful transaction. +Note that when working with L1 to L2 messages (also known as [retryable tickets](/arbos/l1-to-l2-messaging.mdx)), you can use the function [L1ToL2MessageGasEstimator.estimateAll()](https://github.com/OffchainLabs/arbitrum-sdk/blob/main/src/lib/message/L1ToL2MessageGasEstimator.ts#L215) of the Arbitrum SDK or [NodeInterface.estimateRetryableTicket()](https://github.com/OffchainLabs/@nitroRepositorySlug@/blob/@nitroVersionTag@/nodeInterface/NodeInterface.go#L120) to get all the gas information needed to send a succesful transaction. ## Breaking down the formula