---
title: "How to mint an NFT with ethers.js"
description: "Discover the step-by-step guide on minting NFTs with Ethers.js. Create your unique digital assets effortlessly and join the blockchain revolution!"
---

# How to mint an NFT with ethers.js

This tutorial describes how to mint an NFT on the Ethereum blockchain using Ethers via the [ethers.js](https://www.alchemy.com/dapps/ethers-js) library, and our smart contract from Part I: How to Create an NFT. We'll also explore basic test se

_Estimated time to complete this guide: ~10 minutes_

Plus, be sure to check out the rest of our NFT tutorial series:

- 🌟  [How to mint an NFT using Web3.js](https://www.alchemy.com/blog/how-to-mint-an-nft-using-web3-js)
- 👛  [How to view your NFT in your mobile wallet](https://www.alchemy.com/blog/how-to-view-your-nft-in-your-mobile-wallet)
- 💸  [How to set a price on an NFT](https://www.alchemy.com/blog/how-to-set-a-price-on-an-nft)
- 💻  [NFT minter tutorial: How to create a full stack DApp](https://www.alchemy.com/blog/nft-minter-tutorial-how-to-create-a-full-stack-dapp)

In [another tutorial](https://www.alchemy.com/docs/reference/nft-api-overview), we learned how to mint an NFT using Web3 and the [OpenZeppelin contracts library](https://docs.openzeppelin.com/contracts/erc721). In this exercise, we're going to walk you through an alternative implementation using version 4 of the [OpenZeppelin library](https://docs.openzeppelin.com/contracts/4.x/erc721) as well as the [Ethers.js](https://docs.ethers.io/) Ethereum library instead of Web3.

We'll also cover the basics of testing your contract with [Hardhat](https://www.alchemy.com/dapps/hardhat) and [Waffle](https://www.alchemy.com/dapps/waffle). For this tutorial I'm using Yarn, but you can use npm/npx if you prefer.

Lastly, we'll use TypeScript. This is fairly well documented, so we won't cover it here.

In all other respects, this tutorial works the same as the Web3 version, including tools such as Pinata and IPFS.

## A quick reminder

As a reminder, "minting an NFT" is the act of publishing a unique instance of your ERC721 token on the blockchain. This tutorial assumes that that you've successfully [deployed a smart contract to the Ropsten network in Part I](https://www.alchemy.com//blog/how-to-create-an-nft) of the NFT tutorial series, which includes installing Ethers.

## Step 1: create your Solidity contract

[OpenZeppelin](https://www.alchemy.com/dapps/openzeppelin) is library for secure smart contract development. You simply inherit their implementations of popular standards such as [ERC20](https://www.alchemy.com/overviews/erc20-solidity) or ERC721, and extend the behavior to your needs. We're going to put this file at contracts/MyNFT.sol.

## Step 2: create Hardhat tasks to deploy our contract and mint NFT's

Create the file tasks/nft.ts containing the following:

## Step 3: create helpers

You'll notice our tasks imported a few helpers. Here they are.

`contract.ts`

`env.ts`

`provider.ts`

Note that the final getProvider\(\) function uses the ropsten network. This argument is optional and defaults to "homestead" if omitted. We're using Alchemy of course, but there are several [supported alternatives](https://docs.ethers.io/v5/api/providers/#providers-getDefaultProvider).

`wallet.ts`

## Step 4: create tests

Under your test directory, create these files. Note that these tests are not comprehensive. They test a small subset of the ERC721 functionality offered by the OpenZeppelin library, and are intended to provide you with the building blocks to create more robust tests.

`test/MyNFT.spec.ts (unit tests)`

`tasks.spec.ts (integration specs)`

`test-helpers.ts` Note this require the NPM libraries imported, including sinon, chai, and sinon-chai. The `sinon.restore()` call is necessary due to the use of stubbing.

## Step 5: configuration

Here's our fairly bare bones `hardhat.config.ts`.

Note the conditional to only invoke dotenv if we're not running tests. You might not want to run this in production, but rest assured that dotenv will silently ignore it if the .env file isn't present.

## Running our tasks

Now that we've put these files in place, we can run hardhat to see our tasks \(excluding the built-in tasks for brevity\).

Forget the arguments to your task? No problem.

## Running our tests

To run our tests, we run `hardhat test`.

## Summary

In this tutorial, we've created a firm foundation for a well tested NFT infrastructure based on [Solidity](https://www.alchemy.com/overviews/solidity). The wallet provided by **waffle.provider.getWallets\(\)** links to a local fake [Hardhat Network](https://hardhat.org/hardhat-network/) account that [conveniently comes preloaded](https://hardhat.org/hardhat-network/reference/#initial-state) with an eth balance that we can use to fund our test transactions.
