Skip to content
This documentation is in beta, and we’re looking for feedback. See how you can contribute 🌟

ERC-721

Overview

Pros

  • Well-established standard with broad support from Ethereum wallets and exchanges.
  • Allows for the creation of unique, non-fungible tokens.
  • Suitable for creating digital collectibles and representing unique assets.

Cons

  • Only allows for the creation of a single type of token.
  • Inefficient for creating multiple types of NFTs.

🏁 Prerequisites


Tutorial

1. Write your ERC-721 contract

We’ll use a contract based on the OpenZeppelin library’s ERC-721 implementation.

a) First, install the Open Zeppelin library in order to inherit its classes:

Terminal window
npm install @openzeppelin/contracts

b) Next, create a file named NFT.sol under the contracts folder.

c) Lastly, add the following smart contract to NFT.sol file.

// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract NFT is ERC721 {
constructor() ERC721("MyERC721", "M721") {}
}

2. Install Hardhat Deploy

Terminal window
npm install -D hardhat-deploy

3. Install an Ethereum library

In this example, we will use Ether.js

Terminal window
npm install --save-dev @nomiclabs/hardhat-ethers ethers@^5.0.0

4. Set environment variables with dotenv

  • Install dotenv
Terminal window
npm install --save dotenv
  • Create a .gitignore file

A great example of a Solidity .gitignore file can be found here

PRIVATE_KEY = #The private key of the account you intend to use on the Palm network INFURA_API_KEY = #Your Infura API key


5. Edit hardhat.config.js with the following text:

require("dotenv").config()
require("@nomiclabs/hardhat-ethers")
require("hardhat-deploy")
const key = '';
module.exports = {
solidity: "0.8.17",
settings: {
optimizer: {
enabled: true,
runs: 1000000,
},
},
mocha: {
timeout: 90000,
},
networks: {
hardhat: {
initialBaseFeePerGas: 0,
blockGasLimit: 18800000,
},
palm_testnet: {
url: `https://palm-testnet.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts: [`0x` + process.env.PRIVATE_KEY],
gasPrice: 1000,
saveDeployments: true,
deploy: ["scripts/"],
},
palm_mainnet: {
url: `https://palm-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts: [`0x` + process.env.PRIVATE_KEY],
gasPrice: 1000,
saveDeployments: true,
deploy: ["scripts/"],
},
},
namedAccounts: {
deployer: 0
},
}

6. Compile your Contract

To make sure everything is working so far, let’s compile our contract:

Terminal window
npx hardhat compile

7. Write a deploy script

a) Navigate to the scripts folder and create a new file called deploy_NFT.js

b) Add the below code

module.exports = async ({
getNamedAccounts,
deployments,
getChainId,
getUnnamedAccounts,
}) => {
const {deploy} = deployments;
const {deployer} = await getNamedAccounts();
console.log("Contract deployed to address:", deployer);
// Deploy "NFT" if the contract was never deployed or if the code has changed since the last deployment
await deploy('NFT', {
from: deployer,
gasLimit: 4000000,
args: [],
log: true,
});
};

8. Deploy to the target Palm network environment

Terminal window
npx hardhat --network palm_testnet deploy
  • TLDR; How This is Working
  • The task will execute the scripts in the scripts folder and saves the contract deployments to disk. Each deployment is saved into the deployments folder for the specific network.

9. Look Up Your Deployment on the Palm Network Block Explorer

TestnetMainnet
Explorer URLhttps://testnet.palm.chainlens.com/https://palm.chainlens.com/

Paste your contract address into the search bar.

You will see something like this upon successful deployment 👇


10. Verify via Sourcify

Terminal window
npx hardhat --network palm_testnet sourcify

Next Step 👉 Mint your NFT

Using the Smart Contract you just deployed you can now Mint NFTs with Hardhat