Skip to content

Commit

Permalink
Merge branch 'master' into add-custom-events
Browse files Browse the repository at this point in the history
  • Loading branch information
symbolpunk authored Oct 19, 2023
2 parents e70c618 + ddd0d4f commit ee2a6e2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
23 changes: 12 additions & 11 deletions arbitrum-docs/devs-how-tos/how-to-estimate-gas.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,23 @@ import PublicPreviewBannerPartial from '../partials/_public-preview-banner-parti

<PublicPreviewBannerPartial />

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

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.
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/@nitroRepositorySlug@/blob/@nitroVersionTag@/nodeInterface/NodeInterface.go#L120) to get all the gas information needed to send a succesful transaction.

## Breaking down the formula

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.

As explained in the Medium article, the transaction fees to pay at any given moment are the result of the following product:

```
Expand Down Expand Up @@ -143,14 +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.

## 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

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.
Binary file modified arbitrum-docs/for-devs/assets/quickstart-import-metamask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified arbitrum-docs/for-devs/assets/quickstart-localhost-metamask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import KnowMoreToolsBox from '../partials/_know-more-tools-box-partial.md';

Here, we offer a compilation of tools and blockchain explorers that enable you to examine and oversee transactions, smart contracts, and overall blockchain activity related to decentralized applications (dApps) on different Arbitrum chains.

| Tool | Use-cases | Relevant links |
| ---------- | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Arbiscan | Track/trace transactions and examine addresses on Arbitrum networks | <ul><li>Arbitrum One: [https://arbiscan.io/](https://arbiscan.io/)</li><li>Arbitrum Nova: [https://nova.arbiscan.io/](https://nova.arbiscan.io/)</li><li>Arbitrum Goerli: [https://goerli.arbiscan.io/](https://goerli.arbiscan.io/)</li></ul> |
| DexGuru | Track/trace transactions and examine addresses on Arbitrum networks | <ul><li>Arbitrum One: [https://arbitrum.dex.guru/](https://arbitrum.dex.guru/)</li><li>Arbitrum Nova: [https://nova.dex.guru/](https://nova.dex.guru/)</li></ul> |
| Blockscout | Track/trace transactions and examine addresses on Arbitrum networks | <ul><li>Arbitrum Sepolia: [https://sepolia-explorer.arbitrum.io/](https://sepolia-explorer.arbitrum.io/)</li></ul> |
| Dune | Visualize and analyze Arbitrum network data | <ul><li>[Dune](https://dune.com/)</li><li>[Arbitrum community-created Duune dashboard](https://dune.com/browse/dashboards?q=arbitrum)</li></ul> |
| Chainbase | Index, transform, and use on-chain data at scale | [Chainbase](https://chainbase.com/) |
| Tool | Use-cases | Relevant links |
| ---------- | ------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Arbiscan | Track/trace transactions and examine addresses on Arbitrum networks | <ul><li>Arbitrum One: [https://arbiscan.io/](https://arbiscan.io/)</li><li>Arbitrum Nova: [https://nova.arbiscan.io/](https://nova.arbiscan.io/)</li><li>Arbitrum Sepolia: [https://sepolia.arbiscan.io](https://sepolia.arbiscan.io)</li><li>Arbitrum Goerli: [https://goerli.arbiscan.io/](https://goerli.arbiscan.io/)</li></ul> |
| DexGuru | Track/trace transactions and examine addresses on Arbitrum networks | <ul><li>Arbitrum One: [https://arbitrum.dex.guru/](https://arbitrum.dex.guru/)</li><li>Arbitrum Nova: [https://nova.dex.guru/](https://nova.dex.guru/)</li></ul> |
| Blockscout | Track/trace transactions and examine addresses on Arbitrum networks | <ul><li>Stylus Testnet: [https://stylus-testnet-explorer.arbitrum.io](https://stylus-testnet-explorer.arbitrum.io)</li></ul> |
| Dune | Visualize and analyze Arbitrum network data | <ul><li>[Dune](https://dune.com/)</li><li>[Arbitrum community-created Duune dashboard](https://dune.com/browse/dashboards?q=arbitrum)</li></ul> |
| Chainbase | Index, transform, and use on-chain data at scale | [Chainbase](https://chainbase.com/) |
2 changes: 1 addition & 1 deletion arbitrum-docs/for-devs/quickstart-solidity-hardhat.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Let's implement the "web3" version of the above vending machine using Arbitrum.
- **Metamask**: The <a data-quicklook-from='ethereum-wallet'>wallet</a> we'll use to interact with our vending machine. See [metamask.io](https://metamask.io/) to install.
- **Yarn**: The package manager we'll use to install our dependencies. See [yarnpkg.com](https://yarnpkg.com/) to install.

We'll install the rest of our dependencies as we go.
We'll address remaining dependencies as we go.

### Ethereum and Arbitrum in a nutshell

Expand Down
2 changes: 1 addition & 1 deletion arbitrum-docs/getting-started-users.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Here we display the information of the most common Arbitrum chains, but you can
| RPC URL | https://arb1.arbitrum.io/rpc | https://nova.arbitrum.io/rpc | https://sepolia-rollup.arbitrum.io/rpc |
| Chain ID | 42161 | 42170 | 421614 |
| Currency symbol | ETH | ETH | SepoliaETH |
| Block explorer URL | https://arbiscan.io | https://nova.arbiscan.io/ | https://sepolia-explorer.arbitrum.io/ |
| Block explorer URL | https://arbiscan.io | https://nova.arbiscan.io/ | https://sepolia.arbiscan.io |

### Step 3: Initiate the deposit

Expand Down
2 changes: 1 addition & 1 deletion arbitrum-docs/node-running/node-providers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This section provides an overview of the available public RPC endpoints for diff
| Arbitrum One | https://arb1.arbitrum.io/rpc | 42161 | https://arbiscan.io/ | Ethereum | Nitro (Rollup) | wss://arb1.arbitrum.io/feed | https://arb1-sequencer.arbitrum.io/rpc |
| Arbitrum Nova | https://nova.arbitrum.io/rpc | 42170 | https://nova.arbiscan.io/ | Ethereum | Nitro (AnyTrust) | wss://nova.arbitrum.io/feed | https://nova-sequencer.arbitrum.io/rpc |
| Arbitrum Goerli (Testnet) | https://goerli-rollup.arbitrum.io/rpc | 421613 | https://goerli.arbiscan.io | Goerli | Nitro (Rollup) | wss://goerli-rollup.arbitrum.io/feed | https://goerli-rollup-sequencer.arbitrum.io/rpc |
| Arbitrum Sepolia (Testnet) | https://sepolia-rollup.arbitrum.io/rpc | 421614 | https://sepolia-explorer.arbitrum.io/ | Sepolia | Nitro (Rollup) | wss://sepolia-rollup.arbitrum.io/feed | https://sepolia-rollup-sequencer.arbitrum.io/rpc |
| Arbitrum Sepolia (Testnet) | https://sepolia-rollup.arbitrum.io/rpc | 421614 | https://sepolia.arbiscan.io | Sepolia | Nitro (Rollup) | wss://sepolia-rollup.arbitrum.io/feed | https://sepolia-rollup-sequencer.arbitrum.io/rpc |
| Stylus Testnet | https://stylus-testnet.arbitrum.io/rpc | 23011913 | https://stylus-testnet-explorer.arbitrum.io/ | Arbitrum Sepolia | Nitro (Rollup) | wss://stylus-sepolia.arbitrum.io/feed | https://stylus-testnet-sequencer.arbitrum.io/rpc |

⚠️ Unlike the RPC Urls, the Sequencer endpoints only support `eth_sendRawTransaction` and `eth_sendRawTransactionConditional` calls.
Expand Down

0 comments on commit ee2a6e2

Please sign in to comment.