Optimism 백서

Optimism

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 14쪽

and SDKs that surround the OP Stack. Following the [content guide](/op-stack/contribute/content-guide), each listing links exactly one canonical documentation home — this page routes, it does not restate. What gets listed here (and what gets removed) is governed by the [listing criteria](/app-developers/tools-sdks/listing-criteria). ## Support Status Levels | Status | Meaning | | - | - | | **Production** | Stable and recommended for production use by its owner. | | **Developer preview** | Usable today, but its owner has declared it not yet ready for production; APIs may change. | | **Experimental** | A staging ground. Features may change, move, or be upstreamed elsewhere. | ## The Matrix | Tool | Purpose | Owner | Canonical docs | Support status | | - | - | - | - | - | | [`viem/op-stack`](https://viem.sh/op-stack) | General-purpose TypeScript client for OP Stack chains: deposits, withdrawals, L1 gas estimation, and all standard chain interaction, built into viem | [wevm](https://github.com/wevm/viem) (third party) | [viem.sh/op-stack](https://viem.sh/op-stack) | Production | | [`@eth-optimism/viem`](https://github.com/ethereum-optimism/ecosystem/tree/main/packages/viem) | viem extension for OP Stack features that have not yet been upstreamed into viem — Superchain interop actions and utilities; used by this site's bridging and interop tutorials | Optimism ([`ecosystem`](https://github.com/ethereum-optimism/ecosystem) repo) | [Package README & SDK reference](https://github.com/ethereum-optimism/ecosystem/tree/main/packages/viem#readme) | Experimental | | [Actions SDK](https://github.com/ethereum-optimism/actions) (`@eth-optimism/actions-sdk`) | High-level abstractions for building onchain apps — wallet, lend, and swap namespaces over Superchain protocols | Optimism ([`actions`](https://github.com/ethereum-optimism/actions) repo) | [Actions quickstart](/app-developers/quickstarts/actions) and [reference](/app-developers/reference/actions/integrating-wallets) on this site | Developer preview | | [wagmi](https://wagmi.sh) | React hooks for Ethereum apps; works with OP Stack chains as with any EVM chain | [wevm](https://github.com/wevm/wagmi) (third party) | [wagmi.sh](https://wagmi.sh) | Production | | [supersim](/app-developers/tools-sdks/supersim) | Local Superchain simulator: one L1 plus multiple OP Stack L2s for testing L1↔L2 and L2↔L2 message passing without deploying to live networks | Optimism ([`supersim`](https://github.com/ethereum-optimism/supersim) repo) | [Supersim docs](https://supersim.pages.dev) | Developer preview (all releases are alpha pre-releases; interop features in active development) | | [super-cli](https://github.com/ethereum-optimism/super-cli) (`sup`) | Foundry companion CLI for multichain workflows: deploy and verify contracts on multiple chains at once, bridge funds, use connected wallets | Optimism ([`super-cli`](https://github.com/ethereum-optimism/super-cli) repo) | [Repository README](https://github.com/ethereum-optimism/super-cli#readme) | Experimental | | [superchain-registry](https://github.com/ethereum-optimism/superchain-registry) tooling | Not an SDK — the source-of-truth library of chain configs that OP Stack software (such as `op-node` and `op-geth`) consumes, plus the `just` tasks and validation checks used to add and verify a chain | Optimism ([`superchain-registry`](https://github.com/ethereum-optimism/superchain-registry) repo) | [Registry operations docs](https://github.com/ethereum-optimism/superchain-registry/tree/main/docs) | Production | | [op-alloy](/app-developers/tools-sdks/op-alloy/intro) | Rust crates for interfacing with OP Stack chains: consensus, RPC, engine, and network types built on the [Alloy](https://github.com/alloy-rs/alloy) ecosystem; the type layer consumed by kona and op-reth | Optimism ([`rust/op-alloy`](https://github.com/ethereum-optimism/optimism/tree/develop/rust/op-alloy) in the monorepo) | [op-alloy docs](/app-developers/tools-sdks/op-alloy/intro) on this site | Developer preview (owner-declared not yet production-ready; APIs may change) | | [op-revm](/app-developers/tools-sdks/op-revm) | Rust crate implementing the OP Stack's EVM: a revm variant with deposit transactions, L1 and operator fee accounting, and OP-specific precompiles; the EVM inside op-reth and kona | Optimism ([`rust/op-revm`](https://github.com/ethereum-optimism/optimism/tree/develop/rust/op-revm) in the monorepo, vendored from upstream [`bluealloy/revm`](https://github.com/bluealloy/revm)) | [op-revm docs](/app-developers/tools-sdks/op-revm) on this site | Production (consumed transitively through op-reth or kona by most users) | ## Choose an SDK Surface Three of the rows above are TypeScript SDK surfaces that are easy to confuse. The distinction: * **Start with [`viem/op-stack`](https://viem.sh/op-stack).** viem provides first-class OP Stack support in the core library: extend any viem client with `publicActionsL2()` (and friends) imported from `viem/op-stack` to get deposits, withdrawals, and L1 gas estimation. If a feature is available here, this is its production home. Super Root withdrawal proving requires `viem` `2.51.0` or later. * **Reach for [`@eth-optimism/viem`](https://github.com/ethereum-optimism/ecosystem/tree/main/packages/viem) when you need what viem does not have yet.** The package's stated goal is to upstream as much as possible into viem itself; until then it is the home of Superchain interop actions and other pre-production features. The [interop tutorials](/app-developers/tutorials/interoperability/manual-relay) and [bridging tutorials](/app-developers/tutorials/bridging/cross-dom-bridge-erc20) on this site use it. * **Use the [Actions SDK](/app-developers/quickstarts/actions) for app-level building blocks, not chain plumbing.** Where the two viem surfaces expose protocol operations, the Actions SDK offers wallet, lend, and swap namespaces for building end-user apps. It is a developer preview and not yet ready for production use. Building in Rust rather than TypeScript? Start from [op-alloy](/app-developers/tools-sdks/op-alloy/intro) for OP Stack types and RPC surfaces and [op-revm](/app-developers/tools-sdks/op-revm) for execution, and see the [Stack Components index](/op-stack/components/index) for the Rust clients themselves (op-reth, kona-node, kona-client). ## Using wagmi With the OP Stack If you build with React, you likely start from wagmi — and it works with OP Stack chains out of the box. OP Stack chains are standard EVM chains, and `wagmi/chains` ships their definitions (`optimism`, `base`, `zora`, and every other chain from `viem/chains`). Nothing OP-specific is required for reads, writes, or wallet connections. For OP Stack–specific operations — deposits, withdrawals, interop — use the fact that wagmi is a wrapper over viem: 1. Get a viem client from wagmi with the [`useClient`](https://wagmi.sh/react/api/hooks/useClient) or [`useConnectorClient`](https://wagmi.sh/react/api/hooks/useConnectorClient) hooks, following wagmi's own [viem guide](https://wagmi.sh/react/guides/viem). 2. Extend that client with the [`viem/op-stack`](https://viem.sh/op-stack) actions and call them directly. For Superchain interop specifically, the experimental [`@eth-optimism/wagmi`](https://github.com/ethereum-optimism/ecosystem/tree/main/packages/wagmi) package provides React hooks (such as `useSendL2ToL2Message`) over `@eth-optimism/viem`. Treat it like its underlying package: experimental. ## Next Steps * Read the [listing criteria and maintenance-sweep policy](/app-developers/tools-sdks/listing-criteria) that govern this page. * Adding a chain rather than building an app? See [Join the Superchain Registry](/chain-operators/guides/join-superchain-registry). * For where content belongs in general, see the [content guide](/op-stack/contribute/content-guide). # Transferring ETH Source: https://docs.optimism.io/app-developers/tutorials/bridging/bridge-crosschain-eth Learn how to transfer ETH across the OP Stack interop cluster <Info>OP Stack interop is in active development. Some features may be experimental.</Info> <Info> This tutorial provides step-by-step instructions for how to send ETH from one chain in the OP Stack interop cluster to another. For a conceptual overview, see the [interoperable ETH explainer](/op-stack/interop/superchain-eth-bridge). </Info> ## Overview Crosschain ETH transfers across OP Stack chains are facilitated through the [SuperchainETHBridge](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/SuperchainETHBridge.sol) contract. This tutorial walks through how to send ETH from one chain to another. You can do this on [Supersim](/app-developers/tools-sdks/supersim) or production once it is released. ### What you'll build * A TypeScript application to transfer ETH between chains ### What you'll learn * How to send ETH on the blockchain and between blockchains * How to relay messages between chains ## Prerequisites Before starting this tutorial, ensure your development environment meets the following requirements: ### Technical knowledge * Intermediate TypeScript knowledge * Understanding of smart contract development * Familiarity with blockchain concepts ### Development environment * Unix-like operating system (Linux, macOS, or WSL for Windows) * Node.js version 16 or higher * Git for version control ### Required tools The tutorial uses these primary tools: * Foundry: For smart contract development * Supersim: For local blockchain simulation * TypeScript: For implementation * Viem: For blockchain interaction <Steps> <Step title="Install prerequisite software"> 1. Install [Foundry](https://book.getfoundry.sh/getting-started/installation). 2. Install [Node](https://nodejs.org/en). 3. Install [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git). The exact mechanism to do this depends on your operating system; most come with it preinstalled. </Step> <Step title="Configure the network"> You can run this tutorial either with [Supersim](/app-developers/tools-sdks/supersim) running locally, or using the [Interop devnet](/app-developers/guides/building-apps). Select the correct tab and follow the directions. <Tabs> <Tab title="Supersim"> 1. Follow [Install Supersim](/app-developers/tutorials/development/supersim/installation) to set up Supersim for running blockchains with Interop. 2. Start Supersim. ```sh theme={null} ./supersim --interop.autorelay ``` 3. Supersim uses Foundry's `anvil` blockchains, which start with ten prefunded accounts. Set these environment variables to access one of those accounts on the L2 blockchains. ```sh theme={null} export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 ``` 4. Specify the URLs to the chains. ```sh theme={null} SRC_URL=http://localhost:9545 DST_URL=http://localhost:9546 ``` <Accordion title="Sanity check"> Get the ETH balances for your address on both the source and destination chains. ```sh theme={null} cast balance --ether `cast wallet address $PRIVATE_KEY` --rpc-url $SRC_URL cast balance --ether `cast wallet address $PRIVATE_KEY` --rpc-url $DST_URL ``` </Accordion> </Tab> <Tab title="Interop Devnets"> 1. Set `PRIVATE_KEY` to the private key of an address that has [Sepolia ETH](https://cloud.google.com/application/web3/faucet/ethereum/sepolia). ```sh theme={null} export PRIVATE_KEY=0x <PRIVATE_KEY> ``` 2. Send ETH to the two L2 blockchains via their OptimismPortal contracts on Sepolia. ```sh theme={null} cast send --rpc-url https://endpoints.omniatech.io/v1/eth/sepolia/public --private-key $PRIVATE_KEY --value 0.02ether 0x7385d89d38ab79984e7c84fab9ce5e6f4815468a cast send --rpc-url https://endpoints.omniatech.io/v1/eth/sepolia/public --private-key $PRIVATE_KEY --value 0.02ether 0x55f5c4653dbcde7d1254f9c690a5d761b315500c ``` 3. Wait a few minutes until you can see the ETH [on the block explorer](https://sid.testnet.routescan.io/) for your address. 4. Specify the URLs to the chains. ```sh theme={null} SRC_URL=https://interop-alpha-0.optimism.io DST_URL=https://interop-alpha-1.optimism.io ``` <Accordion title="Sanity check"> Get the ETH balances for your address on both the source and destination chains. ```sh theme={null} cast balance --ether `cast wallet address $PRIVATE_KEY` --rpc-url $SRC_URL cast balance --ether `cast wallet address $PRIVATE_KEY` --rpc-url $DST_URL ``` </Accordion> </Tab> </Tabs> </Step> <Step title="Transfer ETH using Foundry"> Run these commands: ```sh theme={null} DST_CHAINID=`cast chain-id --rpc-url $DST_URL` MY_ADDRESS=`cast wallet address $PRIVATE_KEY` SUPERCHAIN_ETH_BRIDGE=0x4200000000000000000000000000000000000024 BEFORE=`cast balance $MY_ADDRESS --rpc-url $DST_URL | cast from-wei` cast send --rpc-url $SRC_URL --private-key $PRIVATE_KEY $SUPERCHAIN_ETH_BRIDGE "sendETH(address,uint256)" $MY_ADDRESS $DST_CHAINID --value 0.001ether sleep 10 AFTER=`cast balance $MY_ADDRESS --rpc-url $DST_URL | cast from-wei` echo -e Balance before transfer\\t$BEFORE echo -e Balance after transfer\\t$AFTER ``` </Step> <Step title="Create the TypeScript project"> <Note>Messages are relayed automatically in the interop devnet.</Note> <Steps> <Step title="Create a new TypeScript project"> ```sh theme={null} mkdir transfer-eth cd transfer-eth npm init -y npm install --save-dev -y viem tsx @types/node @eth-optimism/viem typescript mkdir src ``` </Step> <Step title="Download the SuperchainETHBridge ABI"> ```sh theme={null} curl https://raw.githubusercontent.com/ethereum-optimism/optimism/refs/heads/develop/packages/contracts-bedrock/snapshots/abi/SuperchainETHBridge.json > src/SuperchainETHBridge.abi.json ``` </Step> <Step title="Create src/transfer-eth.mts"> ```typescript theme={null} import { createWalletClient, http, publicActions, getContract, Address, formatEther, parseEther, } from 'viem' import { privateKeyToAccount } from 'viem/accounts' import { supersimL2A, supersimL2B, interopAlpha0, interopAlpha1 } from '@eth-optimism/viem/chains' import { walletActionsL2, publicActionsL2, contracts as optimismContracts } from '@eth-optimism/viem' import superchainEthBridgeAbi from './SuperchainETHBridge.abi.json' const supersimAddress = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`) const sourceChain = account.address === supersimAddress ? supersimL2A : interopAlpha0 const destinationChain = account.address === supersimAddress ? supersimL2B : interopAlpha1 const sourceWallet = createWalletClient({ chain: sourceChain, transport: http(), account, }).extend(publicActions) .extend(publicActionsL2()) .extend(walletActionsL2()) const destinationWallet = createWalletClient({ chain: destinationChain, transport: http(), account, }).extend(publicActions) .extend(publicActionsL2()) .extend(walletActionsL2()) const ethBridgeOnSource = await getContract({ address: optimismContracts.superchainETHBridge.address, abi: superchainEthBridgeAbi, client: sourceWallet, }) const reportBalance = async (address: string): Promise<void> => { const sourceBalance = await sourceWallet.getBalance({ address }) const destinationBalance = await destinationWallet.getBalance({ address }) console.log(` Address: ${address} Balance on source chain: ${formatEther(sourceBalance)} Balance on destination chain: ${formatEther(destinationBalance)} `) } console.log('Before transfer') await reportBalance(account.address) const sourceHash = await ethBridgeOnSource.write.sendETH({ value: parseEther('0.001'), args: [account.address, destinationChain.id], }) const sourceReceipt = await sourceWallet.waitForTransactionReceipt({ hash: sourceHash, }) console.log('After transfer on source chain') await reportBalance(account.address) const sentMessages = await sourceWallet.interop.getCrossDomainMessages({ logs: sourceReceipt.logs, }) const sentMessage = sentMessages[0] const relayMessageParams = await sourceWallet.interop.buildExecutingMessage({ log: sentMessage.log, }) const relayMsgTxnHash = await destinationWallet.interop.relayCrossDomainMessage(relayMessageParams) await destinationWallet.waitForTransactionReceipt({ hash: relayMsgTxnHash }) console.log('After relaying message to destination chain') await reportBalance(account.address) ``` </Step> </Steps> <Accordion title="Explanation of `transfer-eth.mts`"> ```typescript theme={null} import { supersimL2A, supersimL2B, interopAlpha0, interopAlpha1 } from '@eth-optimism/viem/chains' ``` Import all chain definitions from `@eth-optimism/viem`. ```typescript theme={null} const supersimAddress="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`) const sourceChain = account.address == supersimAddress ? supersimL2A : interopAlpha0 const destinationChain = account.address == supersimAddress ? supersimL2B : interopAlpha1 ``` If the address we use is `0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266`, one of the prefunded addresses on `anvil`, assume we're using Supersim. Otherwise, use Interop devnet. ```typescript theme={null} const sourceHash = await ethBridgeOnSource.write.sendETH({ value: parseEther('0.001'), args: [account.address, destinationChain.id] }) const sourceReceipt = await sourceWallet.waitForTransactionReceipt({ hash: sourceHash }) ``` To relay a message we need the information in the receipt. Also, we need to wait until the transaction with the relayed message is actually part of a block. ```typescript theme={null} const sentMessages = await sourceWallet.interop.getCrossDomainMessages({ logs: sourceReceipt.logs, }) const sentMessage = sentMessages[0] ``` A single transaction can send multiple messages. But here we know we sent just one, so we look for the first one in the list. ```typescript theme={null} const relayMessageParams = await sourceWallet.interop.buildExecutingMessage({ log: sentMessage.log, }) const relayMsgTxnHash = await destinationWallet.interop.relayCrossDomainMessage(relayMessageParams) ``` This is how you use `@eth-optimism/viem` to create an executing message. </Accordion> </Step> <Step title="Run the example"> 1. Run the example. ```sh theme={null} npx tsx src/transfer-eth.mts ``` 2. Read the results. ``` Before transfer Address: 0x7ED53BfaA58B79Dd655B2f229258C093b6C09A8C Balance on source chain: 0.020999799151902245 Balance on destination chain: 0.026999459226731331 ``` The initial state. Note that the address depends on your private key; it should be different from mine. ``` After transfer on source chain Address: 0x7ED53BfaA58B79Dd655B2f229258C093b6C09A8C Balance on source chain: 0.019999732176717961 Balance on destination chain: 0.026999459226731331 ``` After the initiating message the balance on the source chain is immediately reduced. Notice that even though we are sending 0.001 ETH, the balance on the source chain is reduced by a bit more (here, approximately 67 gwei). This is the cost of the initiating transaction on the source chain. Of course, as there has been no transaction on the destination chain, that balance is unchanged. ``` After relaying message to destination chain Address: 0x7ED53BfaA58B79Dd655B2f229258C093b6C09A8C Balance on source chain: 0.019999732176717961 Balance on destination chain: 0.027999278943880868 ``` Now the balance on the destination chain increases, by slightly less than 0.001 ETH. The executing message also has a transaction cost (in this case, about 180gwei). </Step> </Steps> ## Next steps * Check out the [SuperchainETHBridge guide](/op-stack/interop/superchain-eth-bridge) for more information. * Review the [OP Stack interop explainer](/op-stack/i
프로젝트로 돌아가기