> ## Documentation Index
> Fetch the complete documentation index at: https://monadfoundation-40611fb6-devops-1498-direct-udp-implementat.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Hardhat

> Start a Hardhat 3 project for Monad or add Monad to an existing project.

[Hardhat 3](https://hardhat.org/docs) is a development environment for compiling, testing, deploying, and verifying smart contracts. You can start with the Monad template or add Monad to an existing Hardhat 3 project.

<Note>
  Hardhat 3 requires Node.js v22.13.0 or later.
</Note>

Choose one setup path:

* **New project:** Clone the Monad template and work inside the cloned repository.
* **Existing project:** Do not clone the template into your project. Merge only the configuration shown below into your existing `hardhat.config.ts`.

## Start with the Monad template

[The Monad Hardhat 3 template](https://github.com/monad-developers/hardhat3-monad) includes:

* Monad Testnet and Mainnet network configuration
* Foundry-compatible Solidity tests and TypeScript tests using `node:test`
* [Viem](https://viem.sh/) for TypeScript interactions
* [Hardhat Ignition](https://hardhat.org/ignition/docs/getting-started) deployment modules
* Sourcify and MonadScan contract verification

Clone and test the template:

```sh theme={null}
git clone https://github.com/monad-developers/hardhat3-monad.git
cd hardhat3-monad
npm install
npx hardhat test
```

See the template's [README](https://github.com/monad-developers/hardhat3-monad#readme) for local, Testnet, and Mainnet deployment commands.

## Configure an existing Hardhat 3 project

Merge the following compiler and network settings into your `hardhat.config.ts`. Keep any plugins and other project-specific settings already in the file.

```ts theme={null}
import { configVariable, defineConfig } from "hardhat/config";

export default defineConfig({
  solidity: {
    version: "0.8.31",
    settings: {
      evmVersion: "osaka",
    },
  },
  networks: {
    monadTestnet: {
      type: "http",
      url: "https://testnet-rpc.monad.xyz",
      accounts: [configVariable("PRIVATE_KEY")],
      chainId: 10143,
    },
    monadMainnet: {
      type: "http",
      url: "https://rpc.monad.xyz",
      accounts: [configVariable("PRIVATE_KEY")],
      chainId: 143,
    },
  },
});
```

<Warning>
  Never put a private key directly in `hardhat.config.ts` or commit it to version control. Provide `PRIVATE_KEY` through Hardhat's [configuration variable system](https://hardhat.org/docs/guides/configuration-variables), using the `PRIVATE_KEY` environment variable or the Hardhat keystore.
</Warning>

The `osaka` EVM target is required when compiling contracts for Monad, and Solidity 0.8.31 requires Hardhat 3.1.0 or later. For the canonical RPC URLs, chain IDs, and explorer URLs, see [Network Information](/developer-essentials/network-information) and [Network Information - Testnet](/developer-essentials/testnet).

Confirm the updated project still compiles and passes its tests:

```sh theme={null}
npx hardhat compile
npx hardhat test
```

## Deploy and verify

* [Deploy a Contract with Hardhat](/guides/deploy-smart-contract/hardhat)
* [Verify a Contract with Hardhat](/guides/verify-smart-contract/hardhat)
