The team of Matter Labs recently presented their vision for zkSync’s zkEVM, a trustless ZK Rollup enabling users to create and develop decentralized applications in a highly scalable Layer-2 environment. This system doesn’t require human operators to verify and finalize the transactions’ legitimacy. Instead, it relies on cryptographic mechanisms.
In a nutshell, this latest zkSync EVM is designed to allow Zero-Knowledge (ZK) proofs for any type of smart contract execution. It can easily take Ethereum’s top-notch security and decentralization to provide solutions with new functionality that verify proofs and expand user design space.
Moreover, the launch of the new zkEVM has become a vital turning point for the crypto industry. Over the last few years, the pace and development of the ZkSync ecosystem have taken another level of growth, beating even experts’ expectations. And due to the many research breakthroughs and revolutionary solutions provided by zkSync, Solidity programmers and developers now have access to the benefits of unmatched security, scaling, and UX of ZK proofs.
So, today let’s explore how to build and develop a smart contract on zkSync and the benefits of using this system for app development.
How to Deploy Smart Contracts on ZkSync? Step-by-Step Guide
Now let’s see what steps you need to follow to build and develop a smart contract on the network.
Building The zkSync L2 Blockchain
To build the L2 blockchain, follow the simple instructions below.
- Run a separate chain.
- For every block, you need to update the Merkle root in the Layer 1 Ethereum blockchain.
- As every transaction on the separate blockchain will have its own ZK proof, you can quickly validate it in the contract.
- After verifying all transactions, you can already check the new Merkle root and keep it in the L1 blockchain.
What’s notable is that ZK Rollups don’t need fraud-proof, unlike Optimistic rollups. It means users don’t have to rely on other operators. Instead, all transactions are always examined for validity.
ZkSync Smart Contract Deploying Process
Since Solidity programming language is supported, deploying contracts is pretty straightforward. You can use an already existing HardHat plugin for deploying smart contract codes on the new public testnet.
Step 1: Installing the Environment
At this stage, you will need to install all required software, including Node Package Manager and Docker.
- sudo apt install npm
Right after Node Package Manager is installed, you can check the current version of the package by filling in the following command.
- node -v
In case of any trouble, you can check out this detailed doc.
Step 2: Creating Smart Contract Project
You can move on to creating a project for your smart contract, once the software installation is completed.
All you need to do is to make a working folder and switch to it.
- cd zksync
- mkdir zksync
And create an npm project by following the command.
- npm init -y
Once done, all that remains is to install the needed npm packages.
Step 3: Developing The Smart Contract
At this stage, you can develop your smart contract. For that, you need to create a specific hardhat config file by following the command below.
- vim hardhat.config.ts
To switch vim, you can press the key <i> key.
After you create the hardhat config, you need to make folders for your future contract with these commands.
- mkdir contracts
- mkdir deploy
Then you can already create the Smart Contract file by filling in this line.
- vim contracts/Greeter.sol
Step 4: Opening a zkSync Account
You will need to create an account at the zkSync network and have some ETH in your wallet balance for deployment. On most EVM blockchains, developers need to deploy contract wallets for this purpose, as it will be easily supported with account abstraction. To get it done, you can follow the steps below.
- Open an account at MetaMask.
- Choose the Goerli Test Network and use its faucet to get some ETH.
- Transfer Ether to the zkSync network by using the zkSync bridge.
- Export the private key of your account.
Step 5: Creating Deploying File
To compile and deploy your smart contract source code, you will need to create a deployed file by following the command below.
- vim deploy/deploy.ts
Step 6: Deploying Smart Contract
After all the steps are done, you can deploy the smart contract to the network. To deploy the code of the smart contract, fill in the command line below.
- npx hardhat deploy-ZkSync.
If everything is right, you will see the contract address and be able to validate it at zkSync Block Explorer.
For more detailed instructions, you can also check out this zkSync Smart Contract Deployment Video Guide.
The Definition and Architecture of the ZKSync Network
Let’s first understand what zkSync is precisely and how it works.
ZkSync, powered by up-to-date ZK Rollup technology, is a trustless and permissionless protocol. Here, ZK stands for the term Zero-Knowledge, and Rollups act for smart contracts. These contracts have one purpose – roll up thousands of transactions off the main chain and merge them into a single transaction.
ZkSync, as an Ethereum scaling solution already running on the Ethereum Mainnet, provides low gas fees and swift transactions while preserving high safety using modern zero-knowledge proofs. As full schemes like state channels designed to scale Ethereum try to move essential data and computations off-chain, this can become a significant threat to overall security. Instead, zkSync eliminates this threat with the help of its hybrid L2 rollup solution.
In addition, the team of zkSync has created an impressive set of developer tools and a block explorer to allow users to spin off their own Layer-3.
FAQ
Deploying the contract on zkSync is actually just sending the details of a transaction carrying the code of the compiled contract without identifying the recipients.
Generally, contracts are immutable and can’t be altered once deployed.
The probability is very low. However, it is possible, if a hacker can exploit any security vulnerability in the written code.