> For the complete documentation index, see [llms.txt](https://pao.peerplays.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pao.peerplays.com/peerplays-2.0/solidity-smart-contracts/solidity-smart-contract-deployment-using-hardhat.md).

# Solidity smart contract deployment using hardhat

## Deployment Using Hardhat

There are three steps involved in the contract deployment using Hardhat,

1. Create a new Hardhat project
2. Configure Hardhat project with targeted blockchain
3. Compile and deploy

## Requirement specification

1. Visual Studio - VS code
2. Hardhat&#x20;

## Software Installation

**A) Setup the Hardhat environment in the VS code:**

Follow the step-by-step procedure explained in the tutorial provided by Hardhat,

{% embed url="<https://hardhat.org/hardhat-runner/docs/guides/project-setup>" %}
Guide to install Hardhat
{% endembed %}

Now, the VS code will be installed with Hardhat framework and ready to begin with smart contract deployment.

## Solidity Smart contract Deployment using Hardhat

The steps to deploy smart contract using Hardhat is explained below,

1. Login to the VS code environment which has the Hardhat framework installed with necessary files and folders to access.
2. Next, OpenZeppelin is an external library which should be present in VS code for contract deployment and it can be installed using below command:

```visual-basic
npm install @openzeppelin/contracts
```

<figure><img src="/files/2ddCIhPNWm02v3hLjLiB" alt=""><figcaption><p>File structure</p></figcaption></figure>

The **`TEST_ERC20.sol`** is the script provided by OpenZeppelin library to provide the desired minting value.

3. There are two files used for contract deployment&#x20;

&#x20;        **A.** hardhat\_config.ts - Config file

&#x20;        **B.** deploy\_config.ts - Deploy script

Example script structure is provided below:

The user has to provide the account's private key for **`accounts`** value in the **`hardhat_config`** file.&#x20;

{% code overflow="wrap" %}

```tsconfig
// Hardhat_config
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
  solidity: "0.8.19",
  defaultNetwork: 'peerplays',
  networks: {
    peerplays: {
      url: 'http://96.46.48.200:9933',
      accounts: [`0x` + process.env.PRIVATE_KEY], // Account's private key is added
      chainId: 33,
    },
  }
};

export default config;
```

{% endcode %}

Ethers library is provided by Ethereum and it has the necessary functions required for calls. Deploy script is required to deploy smart contract.&#x20;

{% code overflow="wrap" %}

```tsconfig
// Deploy_config
import { ethers } from "hardhat";

async function main() {

  const myToken = await ethers.deployContract("MyToken");

  await myToken.waitForDeployment();

  console.log(`MyToken deployed to: ${myToken.target}`) // Mention the Contract name used
}

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

{% endcode %}

4. The command to deploy contract is given below:

```
npx hardhat run scripts/deploy.ts
```

<figure><img src="/files/hYXG9el1siNoaSD7i3BA" alt=""><figcaption></figcaption></figure>

The contract address will be generated with deployment successful message.

Solidity smart contract deployment using Hardhat is successful! ✅


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://pao.peerplays.com/peerplays-2.0/solidity-smart-contracts/solidity-smart-contract-deployment-using-hardhat.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
