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

# Deploy with Hardhat

> Learn how to deploy and verify smart contracts on Whitechain Sepolia using the Hardhat development environment.

This page shows how to deploy and verify a contract on Whitechain Sepolia using Hardhat. Whitechain Sepolia is a standard EVM network, so you add it by chain ID and RPC URL. Hardhat needs no Whitechain-specific plugin. It is for developers who work from the command line.

Ready-made template: [**`Hardhat`**](https://github.com/whitechain-labs/templates/tree/main/Hardhat) in the Whitechain templates repository. The fastest path below clones it and deploys. The companion Foundry template is [**`Foundry`**](https://github.com/whitechain-labs/templates/tree/main/Foundry).

## Fastest path

The Hardhat template is a finished project for Whitechain Sepolia: the network is
configured, the contract and tests are in place, and the deploy script is written.
You need Node.js 22 or later and a funded key. The walkthrough after this section
builds the same project by hand, if you would rather see every step.

1. Get the `Hardhat` folder and install its dependencies.

   ```bash theme={null}
   npx degit whitechain-labs/templates/Hardhat whitechain-hardhat
   cd whitechain-hardhat
   npm install
   ```

2. Copy the environment file.

   ```bash theme={null}
   cp .env.example .env
   ```

   Set `PRIVATE_KEY` to a throwaway key funded from the [faucet](/learn/get-started/get-testnet-wbt). `TESTNET_RPC_URL` already points at the public endpoint. `npm run compile` and `npm test` both run before you fill anything in.

3. Deploy.

   ```bash theme={null}
   npm run deploy:testnet
   ```

   The script prints the deployed address and its explorer URL.

4. Verify, using the address from step 3.

   ```bash theme={null}
   npx hardhat verify --network whitechainSepolia <contract_address>
   ```

The template registers the network as `whitechainSepolia` (chain ID `1874`) and points verification at the Whitechain Blockscout explorer. Source: [whitechain-labs/templates](https://github.com/whitechain-labs/templates/tree/main/Hardhat).

<Note>
  Hardhat publishes its own Agent Skill for AI coding assistants. Install it with `npx skills add nomicfoundation/hardhat-skills` for AI-guided help with Hardhat 3 workflows and migrations. Pair it with the [whitechain-dev skill](/build-with-ai/claude-skills) for the Whitechain-specific steps below.
</Note>

## Before you deploy

* Node.js 22 or later and npm. Hardhat 3 requires Node.js 22 or newer.
* A funded testnet account. Claim test WBT from the [faucet](/learn/get-started/get-testnet-wbt).
* The private key for that account. Use a throwaway key for testing.

## 1. Create a project

```bash theme={null}
npm install --save-dev hardhat
npx hardhat --init
```

When prompted:

| Prompt | Response |
| - | - |
| Which version of Hardhat? | Choose **Hardhat 3 (recommended for new projects)** |
| Where would you like to initialize the project? | Press Enter for the current directory |
| What type of project? | Choose **A TypeScript Hardhat project using Node Test Runner and Viem** |
| Would you like to change `package.json` to turn your project into ESM? | Enter `y` |
| Confirm dependency installation? | Press Enter |

## 2. Set environment variables

```bash theme={null}
npm install --save-dev dotenv
```

Create a `.env` file:

```ini theme={null}
PRIVATE_KEY=0x_your_private_key_here
```

The key must include the `0x` prefix. Hardhat rejects the network configuration without it.

Add `.env` to `.gitignore` so you do not commit the key.

<Warning>
  Never commit a private key, and never reuse a mainnet key for testing. Anyone with the key controls the funds.
</Warning>

## 3. Configure the network

Replace the contents of `hardhat.config.ts` with:

```typescript theme={null}
import type { HardhatUserConfig } from "hardhat/config";
import hardhatToolboxViem from "@nomicfoundation/hardhat-toolbox-viem";
import "dotenv/config";

const config: HardhatUserConfig = {
  plugins: [hardhatToolboxViem],
  solidity: "0.8.30",
  networks: {
    whitechainSepolia: {
      type: "http",
      url: "https://rpc.testnet.whitechain.io",
      accounts: [process.env.PRIVATE_KEY!],
      chainId: 1874,
    },
  },
  verify: {
    sourcify: {
      enabled: true,
    },
  },
};

export default config;
```

## 4. Add a contract

Create `contracts/Storage.sol`.

```solidity theme={null}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.30;

contract Storage {
    uint256 number;

    function store(uint256 num) public {
        number = num;
    }

    function retrieve() public view returns (uint256) {
        return number;
    }
}
```

## 5. Add a deploy script

Create `scripts/deploy.ts`.

```typescript theme={null}
import { network } from "hardhat";

const { viem } = await network.create("whitechainSepolia");
const storage = await viem.deployContract("Storage");
console.log("Storage deployed to:", storage.address);
```

`network.create("whitechainSepolia")` opens a connection to the network defined in `hardhat.config.ts`. Passing the name makes the script explicit; `network.create()` with no argument uses whatever `--network` selects. Do not use `network.connect()`, which is deprecated in Hardhat 3 and will be removed. Hardhat 3 uses ESM with top-level `await`, so no `main()` wrapper is needed.

## 6. Deploy the contract

```bash theme={null}
npx hardhat run scripts/deploy.ts --network whitechainSepolia
```

The contract address prints to the console. Copy it for verification.

## 7. Verify the contract

`Storage` takes no constructor arguments, so pass only the address.

```bash theme={null}
npx hardhat verify --network whitechainSepolia <contract_address>
```

For a contract with constructor arguments, add them after the address.

## Verify the result

Open the contract address on the [explorer](https://explorer.testnet.whitechain.io). The Contract tab shows the source code and a verified marker. `hardhat verify` submits to every verifier configured for the network, so the same source also lands on [Sourcify](https://sourcify.dev).

<Note>
  If you deployed the `Storage` example unchanged, the explorer may show its source before you verify anything. That is a verified twin: the same bytecode is already verified at another address, so the explorer matches it. Hardhat then skips Blockscout and verifies only on Sourcify, and your address stays unverified in its own right. Record it with `npx hardhat verify blockscout --force --network whitechainSepolia <contract_address>`. Your own contracts have unique bytecode, so they have no twin and the plain command covers both verifiers.
</Note>

## Related

* [`Hardhat` template on GitHub](https://github.com/whitechain-labs/templates/tree/main/Hardhat)
* [Deploy a contract](/learn/get-started/deploy-a-contract)
* [Verify a proxy contract](/build/deploy/verify-proxy-contracts)
* [Agent Skills](/build-with-ai/claude-skills)
* [Hardhat Skills](https://github.com/NomicFoundation/hardhat-skills)
* [Connect to Whitechain Sepolia](/learn/get-started/connect-wallet)
* [Deploy with Remix](/build/deploy/deploy-with-remix)
* [Faucet](/learn/get-started/get-testnet-wbt)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.