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

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

Choose the Ethereum framework version v6 recommended

Choose the template to use Hardhat + Solidity recommended

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

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