Quickstart Guide to Develop on zkSync : Fundamental Concept and Development with ZKSync Remix IDE 'Instant Way' (Chapter 1)

The Ethereum network is often congested, leading to slow transactions and high gas fees. This problem has persisted for a long time, creating the need for a better solution: one that doesn't limit throughput but instead achieves a high transaction rate without sacrificing security. This is where Layer 2 solutions come in.
Layer 2 solutions are designed as extensions of Ethereum, offering various ways to alleviate network congestion. While covering all Layer 2 solutions is beyond the scope of this article, we will focus on explaining rollups.
What Are Rollups?
Rollups are a recent development aimed at increasing Ethereum's scalability by performing calculations off-chain, bundling many transactions into a single batch, and submitting it to the main Ethereum chain in one go. Instead of submitting each transaction separately, rollup operators submit a summary of the necessary changes to represent all transactions in a batch.
To work on a rollup, funds need to be locked in a smart contract on the Layer 1 blockchain. This allows transactions to be processed without the overhead of all the data associated with performing a transaction on the main chain. Rollups significantly decrease transaction processing times and gas fees.
Optimistic vs ZK Rollups
Currently, there are two types of rollups used to scale Ethereum:
ZK Rollups (Zero-Knowledge Rollups): Examples include zkSync, Loopring, Starknet, and Scroll.
Optimistic Rollups: Examples include Optimism and Arbitrum.
The main difference between ZK and Optimistic rollups is how the batch of transactions is finalized.
What Are ZK Rollups?
In ZK rollups, the batch of transactions is verified for correctness on the Ethereum network. Once verified, the batch is considered final, just like any other Ethereum transaction. This is achieved through cryptographic validity proofs (commonly called zero-knowledge proofs). For each batch of off-chain transactions, the ZK rollup operator generates a proof of validity. Once generated, this proof is submitted to Ethereum to finalize the rollup batch. In zkSync, this is done via a SNARK, which stands for succinct non-interactive argument of knowledge.
What Are Optimistic Rollups?
Optimistic rollups assume off-chain transactions are valid unless proven otherwise, hence the name "optimistic." They rely on fraud-proof systems, which challenge the submitted state to Ethereum. If a challenge is submitted, the Optimistic rollup operator must prove that the state and transactions in question are valid. This process is more cumbersome and requires watchers to ensure the operator's honesty at all times.
L1 and L2: What's the Difference?
Layer 1 (L1): Refers to the underlying primary blockchain, like Ethereum or Bitcoin. L1 blockchains set protocol rules, determine transaction finality, and handle the base-level functions of applications built on them.
Layer 2 (L2): Describes an overlaying application or network operating on top of the Layer 1 chain. L2 solutions provide scalability by taking on a portion of transaction-related tasks, reducing the load on the L1 chain, speeding up transaction times, and lowering gas fees.
Introduction to zkSync Era
zkSync Era is a ZK rollup, a trustless protocol using cryptographic validity proofs to offer scalable and low-cost transactions on Ethereum. In zkSync Era, computation and most data storage happen off-chain. Because all transactions are proven on the Ethereum main chain, users enjoy the same level of security as Ethereum.
zkSync Era is designed to feel like Ethereum but with lower fees. Smart contracts are written in Solidity/Vyper and can be called using the same clients as other EVM-compatible chains.
You don’t need to register a separate private key before using zkSync; it supports existing Ethereum wallets out of the box. Currently, zkSync is centralized, operated by the zkSync team’s servers, but it will transition to a decentralized system soon.
zkSync Operations
zkSync operations are divided into rollup transactions (initiated inside the rollup by a rollup account) and priority operations (initiated on the main chain by an Ethereum account). The lifecycle of zkSync rollup operations is:
A user creates a transaction or a priority operation.
The operator processes this request, creates a rollup operation, and adds it to the block.
Once the block is complete, the operator submits it to the zkSync smart contract as a block commitment. Part of the logic of some rollup operations is checked by the smart contract.
The proof for the block is submitted to the zkSync smart contract for verification. If verification succeeds, the new state is considered final.
Each L2 block progresses through the following stages until it is final:
Pending: The transaction was received by the operator but has not been processed yet.
Processed: The transaction is processed by the operator and confirmed to be included in the next block.
Committed: The transaction data of this block has been posted on Ethereum. This ensures the availability of the block data but does not prove it has been executed validly.
Finalized: The SNARK validity proof for the transaction has been submitted and verified by the smart contract. After this step, the transaction is considered final.
Start Development with Remix IDE : the Easy Way!
At this stage, we will learn how to use the Remix plugin created by nethermind for the zkSync ecosystem. The zkSync Era Remix Plugin offers a smooth and user-friendly interface for developers of all skill levels to engage with zkSync.
To get started, simply go to the Remix IDE and access the Plugin Manager. Then, search for 'zkSync IDE' and click activate.
Next, let's prepare the code that we will use for deployment. Here, I am using a sample code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleStorage {
uint256 private storedData;
function set(uint256 x) public {
storedData = x;
}
function get() public view returns (uint256) {
return storedData;
}
}
After that, click on the zkSync logo in the top-left corner and compile the code. Once the code is compiled, proceed with the deployment.
As a note, The zkSync Remix Plugin is currently in Alpha. Additionally, Solidity contracts are compiled on a server hosted by Nethermind.
For the environment, Nethermind provides several options:
You can choose to use our remote devnet, from which you’ll have access to 10 accounts to play around with. this one that we use.
Alternatively, you can do the same with a devnet you run on your machine! Use zksync-cli for this purpose.
You can also select the wallet you want to use as an account and interact with mainnet or a testnet. If you’re not interested in using your account for this, create a test account, fund it from the faucet, and deploy it.
After that, you can interact with the code through the Remix zkSync plugin:
set Function: This public function allows anyone to set the value of
storedData
.get Function: This public function allows anyone to retrieve the current value of
storedData
.
Deploy on zkSync Sepolia Testnet via Metamask Wallet
Of course, you can also deploy smart contracts on zkSync Sepolia in addition to using the devnet mentioned above.
You can connect Metamask to the zkSync Sepolia testnet using this link: https://chainlist.org/chain/300. Then, you will need to get faucet tokens. One website that provides them is learnweb3 faucet
After everything is set up successfully, simply change the environment from 'devnet' to 'wallet' then connect to your MetaMask and redeploy the previous smart contract.
After that, in the Transaction section, you can find the Transaction ID, which can be opened in a blockchain explorer : https://sepolia.explorer.zksync.io
Closing
Thank you for your support and interest in this series of articles, which is part of a grant program available at Wave Hacks on Akindo.
Structure :
Subscribe to my newsletter
Read articles from Ridho Izzulhaq directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
