Deploying Contract

Deploying and compiling the contract is different for the zkSync Hyperchain. Here we discuss the steps to deploy your first contract in the zkSync Hyperchain network.

Step 1: Get the RPC URL - Follow the instructions in RPC Access to get the RPC endpoints

Step 2: Get Explorer URL - In the network overview page in the top right corner, you can see an explorer button. it will open the explorer URL.

Step 3: Create a zkSync project - create a zkSync project with the help of zkSync-cli.

# initialize the project with
npx zksync-cli create contract-deploy
project step 1

Select the contracts in the type of project to deploy the contract

project step 2

Choose the Ethereum framework version v6 recommended

project step 3

Choose the template to use Hardhat + Solidity recommended

project step 4

Enter your private key which has enough tokens in the zkSync Hyperchain (l2 network) for the gas price.

project step 5

Choose one package manager to manage the project dependency npm recommended. It will start cloning and setting up the environment

Step 4: Changing config values - Once the project setup is done. change the directory to the project directory and install all the dependency

# changing directory
cd contract-deploy
# install packages
npm i

Change the hardhat.config.ts file in the root of the project, replace the URL of your Rpc with url variable and your explorer URL with /contract_verification appended in the end with the verifyURL variable in the zkSyncSepoliaTestnet object.

Step 5: Compile and deploy your contract - To compile the contract you need to run the command listed below. It will compile all the contracts in the /contracts directory. deploy command will only deploy the Greeting.sol contract to the blockchain.

# to compile
npm run compile
# to deploy
npm run deploy

Step 6: Interacting with the contract - once it is deployed copy the contract address from the logs, you can see in the below screenshot 0x71Ae38d9b09716a4D7d7EB6bcA392710Cbf4cd66

Replace this address in the /deploy/interact.ts file in the CONTRACT_ADDRESS variable. save it and run the command for interacting with the contract

# to interact
npm run interact

You will see output something like this, you can modify and play around with the /deploy/interact.ts to interact with the contract with different values.

Last updated

Was this helpful?