Skip to main content

Setup Hardhat

Hardhat is a development environment for Ethereum software. It helps developers compile, deploy, test, and debug their Ethereum applications. This guide will help you set up Hardhat for developing on SKALE.

Prerequisites

  • Node.js (v16 or higher) installed
  • npm or yarn package manager
  • Basic knowledge of JavaScript/TypeScript

Step 1: Create a New Project

Create a new directory and initialize a Node.js project:

Step 2: Install Hardhat

Install Hardhat and its dependencies:
The @nomicfoundation/hardhat-toolbox package includes all commonly used plugins and tools for Hardhat development.

Step 3: Initialize Hardhat

Initialize a Hardhat project:
Select “Create a JavaScript project” (or TypeScript if preferred) and follow the prompts.

Step 4: Configure Hardhat for SKALE

Update your hardhat.config.js (or hardhat.config.ts) file:
Replace the RPC URLs with your specific SKALE Chain endpoint. You can find SKALE Chain endpoints in the SKALE Portal.

Step 5: Install OpenZeppelin Contracts

Install OpenZeppelin Contracts:

Step 6: Create Environment File

Create a .env file in your project root:
Never commit your .env file to version control. Add it to your .gitignore file.
Install dotenv package:
Update your hardhat.config.js to load environment variables:

Step 7: Create a Deployment Script

Create a deployment script in scripts/deploy.js. Run:
Add the deployment code:

Step 8: Compile Contracts

Compile your contracts:

Step 9: Run Tests

Run your tests:

SKALE-Specific Considerations

When deploying to SKALE with Hardhat:
  1. Transaction Type: Hardhat automatically handles transaction types, but ensure your Hardhat version supports legacy transactions if needed
  2. Gas Configuration: SKALE has zero gas fees, but you still need sFUEL for transactions:
  3. Contract Verification: Verify contracts using Hardhat’s verify plugin:

Project Structure

Your Hardhat project should look like this: