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

# Deploy a smart contract on Monad using Hardhat

[Hardhat](https://hardhat.org/docs) is a comprehensive development environment consisting of different components for editing, compiling, debugging, and deploying your smart contracts.

## Requirements

Before you begin, you need to install the following dependencies:

* Node.js v18.0.0 or later

<Note>
  If you are on Windows, we strongly recommend using [WSL 2](https://learn.microsoft.com/en-us/windows/wsl/about) when following this guide.
</Note>

<Warning>
  When deploying to Monad, set `evmVersion: "prague"` in your Hardhat Solidity compiler settings. For example:

  ```ts theme={null}
  solidity: {
    version: "0.8.28",
    settings: {
      evmVersion: "prague",
    },
  },
  ```
</Warning>

<Tabs>
  <Tab title="Hardhat 2">
    ## 1. Create a new Hardhat project

    <Tip>
      You can use the `hardhat-monad` template to create a new project with Monad configuration already set up.

      *[hardhat-monad](https://github.com/monad-developers/hardhat-monad) is a Hardhat template with Monad configuration.*
    </Tip>

    Clone the repository to your machine using the command below:

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

    ## 2. Install dependencies

    ```sh theme={null}
    npm install
    ```

    ## 3. Create an .env file

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

    Edit the `.env` file with your private key:

    ```
    PRIVATE_KEY=your_private_key_here
    ```

    <Warning>
      Protect your private key carefully. Never commit it to version control, share it in public repositories, or expose it in client-side code. Your private key provides full access to your funds.
    </Warning>

    ## 4. Deploy the smart contract

    The following commands use [Hardhat Ignition](https://hardhat.org/ignition/docs/getting-started#overview):

    ### Deploying to the local hardhat node

    Run hardhat node by running:

    ```bash theme={null}
    npx hardhat node
    ```

    To deploy the example contract to the local hardhat node, run the following command in a separate terminal:

    ```bash theme={null}
    npx hardhat ignition deploy ignition/modules/Counter.ts
    ```

    ### Deploying to Monad Testnet

    Ensure your private key is set in the `.env` file.

    Deploy the contract to Monad Testnet:

    ```bash theme={null}
    npx hardhat ignition deploy ignition/modules/Counter.ts --network monadTestnet
    ```

    Redeploy the same code to a different address:

    ```bash theme={null}
    npx hardhat ignition deploy ignition/modules/Counter.ts --network monadTestnet --reset
    ```

    ### Deploying to Monad Mainnet

    Ensure your private key is set in the `.env` file.

    Deploy the contract to Monad Mainnet:

    ```bash theme={null}
    npx hardhat ignition deploy ignition/modules/Counter.ts --network monadMainnet
    ```

    Redeploy the same code to a different address:

    ```bash theme={null}
    npx hardhat ignition deploy ignition/modules/Counter.ts --network monadMainnet --reset
    ```
  </Tab>

  <Tab title="Hardhat3">
    ## 1. Create a new Hardhat3 project

    <Tip>
      You can use the `hardhat3-monad` template to create a new project with Monad configuration already set up for Hardhat3.

      *[hardhat3-monad](https://github.com/monad-developers/hardhat3-monad) is a Hardhat3 template with Monad configuration.*

      To learn more about Hardhat3, please visit the [Getting Started guide](https://hardhat.org/docs/getting-started#getting-started-with-hardhat-3).
    </Tip>

    Clone the repository to your machine using the command below:

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

    ## 2. Install dependencies

    ```sh theme={null}
    npm install
    ```

    ## 3. Set up your private key

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

    ```sh theme={null}
    PRIVATE_KEY=your_private_key_here
    ETHERSCAN_API_KEY=your_etherscan_api_key_here
    ```

    <Warning>
      Protect your private key carefully. Never commit your `.env` file or expose your private key. Your private key provides full access to your funds.
    </Warning>

    ## 4. Deploy the smart contract

    The following commands use [Hardhat Ignition](https://hardhat.org/ignition/docs/getting-started#overview):

    ### Deploying to a local chain

    ```bash theme={null}
    npx hardhat ignition deploy ignition/modules/Counter.ts
    ```

    ### Deploying to Monad Testnet

    Ensure your `.env` file is set up with your private key.

    ```bash theme={null}
    npx hardhat ignition deploy ignition/modules/Counter.ts --network monadTestnet
    ```

    ### Deploying to Monad Mainnet

    Ensure your `.env` file is set up with your private key.

    ```bash theme={null}
    npx hardhat ignition deploy ignition/modules/Counter.ts --network monadMainnet
    ```
  </Tab>
</Tabs>

## Next Steps

Check out [how to verify the deployed smart contract on MonadVision](/guides/verify-smart-contract/hardhat).
