Hardhat
Learn how to use Hardhat to build and deploy smart contracts on Abstract.
YouTube Tutorial: Get Started with Hardhat
Watch a step-by-step tutorial on how to get started with Hardhat.
1. Create a new project
Inside an empty directory, initialize a new Hardhat project using the Hardhat CLI:
Create a new directory and navigate into it:
Initialize a new Hardhat project within the directory:
Select your preferences when prompted by the CLI, or use the recommended setup below.
2. Install the required dependencies
Abstract smart contracts use different bytecode than the Ethereum Virtual Machine (EVM).
Install the required dependencies to compile, deploy and interact with smart contracts on Abstract:
- @matterlabs/hardhat-zksync: A suite of Hardhat plugins for working with Abstract.
- @matterlabs/zksync-contracts: Access system contracts and other utilities.
- zksync-ethers: Recommended package for writing Hardhat scripts to interact with your smart contracts.
3. Modify the Hardhat configuration
Update your hardhat.config.ts
file to include the following options:
Using system contracts
To use system contracts,
set the enableEraVMExtensions
flag to true:
4. Write a smart contract
Rename the existing contracts/Lock.sol
file to contracts/HelloAbstract.sol
:
Write a new smart contract in the contracts/HelloAbstract.sol
file, or use the example smart contract below:
5. Compile the smart contract
Clear any existing artrifacts:
Use the zksolc compiler (installed in the above steps) to compile smart contracts for Abstract:
You should now see the compiled smart contracts in the generated artifacts-zk
directory.
6. Deploy the smart contract
Add your private key
Create a new configuration variable
called DEPLOYER_PRIVATE_KEY
.
Enter the private key of a new wallet you created for this step.
Write the deployment script
Create a new Hardhat script located at /deploy/deploy.ts
:
Add the following code to the deploy.ts
file:
Deploy your smart contract
Run the following command to deploy your smart contracts:
If successful, your output should look similar to the following:
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:
Note: Replace YOUR_CONTRACT_ADDRESS
with the address of your deployed smart contract.
If successful, your output should look similar to the following:
Was this page helpful?