Supporting Optimism in your wallet
This guide is intended for wallet developers who want to give their users the ability to send transactions on the Optimism network. Optimism generally behaves like any other EVM-based chain with the exception of minor discrepancies related to transaction fees. These fee discrepancies are an inherent result of the fact that Optimism is a Layer 2 blockchain network that must publish transaction data to Ethereum.
# Connecting to Optimism
Optimism shares the Ethereum JSON-RPC API (opens new window) with only a few minor differences. You'll find all of the important information about each Optimism network on our Networks page. You can choose to connect to Optimism via our rate-limited public endpoints, private endpoints from infrastructure providers, or by running your own node. Because of throughput limits, we recommend using private node providers (particularly Alchemy (opens new window)) or running your own node for production applications.
# Canonical token addresses
The ERC-20 contract address for a token on Optimism may be different from the address for the same token on Ethereum. Optimism maintains a token list (opens new window) that includes known addresses for many popular tokens. You can see the same list with a nicer user interface here (opens new window).
For example, looking at the SNX token, the Optimism token list (opens new window) returns the following addresses:
|42||Kovan (test network)|
|69||Optimistic Kovan (test network)|
# Transaction status
A transaction in Optimism can be in one of two states:
- Sequencer Confirmed: The transaction has been accepted by the sequencer on Optimism (L2)
- Confirmed On-Chain: The transaction has been written to Ethereum (L1)
We're still working on the tooling to easily detect when a given transaction has been published to Ethereum. For the moment, we recommend wallets consider transactions final after they are "Sequencer Confirmed". Transactions are considered "Sequencer Confirmed" as soon as their transaction receipt shows at least one confirmation.
# Transaction Fees
We aim to be EVM equivalent (opens new window), meaning we aim to minimize the differences between Optimism and Ethereum. You can see a summary of the few differences between Optimism and Ethereum here. One of the most important discrepancies can be found within Optimism's fee model. As a wallet developer, you must be aware of this difference.
# Estimating total fees
Most of the cost of a transaction on Optimism comes from the cost of publishing the transaction to Ethereum. This publication step is what makes Optimism a Layer 2 blockchain. Unlike with the standard execution gas fee, users cannot specify a particular gas price or gas limit for this portion of their transaction cost. Instead, this fee is automatically deducted from the user's ETH balance on Optimism when the transaction is executed.
You can read more about this subject here.
In particular, you should examine this code sample that explains how to accurately estimate the L1 portion of a transaction's fee.
The total fee paid by a transaction will be a combination of the normal fee estimation formula (
gasPrice * gasLimit) in addition to the estimated L1 fee.
# Displaying fees
We highly recommend displaying fees on Optimism as one unified fee to minimize user confusion. You can do this by combining both portions of the fee (the L2 execution fee and the L1 data fee) into a single value presented to the end user.
# Sending "max" ETH
Many wallets allow users to send the maximum amount of ETH available in the user's balance. Of course, this requires that the predicted fee for the send transaction be deducted from the ETH balance being sent. You MUST deduct both the L2 execution fee and the L1 data fee or the charged fee plus the balance sent will exceed the user's balance and the transaction will fail.