> ## Documentation Index
> Fetch the complete documentation index at: https://l2docs.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.

<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: {
    whitechainTestnet: {
      type: "http",
      url: "https://rpc.testnet.whitechain.io",
      accounts: [process.env.PRIVATE_KEY!],
    },
  },
  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. The same submission also lands on [Sourcify](https://sourcify.dev), because both verifiers are enabled in the config above.

## Related

* [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)
