zkSync Era | Deploy

A2 Finance
4 min readMay 8, 2023

--

zkSync is a ZK rollup, a trustless protocol that uses cryptographic validity proofs to provide scalable and low-cost transactions on Ethereum.

Project Information

Description

zkSync is a ZK rollup, a trustless protocol that uses cryptographic validity proofs to provide scalable and low-cost transactions on Ethereum. In zkSync, computation is performed off-chain and most data is stored off-chain as well. As all transactions are proven on the Ethereum mainchain, users enjoy the same security level as in Ethereum.

zkSync Era is made to look and feel like Ethereum, but with lower fees. Just like on Ethereum, smart contracts are written in Solidity/Vyper and can be called using the same clients as the other EVM-compatible chains.

zkSync raised $458M by Coinbase Ventures, a16z, Ethereum Foundation, ParaFi Capital, Coinfund and other.

Requirements

The following are minimum requirements to Deploy:

  • CPU: 2-cores
  • RAM: 4GB of memory
  • Storage: 30GB of disk space
  • Network: 10 Mbps of upload and download bandwidth
  • Software: Linux

We do not recommend using this method with your primary wallets. If you want to test the network and deploy primitive contract on zkSync Era, we recommend to create a new wallet with small amount of funds, not afraid of losing it.

Server Preparation

sudo apt-get update && sudo apt-get install -y
apt install curl -y
curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh
sudo bash /tmp/nodesource_setup.sh
sudo apt-get install -y nodejs
sudo apt-get install vim

Preparing for Deploy

npm init -y
npm install --save-dev hardhat
npm install -g npm@9.6.2
npx hardhat
  1. Press Create a TypeScript project
  2. Press Enter
  3. Press Y 3 times
mkdir greeter
cd greeter
npm init -y
npm add -D typescript ts-node @types/node ethers@^5.7.2 zksync-web3@^0.14.3 @ethersproject/hash @ethersproject/web hardhat @matterlabs/hardhat-zksync-solc @matterlabs/hardhat-zksync-deploy
vim hardhat.config.ts

Insert the following code:

import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-solc";

module.exports = {
zksolc: {
version: "1.3.6",
compilerSource: "binary",
settings: {},
},
defaultNetwork: "zkSyncMainnet",
networks: {
zkSyncMainnet: {
url: "https://zksync2-mainnet.zksync.io",
ethNetwork: "mainnet",
zksync: true,
},
},
solidity: {
version: "0.8.17",
},
};
  1. Press Esc
  2. Write :wq
  3. Press Enter
mkdir contracts
mkdir deploy
vim contracts/Greeter.sol

Insert the following code:

//SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.0;

contract Greeter {
string private greeting;

constructor(string memory _greeting) {
greeting = _greeting;
}

function greet() public view returns (string memory) {
return greeting;
}

function setGreeting(string memory _greeting) public {
greeting = _greeting;
}
}
  1. Press Esc
  2. Write :wq
  3. Press Enter
npx hardhat compile
vim deploy/deploy.ts
  1. Change <WALLET-PRIVATE-KEY> in the code to your own private key.
import { utils, Wallet } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";

// An example of a deploy script that will deploy and call a simple contract.
export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the Greeter contract`);

// Initialize the wallet.
const wallet = new Wallet("<WALLET-PRIVATE-KEY>");

// Create deployer object and load the artifact of the contract we want to deploy.
const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact("Greeter");

// Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`.
// `greeting` is an argument for contract constructor.
const greeting = "Hi there!";
const greeterContract = await deployer.deploy(artifact, [greeting]);

// Show the contract info.
const contractAddress = greeterContract.address;
console.log(`${artifact.contractName} was deployed to ${contractAddress}`);

// Call the deployed contract.
const greetingFromContract = await greeterContract.greet();
if (greetingFromContract == greeting) {
console.log(`Contract greets us with ${greeting}!`);
} else {
console.error(`Contract said something unexpected: ${greetingFromContract}`);
}

// Edit the greeting of the contract
const newGreeting = "Hey guys";
const setNewGreetingHandle = await greeterContract.setGreeting(newGreeting);
await setNewGreetingHandle.wait();

const newGreetingFromContract = await greeterContract.greet();
if (newGreetingFromContract == newGreeting) {
console.log(`Contract greets us with ${newGreeting}!`);
} else {
console.error(`Contract said something unexpected: ${newGreetingFromContract}`);
}
}

2. Paste the modified code into the console

3. Press Esc

4. Write :wq

5. Press Enter

Deploy

npx hardhat deploy-zksync

If you received this answer, then the contract has been deployed:

Greeter was deployed to … 
Contract greets us with Hi there!!
Contract greets us with Hey guys!

You can see deployed contract in explorer by putting your wallet address.

Useful Links

Official website of the project

Discord | Twitter | Blog

Docs | Explorer

--

--

A2 Finance

A2 Finance specialises in community building and development and everything connected with it.