ZKsync 백서

ZKsync

원문

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

'https://zksync-os-testnet-alpha.staging-scan-v2.zksync.dev' , }, }, }); export const activeChain = import . meta .env. VITE_CHAIN === 'local' ? anvil : zksyncOSTestnet; export const config = import . meta .env. VITE_CHAIN === 'local' ? createConfig ({ chains: [anvil], connectors: [ injected ()], transports: { [anvil.id]: http (), }, }) : createConfig ({ chains: [zksyncOSTestnet], connectors: [ injected ()], transports: { [zksyncOSTestnet.id]: http (), }, }); Next, configure the wagmi and query client providers in src/main.tsx . import React from 'react' ; import ReactDOM from 'react-dom/client' ; import { QueryClient, QueryClientProvider } from '@tanstack/react-query' ; import { WagmiProvider } from 'wagmi' ; import App from './App' ; import { config } from './wagmi' ; import './index.css' ; const queryClient = new QueryClient (); ReactDOM. createRoot (document. getElementById ( 'root' ) ! ). render ( < React.StrictMode > < WagmiProvider config = {config} > < QueryClientProvider client = {queryClient} > < App /> </ QueryClientProvider > </ WagmiProvider > </ React.StrictMode > ); Replace src/App.tsx with the code below. App.tsx Create a .env file in the root of the token-frontend folder, add your deployed contract address as VITE_CONTRACT_ADDRESS , and set VITE_CHAIN to local . VITE_CONTRACT_ADDRESS=0x... VITE_CHAIN=local Finally you can start the development server. npm yarn pnpm bun npm run dev Add your local node to your browser wallet. Depending on what browser wallet you are using, the steps for this may be different. For Metamask, click on the top right menu bars, select "Networks", and then click on "Add a Custom Network". Enter the name "Anvil", http://localhost:8545 as the RPC URL, 31337 for the chain ID, and ETH as the currency symbol. Next, either import one of the rich wallets from anvil to your browser wallet using one of the private keys logged when starting the node, or use the command below to send some test ETH to your wallet. The cast CLI should already be installed through foundryup . cast send < 0x_YOUR_WALLET_ADDRES S > --value 1ether --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url http://localhost:8545 You can use the interact script in the previous step to send some tokens to your address if you need. Create a Vite Vue project. npm yarn pnpm bun npm create vite@latest token-frontend-vue -- --template vue-ts --no-interactive Move into the project folder and install the required packages. cd token-frontend-vue npm yarn pnpm bun npm install npm install @wagmi/vue viem@2.x @tanstack/vue-query Create file in the src folder called wagmi.ts and copy/paste the config below. import { createConfig, http, injected } from '@wagmi/vue' ; import { defineChain } from 'viem' ; import { anvil } from 'viem/chains' ; const zksyncOSTestnet = defineChain ({ id: 8022833 , name: 'ZKsync OS Developer Preview' , nativeCurrency: { name: 'Ether' , symbol: 'ETH' , decimals: 18 }, rpcUrls: { default: { http: [ 'https://zksync-os-testnet-alpha.zksync.dev' ] } }, blockExplorers: { default: { name: 'ZKsync OS Developer Preview Explorer' , url: 'https://zksync-os-testnet-alpha.staging-scan-v2.zksync.dev' , }, }, }); export const activeChain = import . meta .env. VITE_CHAIN === 'local' ? anvil : zksyncOSTestnet; export const config = import . meta .env. VITE_CHAIN === 'local' ? createConfig ({ chains: [anvil], connectors: [ injected ()], transports: { [anvil.id]: http (), }, }) : createConfig ({ chains: [zksyncOSTestnet], connectors: [ injected ()], transports: { [zksyncOSTestnet.id]: http (), }, }); Next, configure the wagmi plugin and query client in src/main.ts . import { QueryClient, VueQueryPlugin } from '@tanstack/vue-query' ; import { WagmiPlugin } from '@wagmi/vue' ; import { createApp } from 'vue' ; import App from './App.vue' ; import { config } from './wagmi' ; const app = createApp (App); const queryClient = new QueryClient (); app. use (VueQueryPlugin, { queryClient }); app. use (WagmiPlugin, { config }); app. mount ( '#app' ); Replace src/App.vue with the code below. App.vue Create a .env file in the root of the token-frontend-vue folder, add your deployed contract address as VITE_CONTRACT_ADDRESS , and set VITE_CHAIN to local . VITE_CONTRACT_ADDRESS=0x... VITE_CHAIN=local Finally you can start the development server. npm yarn pnpm bun npm run dev Add your local node to your browser wallet. Depending on what browser wallet you are using, the steps for this may be different. For Metamask, click on the top right menu bars, select "Networks", and then click on "Add a Custom Network". Enter the name "Anvil", http://localhost:8545 as the RPC URL, 31337 for the chain ID, and ETH as the currency symbol. Next, either import one of the rich wallets from anvil to your browser wallet using one of the private keys logged when starting the node, or use the command below to send some test ETH to your wallet. The cast CLI should already be installed through foundryup . cast send < 0x_YOUR_WALLET_ADDRES S > --value 1ether --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url http://localhost:8545 You can use the interact script in the previous step to send some tokens to your address if you need. Testing the frontend Now you can test the frontend by opening http://localhost:5173/ in your browser, connecting your wallet, checking the token metadata, and submitting a token transfer. Takeaways ZKsync chains after the Atlas upgrade are fully EVM-equivalent , meaning you can write smart contracts in Solidity or Vyper as in Ethereum and test apps with standard EVM tooling. You can use ZKsync's latest testnet, the ZKsync OS Developer Preview , to test your apps as you develop them. As you continue building with ZKsync, make sure to join our GitHub Discussions Community to ask questions, get help and help other devs building on ZKsync, or share your project. Interact with your contract Interact with your deployed contract using a script Elastic Network Chains Detailed list of all chains on the Elastic Network. ## /zksync-network/environment/l1-contracts ZKsync Docs L1 contracts L1 contract addresses The information about L1 smart contracts can be found in the protocol documentation . L1 Mainnet Contract Addresses DiamondInit: 0xb91d905A698c28b73C61aF60C63919b754FCF4DE DiamondProxy: 0x32400084c286cf3e17e7b677ea9583e60a000324 DiamondUpgrade: 0xe79a6d29bB0520648F25D11d65e29FB06B195F0F ExecutorFacet: 0xD059478a564dF1353A54AC0D0e7Fc55A90b92246 GettersFacet: 0xF3ACF6a03ea4a914B78Ec788624B25ceC37c14A4 Verifier: 0xB465882F67d236DcC0D090F78ebb0d838e9719D8 MailboxFacet: 0x63b5EC36B09384fFA7106A80Ec7cfdFCa521fD08 ValidatorTimelock: 0xa8cb082a5a689e0d594d7da1e2d72a3d63adc1bd AllowList: 0x0C0dC1171258694635AA50cec5845aC1031cA6d7 ZK Token: 0x66A5cFB2e9c529f14FE6364Ad1075dF3a649C0A5 Disclaimer: The ZK token contract address is provided for informational purposes only. Users should verify this address independently before interacting with it. Matter Labs makes no guarantees regarding the token's functionality, security, or value. This information is not investment advice. Users interact with the contract at their own risk. L1 Testnet Contract Addresses DiamondInit: 0x457701fDC6CaBc7D2EfB9b85f7faB0EE4bBD3c36 DiamondProxy: 0x9a6de0f62Aa270A8bCB1e2610078650D539B1Ef9 DiamondUpgrade: 0xA6b2731c08385782fBaCfCcD63D3c7fc7b798E47 ExecutorFacet: 0xe6cc1455217a8BBCF2c663607A0b8c200B8732F1 GettersFacet: 0x10f328c20dD2469b7e88f374B9794471599c1c8D Verifier: 0xf07ea72e071bc21612449570C365Ff3DC9176Ecb MailboxFacet: 0x2ed8eF54a16bBF721a318bd5a5C0F39Be70eaa65 ValidatorTimelock: 0x8CaC0a609A314E4161b8070cdEe065060B2486A1 AllowList: 0x7546a21cd4D74fc98Ef1A50145dfd8c043e2096F ZK Token: 0x2569600e58850a0aad61f7dd2569516c3d909521 Elastic Network Chains Detailed list of all chains on the Elastic Network. System contracts System contract addresses ## /zksync-network/environment/l2-contracts ZKsync Docs System contracts System contract addresses Addresses for L2 system contracts are the same on any chain powered by the ZK protocol. The addresses, as well as an overview of the system contract functionality, can be found in the protocol description . L1 contracts L1 contract addresses Overview Learn about how ZKsync Connect enables interoperable ZKsync chains. ## /zksync-network/zksync-connect ZKsync Docs Overview Learn about how ZKsync Connect enables interoperable ZKsync chains. ZKsync Connect enables interoperability across ZKsync chains in the Elastic Network. Interop, or interoperability, is a way to communicate and transact between two ZK Stack chains, or between a ZK Stack chain and Ethereum L1. It is made possible by smart contracts that verify transactions across chains using Merkle proofs. It allows you to: Observe messages : Track when an interop message (think of it as a special event) is created on the source chain. Send assets: Transfer ERC20 tokens and other assets between chains. Execute calls: Call a contract on another ZKsync chain or Ethereum L1 with specific calldata and value. Execute bundles of calls atomically: Group multiple remote calls into a single bundle, ensuring all of them execute at once. Control shadow accounts: Manage smart accounts on other chains, including L1, to execute transactions and manage assets without needing a local account on that chain. Enhanced user experience Interoperability enhances the blockchain user experience by abstracting complex cross-chain interactions. Users do not need to manually bridge funds to another chain in the Elastic Network if they already have funds on one. Reduced Complexity : Users interact with a seamless interface that hides the underlying complexities of blockchain operations. Asset Bridging : Relayers manage the process of bridging assets between chains, handling the necessary burning and minting of assets as they move across the ecosystem. Lower Fees : By leveraging efficient relayers and minimizing manual operations, transaction costs are kept low, akin to standard gas fees within a single chain. Real-World Application: Crosschain Transactions Consider a practical scenario where you want to swap ETH for DAI using a crosschain transaction on a defi platform: Transaction Initiation : You initiate the transaction directly from your wallet. Relayer Involvement : A relayer picks up your ETH and deposits it into the defi chain. Asset Swap : On the defi chain, your ETH is automatically swapped for DAI. Completion and Return : The relayer then transfers the DAI back to your original chain. This entire process is executed as a single transaction, making it feel as seamless as if no chain-switching occurred. The only difference a user might notice is a slightly longer confirmation time, depending on the specific ZKsync chain used. Transaction Lifecycle An interop transaction in the Elastic Network follows these steps: Initiation : A transaction is initiated on a ZKsync chain, aimed at crossing to another chain within the Elastic Network. Settlement on L1 : The sending ZKsync chain compiles a cryptographic proof of the transaction and settles it onto Ethereum's Layer 1, anchoring the transaction's validity. Interop Root Update : The shared interop/message root gets updated to include the source chain's new message root. Root Importation : The receiving ZKsync chain imports this updated interop root through its consensus mechanism. Bundle Submission : A relayer submits the bundle together with a message inclusion proof to the receiving ZKsync chain. This proof connects the bundle message to the imported interop root. Verification and Execution : The receiving ZKsync chain verifies the bundle message against the interop root. If the verification is successful, the transaction is executed, and the relayer is compensated for their service. Proof Settlement : Finally, the receiving ZKsync chain settles its proof on L1, conclusively validating the transaction within the Elastic Network. Rollout Phases There are three steps planned for rolling out full interoperability: Messaging Atomic Asset transfers , and transaction bundles Automatic crosschain transactions, L1 interop, and shadow accounts. Messaging is already available on all ZKsync chains. System contracts System contract addresses Transaction Bundles Learn about how transaction bundles work. ## /zksync-network/zksync-connect/transaction-bundles ZKsync Docs Transaction Bundles Learn about how transaction bundles work. Transaction bundles are not yet live on any mainnet or testnet chains. They will be added in a future protocol upgrade. What are transaction bundles? Transaction bundles are a group of transactions that can be sent from one ZKsync chain (the origin chain) to another ZKsync chain (the destination chain) to be executed on the destination chain. The transactions in the bundle are executed one after another in the order they are sent. They can be configured so that only a specific address can execute the bundle, or any address can. Bundles are not executed automatically, but this feature will be enabled in a future upgrade. Can any contract be called? To call a contract with a transaction bundle, the contract must support the receiveMessage interface. function receiveMessage ( bytes32 , // message id bytes calldata , // ERC-7930 sender bytes calldata payload // bundle payload ) external payable returns ( bytes4 ) { If a contract does not have a receiveMessage function, you must use an adapter contract as an intermediary. You can see an example of an adapter contract for a counter contract below: CounterAdapter.sol How can I send a transaction bundle? The basic steps of using bundles are: Construct a bundle. Send the bundle. Execute the bundle on the destination chain. The InteropCenter contract is used to send bundles. The InteropHandler contract is used to finalize and execute bundles. Lifecycle of a bundle Bundle creation: The sender builds an InteropBundle with a destination chain, one or more calls, and bundle attributes such as the execution address, unbundler address, and fee mode. Bundle submission: The sender calls InteropCenter.sendBundle on the source chain. The contract validates the destination chain, processes the call starters, collects the required fees, and emits the bundle as an L2 to L1 message. Interop root update: The bundle message is included in the shared interop root for that chain. Root importation: The destination chain imports the relevant interop root, making the bundle message provable there. Proof submission: A relayer submits the ABI-encoded bundle and its MessageInclusionProof to InteropHandler on the destination chain. Bundle verification: InteropHandler checks that the proof matches the source chain, destination chain, and bundle contents, then marks the bundle as Verified . Bundle execution: InteropHandler.executeBundle calls each destination contract's receiveMessage function in order. If every call succeeds, the bundle is executed atomically and marked as FullyExecuted . Optional unbundling: If the bundle is verified but cannot be fully executed as one atomic operation, the authorized unbundler can use unbundleBundle to execute or cancel calls individually. sendBundle Details The interface for sending a bundle via the InteropCenter contract looks like this: function sendBundle ( bytes calldata _destinationChainId, InteropCallStarter [] calldata _callStarters, bytes [] calldata _bundleAttributes ) external payable returns ( bytes32 bundleHash ); The function returns the hash of the sent bundle. There are three input arguments: _destinationChainId : An ERC-7930 address that MUST have an empty address field, and encodes an EVM destination chain ID to send the bundle to. _callStarters : An array of InteropCallStarter structs. _bundleAttributes : A bytes array for the bundle's attributes. Interop Call Starters An interop call starter represents a transaction to be included in the bundle. An interop call starter struct looks like this: struct InteropCallStarter { bytes to; bytes data; bytes [] callAttributes; } It contains three fields: to : the ERC-7930 address to call on the destination chain. The address must have empty ChainReference . This is due to the fact that chain ID is always provided on a bundle level as the destination chain ID. data : The calldata payload to send to the to address on the destination chain. callAttributes : The EIP-7786 attributes. Attributes are structured metadata. Call Attributes The call attributes describe how a call inside a bundle should be executed on the destination chain. struct CallAttributes { uint256 interopCallValue; bool indirectCall; uint256 indirectCallMessageValue; } A CallAttributes struct includes: interopCallValue : The base token value on destination chain to send for an interop call. indirectCall : If the call is direct or not. An indirect call first calls a contract specified by the call starter, which then returns an actual call starter that is used to form an interop call. In particular, this is used for interop token transfers. In contrast, a direct call uses the call starter to form an interop call. indirectCallMessageValue : The base token value on the origin chain to send for an indirect call. Bundle Attributes The information in the bundle attributes decides three things: If anyone can execute the bundle on the destination chain, or only some specific address. What address can unbundle the bundle. What fee mode is used when the bundle is sent. A BundleAttributes struct looks like this: struct BundleAttributes { bytes executionAddress; bytes unbundlerAddress; bool useFixedFee; } The executionAddress can either be empty or an ERC-7930 address. If the byte array is empty then execution is permissionless. The unbundlerAddress must be an ERC-7930 address. If the unbundler is not set for a bundle, the InteropCenter contract sets the unbundler to be equal to the original sender. useFixedFee selects the fee mode for the bundle. If true , the sender pays the fixed interop fee in ZK tokens. If false , the sender pays the dynamic per-call fee in the source chain's base token. If the attribute is omitted, it defaults to false . executeBundle Details Bundles are executed atomically, which means that if any call in the bundle fails, every call in the bundle is reverted. function executeBundle ( bytes memory _bundle, MessageInclusionProof memory _proof) external ; There are two input arguments for executeBundle : _bundle : the ABI-encoded InteropBundle to execute. This must match exactly the bundle that is sent in sendBundle . _proof : The inclusion proof for the bundle message. The bundle message itself gets broadcasted by the InteropCenter contract when the bundle was sent. Getting the status of a bundle Once a bundle is sent, its status can be queried from the InteropHandler contract using the bundle hash. function bundleStatus ( bytes32 bundleHash ) external view returns ( BundleStatus ); A bundle can have four different statuses: enum BundleStatus { Unreceived , Verified , FullyExecuted , Unbundled } Unreceived : The bundle is not processed in any way yet. Verified : The bundle's inclusion proof was accepted, but the bundle is not processed or executed. FullyExecuted : All calls in the bundle have been executed via executeBundle . Unbundled : Bundle was processed, but not executed. This can happen if a bundle is attempted to be executed but one o
프로젝트로 돌아가기