> For the complete documentation index, see [llms.txt](https://docs.pharos.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pharos.xyz/developer-guide/hardhat/write-your-first-nft.md).

# Write Your First NFT

### Prerequisites

Before you begin, ensure you have the following:

* Git: Used for code management and obtain examples.
* Node.js: Install it from [nodejs.org](https://nodejs.org/).
* Pharos Devnet/Testnet Access: Access to a Pharos node (local or remote) for interacting with the blockchain.

### Setup 1: Install Hardhat

* [Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#installation)

### Setup 2: Set Up the Project

Clone the example repo:

```shell
git clone https://github.com/PharosNetwork/examples
cd examples/nft/hardhat/contract
```

Install OpenZeppelin Contracts:

```shell
npm install
```

### Setup 3: Write the NFT Contract

Create a New Solidity File:

* Create a new file for your NFT contract:

```shell
touch contracts/Token.sol
```

Write the Token Contract:

* Open `contracts/Token.sol` in your favorite text editor and add the following code:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract Token is ERC721 {
    uint256 id;
    constructor() ERC721("Token", "MTK") {}

    function mint(address to) public returns (uint256) {
        id += 1;
        _mint(to, id);
        return id;
    }
}
```

Compile the Smart Contract:

```shell
npx hardhat compile
```

Test the Smart Contract

```shell
npx hardhat test
```

### Step 4: Deploy the Token Contract

Set the private key:

```shell
npx hardhat vars set PRIVATE_KEY
```

Deploy the Contract:

```shell
npx hardhat ignition deploy ./ignition/modules/Token.js --network pharos
```

### Step 5: Verify the Token Contract

Add the following content to your `hardhat.config.js` file

* For Atlantic Testnet

| Field         | Value                                                                                  |
| ------------- | -------------------------------------------------------------------------------------- |
| chain\_name   | pharos                                                                                 |
| chain\_id     | 688689                                                                                 |
| rpc\_endpoint | <https://atlantic.dplabs-internal.com>"                                                |
| api\_host     | <https://api.socialscan.io/pharos-atlantic-testnet/v1/explorer/command\\_api/contract> |
| explorer\_url | <https://atlantic.pharosscan.xyz/>                                                     |

```js
require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.28",
  networks: {
    pharos: {
      url: "https://atlantic.dplabs-internal.com",
      accounts: [vars.get("PRIVATE_KEY")],
    },
  },
  etherscan: {
    customChains: [
      {
        network: "pharos",
        chainId: 688689,
        urls: {
          apiURL: "https://api.socialscan.io/pharos-atlantic-testnet/v1/explorer/command_api/contract",
          browserURL: "https://atlantic.pharosscan.xyz/",
        },
      },
    ],
    apiKey: {
      pharos: "Put a random string", // Note we don't need a apiKey here, just leave a random string
    },
  }
};
```

* For Testnet

| Field         | Value                                                                         |
| ------------- | ----------------------------------------------------------------------------- |
| chain\_name   | pharos                                                                        |
| chain\_id     | 688688                                                                        |
| rpc\_endpoint | <https://testnet.dplabs-internal.com>                                         |
| api\_host     | <https://api.socialscan.io/pharos-testnet/v1/explorer/command\\_api/contract> |
| explorer\_url | <https://testnet.pharosscan.xyz/>                                             |

```js
require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.28",
  networks: {
    pharos: {
      url: "https://testnet.dplabs-internal.com",
      accounts: [vars.get("PRIVATE_KEY")],
    },
  },
  etherscan: {
    customChains: [
      {
        network: "pharos",
        chainId: 688688, // Or use Pharos Atlantic Testnet chain id 688689
        urls: {
          apiURL: "https://api.socialscan.io/pharos-testnet/v1/explorer/command_api/contract",
          browserURL: "https://testnet.pharosscan.xyz/",
        },
      },
    ],
    apiKey: {
      pharos: "Put a random string", // Note we don't need a apiKey here, just leave a random string
    },
  }
};
```

Run the hardhat verify command

```shell
npx hardhat verify --network pharos <contract_address> <constructor_args_params>
```

### Troubleshooting

* **Contract Deployment Fails**: Ensure you have enough testnet tokens to cover the deployment cost.
* **Interaction Issues**: Verify that the contract address and ABI are correct.
* **Insufficient Balance**: Ensure your wallet has enough tokens to transfer.

### Conclusion

Now that you’ve created and deployed your first NFT using Hardhat.

This guide provides a comprehensive introduction to to creating and deploying an NFT on the Pharos blockchain. If you encounter any issues, refer to the Troubleshooting section or consult the Hardhat documentation. Happy building! 🚀


---

# 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://docs.pharos.xyz/developer-guide/hardhat/write-your-first-nft.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.
