# How to deploy contract ZKSYNC ERA TESTNET.

By [wizard](https://paragraph.com/@wizardmain) · 2023-03-13

---

Today i will teach you how to deploy @zksync contract in ERA ZKSYNC TESNET.
---------------------------------------------------------------------------

![](https://storage.googleapis.com/papyrus_images/1ef9eabd5d7c4a5c9f7060e9dec62f6f761c7381aa4d879b991996b6d1f9cb92.png)

> \*1 Open [https://goerlifaucet.com/](https://goerlifaucet.com/) \*
> 
> _login/register from Alchemy and faucet some ETH Goerli._

> _2 Add ZKSync tesnet chain in your wallet_
> 
> [_https://chainlist.org/?testnets=true&search=zksync+era+testnet_](https://chainlist.org/?testnets=true&search=zksync+era+testnet)

> 3 \*Connect to official bridge [https://goerli.portal.zksync.io/bridge/withdraw](https://goerli.portal.zksync.io/bridge/withdraw) \*
> 
> _and bridge some funds in tesntet chain from goerli (Switch chain like on screen at right bottom corner)_

![Funds will moved in \~3 mins.](https://storage.googleapis.com/papyrus_images/a77edf53e039cef45424e8eb8436b0c5ca22f7f8250882ed225bf359113e9ae2.png)

Funds will moved in \\~3 mins.

> 4 _Open/Install_ **_Visual Studio Code_** _-_ [_https://code.visualstudio.com/_](https://code.visualstudio.com/) _and install extensions -_ **_Solidity, npm Intellisense_**

![](https://storage.googleapis.com/papyrus_images/2051d627123e306537c946869f934075b3e2bf20b09f780980265b6d332db2f4.png)

> _5 Create_ **_folder_** _and open from visual code._

> _6 Open_ **_terminal_** _and type this code:_
> 
>     npm init -y   
>     

> _7 Type next code:_
> 
>     npm i -D typescript ts-node ethers zksync-web3 hardhat @matterlabs/hardhat-zksync-solc @matterlabs/hardhat-zksync-deploy
>     

> _8 Create the_ `hardhat.config.ts` _file and paste the following code there:_
> 
>     import "@matterlabs/hardhat-zksync-deploy";
>     import "@matterlabs/hardhat-zksync-solc";
>     
>     module.exports = {
>       zksolc: {
>         version: "1.3.1",
>         compilerSource: "binary",
>         settings: {},
>       },
>       defaultNetwork: "zkSyncTestnet",
>     
>       networks: {
>         zkSyncTestnet: {
>           url: "https://zksync2-testnet.zksync.dev",
>           ethNetwork: "goerli", // Can also be the RPC URL of the network (e.g. `https://goerli.infura.io/v3/<API_KEY>`)
>           zksync: true,
>         },
>       },
>       solidity: {
>         version: "0.8.17",
>       },
>     };
>     

> _9 Create the_ `contracts` _and_ `deploy` _folders. The former is the place where we will store all the smart contracts'_ `*.sol` _files, and the latter is the place where we will put all the scripts related to deploying the contracts._

> _10 Create the_ `contracts/Greeter.sol` _contract and paste the following code in it:_
> 
>     //SPDX-License-Identifier: Unlicense
>     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;
>         }
>     }
>     

> _11 Compile the contract with the following command in_ **_terminal_**_:_
> 
>     npx hardhat compile
>     

> _12 Create the following deployment script in_ `deploy/deploy.ts`
> 
>     import { Wallet, utils } 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 you want to deploy.
>       const deployer = new Deployer(hre, wallet);
>       const artifact = await deployer.loadArtifact("Greeter");
>     
>       // Estimate contract deployment fee
>       const greeting = "Hi there!";
>       const deploymentFee = await deployer.estimateDeployFee(artifact, [greeting]);
>     
>       // OPTIONAL: Deposit funds to L2
>       // Comment this block if you already have funds on zkSync.
>       const depositHandle = await deployer.zkWallet.deposit({
>         to: deployer.zkWallet.address,
>         token: utils.ETH_ADDRESS,
>         amount: deploymentFee.mul(2),
>       });
>       // Wait until the deposit is processed on zkSync
>       await depositHandle.wait();
>     
>       // 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 parsedFee = ethers.utils.formatEther(deploymentFee.toString());
>       console.log(`The deployment is estimated to cost ${parsedFee} ETH`);
>     
>       const greeterContract = await deployer.deploy(artifact, [greeting]);
>     
>       //obtain the Constructor Arguments
>       console.log("constructor args:" + greeterContract.interface.encodeDeploy([greeting]));
>     
>       // Show the contract info.
>       const contractAddress = greeterContract.address;
>       console.log(`${artifact.contractName} was deployed to ${contractAddress}`);
>     }
>     

> _13 Replacing the_ `WALLET-PRIVATE-KEY` _with the private key of the Ethereum wallet you're using for development, and run the script using the following command to run the deployment script:_
> 
>     hardhat deploy-zksync
>     

> _14 Terminal gives you log like this_

![](https://storage.googleapis.com/papyrus_images/70fe79f4e7b5ce9bf4e06e501375f98b2eff41b6ba9d81308d6bd8b3f68118ee.png)

> _15 Copy address from “Greeter was deployed to_ **_ADDRESS HERE_**_“_

> _16 Open_ [_goerli.explorer.zksync.io_](http://goerli.explorer.zksync.io)_, past contract address and search it_

> _17 Click “_**_Contract_**_” and after click “_**_Verify contract_**_”._
> 
> _Name of contract -_ **_Greeter_**
> 
> \*Code contract copy from **step #10** \*
> 
> _And signature code copy from Visual Studio Code in last log from terminal (Its somethink like_
> 
>     constructor args:0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000005211241212657265210000000000000000000000000000000000000000000000
>     
> 
> _Click_ **_VERIFY_**_._

Congratulations! You have deployed a smart contract to zkSync Era Testnet 🎉
----------------------------------------------------------------------------

Follow me in twitter and DM your questions:

[https://twitter.com/wizardmain](https://twitter.com/wizardmain)

Official links of ZKSYNC:

[https://discord.gg/px2ar7w](https://discord.gg/px2ar7w)

[https://twitter.com/zksync](https://twitter.com/zksync)

[https://era.zksync.io/docs/](https://era.zksync.io/docs/)

---

*Originally published on [wizard](https://paragraph.com/@wizardmain/how-to-deploy-contract-zksync-era-testnet)*
