Get started with Abstract by deploying your first smart contract using Hardhat.
This document outlines the end-to-end process of deploying a smart contract on Abstract using Hardhat.
It’s the ideal guide if you’re building a new project from scratch.
If you are on Windows, we strongly recommend using WSL 2 to follow this guide.
Inside an empty directory, initialize a new Hardhat project using
the Hardhat CLI:
Create a new directory and navigate into it:
Copy
mkdir my-abstract-project && cd my-abstract-project
Initialize a new Hardhat project within the directory:
Copy
npx hardhat init
Select your preferences when prompted by the CLI, or use the recommended setup below.
Recommended Hardhat setup
We recommend selecting the following options when prompted by the Hardhat CLI:
Copy
✔ What do you want to do? · Create a TypeScript project✔ Hardhat project root: · /path/to/my-abstract-project✔ Do you want to add a .gitignore? (Y/n) · y✔ Do you ... install ... dependencies with npm ... · y
Enter the private key of a new wallet you created for this step.
Copy
✔ Enter value: · ****************************************************************
Do NOT use a private key associated with real funds. Create a new wallet for this step.
2
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.
Write the deployment script
Create a new Hardhat script located at /deploy/deploy.ts:
Copy
mkdir deploy && touch deploy/deploy.ts
Add the following code to the deploy.ts file:
Copy
import { Wallet } from "zksync-ethers";import { HardhatRuntimeEnvironment } from "hardhat/types";import { Deployer } from "@matterlabs/hardhat-zksync";import { vars } from "hardhat/config";// 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`); // Initialize the wallet using your private key. const wallet = new Wallet(vars.get("DEPLOYER_PRIVATE_KEY")); // Create deployer object and load the artifact of the contract we want to deploy. const deployer = new Deployer(hre, wallet); // Load contract const artifact = await deployer.loadArtifact("HelloAbstract"); // Deploy this contract. The returned object will be of a `Contract` type, // similar to the ones in `ethers`. const tokenContract = await deployer.deploy(artifact); console.log( `${ artifact.contractName } was deployed to ${await tokenContract.getAddress()}` );}
Deploy your smart contract
Run the following command to deploy your smart contracts:
If successful, your output should look similar to the following:
Copy
Running deploy scriptHelloAbstract was deployed to YOUR_CONTRACT_ADDRESS
Verify your smart contract on the block explorer
Verifying your smart contract is helpful for others to view the code and
interact with it from a block explorer.
To verify your smart contract, run the following command: