The zksync-ethers package provides a modified version of the ethers library that is compatible with Abstract and the ZKsync VM. Install the package by running the following command:
Copy
npm install -D zksync-ethers
3
Write test definitions
Write test definitions inside the /test directory, for example, test/HelloWorld.test.ts.
test/HelloWorld.test.ts
Copy
import * as hre from "hardhat";import { expect } from "chai";import { Deployer } from "@matterlabs/hardhat-zksync";import { Wallet, Provider, Contract } from "zksync-ethers";import { vars } from "hardhat/config";describe("HelloWorld", function () { let helloWorld: Contract; beforeEach(async function () { const provider = new Provider(hre.network.config.url); const wallet = new Wallet(vars.get("DEPLOYER_PRIVATE_KEY"), provider); const deployer = new Deployer(hre, wallet); const artifact = await hre.deployer.loadArtifact("HelloWorld"); helloWorld = await deployer.deploy(artifact); }); it("Should return the correct initial message", async function () { expect(await helloWorld.getMessage()).to.equal("Hello World"); }); it("Should set a new message correctly", async function () { await helloWorld.setMessage("Hello Abstract!"); expect(await helloWorld.getMessage()).to.equal("Hello Abstract!"); });});
4
Add a deployer private key
Create a new configuration variable called DEPLOYER_PRIVATE_KEY that contains the private key of a wallet you want to deploy the contract from.
Copy
npx hardhat vars set DEPLOYER_PRIVATE_KEY
Enter the private key of a new wallet you created for this step.
Copy
✔ Enter value: · ****************************************************************
Use one of the rich wallets as the DEPLOYER_PRIVATE_KEY when using a local node.
5
Get ETH in the deployer account
The deployer account requires ETH to deploy a smart contract.
Testnet: Claim ETH via a faucet, or
bridge ETH from Sepolia.
Mainnet: Use a bridge to transfer ETH to Abstract mainnet.
Add the local node as a network in your Hardhat configuration file:
hardhat.config.ts
Copy
networks: { // ... Existing Abstract networks inMemoryNode: { url: "http://127.0.0.1:8011", ethNetwork: "localhost", // in-memory node doesn't support eth node; removing this line will cause an error zksync: true, },},
3
Update the deployer private key configuration variable
Update the DEPLOYER_PRIVATE_KEY configuration variable to use one of the pre-funded rich wallet private keys.