> ## Documentation Index
> Fetch the complete documentation index at: https://docs.skale.space/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup Hardhat

> Guide to setting up Hardhat for SKALE development

## 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:

```shell theme={null}
mkdir my-skale-project
cd my-skale-project
npm init -y
```

## Step 2: Install Hardhat

Install Hardhat and its dependencies:

```shell theme={null}
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
```

<Note>
  The `@nomicfoundation/hardhat-toolbox` package includes all commonly used plugins and tools for Hardhat development.
</Note>

## Step 3: Initialize Hardhat

Initialize a Hardhat project:

```shell theme={null}
npx hardhat init
```

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:

```javascript theme={null}
require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: {
    version: "0.8.19",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
  },
  networks: {
    skale_testnet: {
      url: "https://base-sepolia-testnet.skalenodes.com/v1/jubilant-horrible-ancha",
      accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
      chainId: 324705682,
    },
    skale_mainnet: {
      url: "https://skale-base.skalenodes.com/v1/base",
      accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
      chainId: 1187947933,
    },
  },
  etherscan: {
    apiKey: {
      skale_testnet: "your-api-key", // Not required for Blockscout
    },
    customChains: [
      {
        network: "skale_testnet",
        chainId: 324705682,
        urls: {
          apiURL: "https://base-sepolia-testnet-explorer.skalenodes.com/api",
          browserURL: "https://base-sepolia-testnet-explorer.skalenodes.com",
        },
      },
      {
        network: "skale_mainnet",
        chainId: 1187947933,
        urls: {
          apiURL: "https://skale-base-explorer.skalenodes.com/api",
          browserURL: "https://skale-base-explorer.skalenodes.com",
        },
        },
      },
    ],
  },
};
```

<Note>
  Replace the RPC URLs with your specific SKALE Chain endpoint. You can find SKALE Chain endpoints in the [SKALE Portal](https://portal.skale.space).
</Note>

## Step 5: Install OpenZeppelin Contracts

Install OpenZeppelin Contracts:

```shell theme={null}
npm install @openzeppelin/contracts
```

## Step 6: Create Environment File

Create a `.env` file in your project root:

```env theme={null}
PRIVATE_KEY=your-private-key-here
```

<Warning>
  Never commit your `.env` file to version control. Add it to your `.gitignore` file.
</Warning>

Install dotenv package:

```shell theme={null}
npm install dotenv
```

Update your `hardhat.config.js` to load environment variables:

```javascript theme={null}
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

// ... rest of config
```

## Step 7: Create a Deployment Script

Create a deployment script in `scripts/deploy.js`. Run:

```shell theme={null}
touch scripts/deploy.js
```

Add the deployment code:

```javascript theme={null}
const hre = require("hardhat");

async function main() {
  const MyContract = await hre.ethers.getContractFactory("MyContract");
  const myContract = await MyContract.deploy();

  await myContract.waitForDeployment();

  console.log("Contract deployed to:", await myContract.getAddress());
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });
```

## Step 8: Compile Contracts

Compile your contracts:

```shell theme={null}
npx hardhat compile
```

## Step 9: Run Tests

Run your tests:

```shell theme={null}
npx hardhat test
```

## 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:
   ```javascript theme={null}
   networks: {
     skale_testnet: {
       url: "...",
       accounts: [...],
       gasPrice: 0, // SKALE has zero gas fees
     },
   },
   ```

3. **Contract Verification**: Verify contracts using Hardhat's verify plugin:
   ```shell theme={null}
   npx hardhat verify --network skale_testnet <CONTRACT_ADDRESS> <CONSTRUCTOR_ARGS>
   ```

## Project Structure

Your Hardhat project should look like this:

```
my-skale-project/
├── contracts/     # Smart contracts
├── scripts/       # Deployment scripts
├── test/          # Test files
├── hardhat.config.js
├── .env
└── package.json
```

## Related Topics

* [Setup Foundry](/cookbook/deployment/setup-foundry)
* [Solidity Quickstart](/developers/solidity-quickstart)
* [Troubleshooting](/developers/troubleshooting)
