How to create and deploy an NFT smart contracts

Learn how to create and deploy NFT smart contracts with our step-by-step guide. Unlock the potential of blockchain and monetize your digital assets today.

How to create and deploy an NFT smart contracts

Darkweb v2.0 public release is here

Lorem ipsum dolor sit amet, consectetur adipiscing elit lobortis arcu enim urna adipiscing praesent velit viverra sit semper lorem eu cursus vel hendrerit elementum morbi curabitur etiam nibh justo, lorem aliquet donec sed sit mi dignissim at ante massa mattis.

  1. Neque sodales ut etiam sit amet nisl purus non tellus orci ac auctor
  2. Adipiscing elit ut aliquam purus sit amet viverra suspendisse potent i
  3. Mauris commodo quis imperdiet massa tincidunt nunc pulvinar
  4. Adipiscing elit ut aliquam purus sit amet viverra suspendisse potenti

What has changed in our latest release?

Vitae congue eu consequat ac felis placerat vestibulum lectus mauris ultrices cursus sit amet dictum sit amet justo donec enim diam porttitor lacus luctus accumsan tortor posuere praesent tristique magna sit amet purus gravida quis blandit turpis.

All new features available for all public channel users

At risus viverra adipiscing at in tellus integer feugiat nisl pretium fusce id velit ut tortor sagittis orci a scelerisque purus semper eget at lectus urna duis convallis. porta nibh venenatis cras sed felis eget neque laoreet suspendisse interdum consectetur libero id faucibus nisl donec pretium vulputate sapien nec sagittis aliquam nunc lobortis mattis aliquam faucibus purus in.

  • Neque sodales ut etiam sit amet nisl purus non tellus orci ac auctor
  • Adipiscing elit ut aliquam purus sit amet viverra suspendisse potenti
  • Mauris commodo quis imperdiet massa tincidunt nunc pulvinar
  • Adipiscing elit ut aliquam purus sit amet viverra suspendisse potenti
Coding collaboration with over 200 users at once

Nisi quis eleifend quam adipiscing vitae aliquet bibendum enim facilisis gravida neque. Velit euismod in pellentesque massa placerat volutpat lacus laoreet non curabitur gravida odio aenean sed adipiscing diam donec adipiscing tristique risus. amet est placerat in egestas erat imperdiet sed euismod nisi.

“Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum”
Real-time code save every 0.1 seconds

Eget lorem dolor sed viverra ipsum nunc aliquet bibendum felis donec et odio pellentesque diam volutpat commodo sed egestas aliquam sem fringilla ut morbi tincidunt augue interdum velit euismod eu tincidunt tortor aliquam nulla facilisi aenean sed adipiscing diam donec adipiscing ut lectus arcu bibendum at varius vel pharetra nibh venenatis cras sed felis eget dolor cosnectur drolo.

NFTs have gained traction since the first token surfaced in 2014. In fact, according to a report from DappRadar, NFT sales volume grew from $94.9 Million in 2020 to $24.9 billion in 2021, The wallets trading them grew from over 500,000 to 26.6 Million within the year!

Despite the steady momentum, about 70% of the US Population still know nothing about NFTs. 

The good news is you can create your own NFT smart contract and deploy it on the Ethereum network. You don’t need to be a programming wizard to get started.

In this guide, we will show you how to build an NFT using the ERC-721 standard and deploy it on the Ethereum main net (or testnet) using Alchemy and Metamask!

Set Up a Development Environment

The development environment is the software that you use to create your smart contract.

Smart contracts are the next layer of the blockchain. They allow developers to create applications that run on top of the blockchain, but with a more user-friendly interface.

The development environment can be either a local computer or an online service, such as Amazon Web Services (AWS). 

Local Environment - Local environments are software programs that run directly on your computer.

Why do you need a development environment?

It is not always easy to deploy your smart contract on the Ethereum network using just your browser. You'll need some kind of basic programming language and access to other tools like MetaMask so that you can interact with the Ethereum network from within the Web3 tooling of your choice.

Install and Set Up Metamask

Setting up MetaMask lets you  store and swap ether and ether-related tokens. 

You can install Metamask on your computer by downloading the Metamask plugin for your browser. Then, create your MetaMask wallet.

Now that you have a wallet, you can begin setting up. To deploy NFT Smart Contract to the test network, you need to add ETH from a faucet.

You need to do this because you are required a Gas fee which you pay through cryptocurrencies or tokens whenever you want to deploy a code on the Blockchain. 

You can do these by following two easy steps:

  1. Once you have installed MetaMask, change the network to Goerli Test Network.
  1. Locate Goerli Faucet, enter your wallet address, and transfer some test GoerliETH. 

Your wallet should reflect a new balance when you are done.

Next, open up a new window in the browser and go to this link:

This will show all of the transactions made using that particular address since it was created, each one with the amount that was sent and received in ETH, as well as the token contract address where those tokens were sent.

Prepare your Alchemy Account

Alchemy provides an array of developer tools and infrastructures for blockchain companies.

You will need to create an account on the Alchemy platform. This will be used to create an ERC20 token. This account is separate from your Metamask account and uses a different wallet address.

You can do this by clicking "Create New Account" in the upper right-hand corner of your browser.

 Once you have created an account, you have to create an app, input a name, and choose Network as Gorelik.

You'll need to import your wallet so that we can transfer funds from it into our smart contract. The easiest way to do this is through MetaMask. If you're using MetaMask, click "Import Wallet" in its top menu bar and then select the wallet you made from there.

After importing any necessary private keys/addresses that belong within each party's respective wallets (if any), make sure there is enough Ether available within both accounts before moving forward with creating our smart contract—this gas fee must be paid before being able to deploy anything onto the blockchain network. 

Once you've confirmed that there is enough Ether available for deployment, click on "Create Contract" and fill out the form that appears. This can be done by selecting a name for your contract and choosing whether or not it should be open source (if you're creating a smart contract with another party). Once this information has been filled out, select "Create" at the bottom of the page.

Creating an Nft Smart Contract

Create a new file called "NFT.sol" in the contracts/ directory of the newly created nft-tutorial directory in your preferred IDE.// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

import "@openzeppelin/contracts/utils/Counters.sol";

contract NFT is ERC721 {

    using Counters for Counters.Counter;

    Counters.Counter private currentTokenId;

    constructor() ERC721("NFTTutorial", "NFT") {}    

    function mintTo(address recipient)

        public

        returns (uint256)

    {

        currentTokenId.increment();

        uint256 newItemId = currentTokenId.current();

        _safeMint(recipient, newItemId);

        return newItemId;

    }

Let's try to put our (basic) contract together and make sure it is prepared for deployment now that it has been written.

Since deploying the contract will cost us ETH, we will need to incorporate the MetaMask account we previously generated into our project.

Let's first create a new file called ".env" in the project's root folder. Both our Alchemy API key and our account's private key will be kept in this file.

When your private key and Alchemy API key are prepared, paste them into .env using the following format:

ALCHEMY_KEY = "alchemy-api-key"

ACCOUNT_PRIVATE_KEY = "private-key"

Next, update the hardhat.config.js file by adding the following:

/**

* @type import('hardhat/config').HardhatUserConfig

*/

require('dotenv').config();

require("@nomiclabs/hardhat-ethers");

const { ALCHEMY_KEY, ACCOUNT_PRIVATE_KEY } = process.env;

module.exports = {

   solidity: "0.8.0",

   defaultNetwork: "rinkeby",

   networks: {

    hardhat: {},

    rinkeby: {

      url: `https://eth-rinkeby.alchemyapi.io/v2/${ALCHEMY_KEY}`,

      accounts: [`0x${ACCOUNT_PRIVATE_KEY}`]

    },

    ethereum: {

      chainId: 1,

      url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_KEY}`,

      accounts: [`0x${ACCOUNT_PRIVATE_KEY}`]

    },

  },

}

These modifications ought to be rather simple:

  • Several imports from dotenv and hardhat-ethers are necessary in order to use the variables we previously set and to later deploy our contract.

  • To deploy the same code to Rinkeby testnet, Ethereum mainnet, or any other network in the future, a module configuration specifies our default Solidity version, default network, and some network parameters.

Compile The Contract

To compile our program we use the following command:

npx hardhat compile

And the result should look something like this:

Compiling 1 file with 0.8.0

Compilation finished successfully

If done well, this should run freely without errors.

Deploy The Contract

When you deploy your smart contract, it is compiled and converted into bytecodes before it will be stored in the Blockchain and an address assigned to it.

The next step is to deploy the contract. This can be done by sending a transaction to the address of your smart contract and setting some parameters.

To do this, you'll need to create a transaction with Metamask.

  •  First, set the address of your newly created NFT smart contract as an input value in this transaction, 
  • Next, set the Gas Price and Gas Limit for each operation that should be performed by this smart contract,
  •  Sign off on this transaction using Metamask by clicking "Sign" or hitting enter on your keyboard.

There is just one thing left to do at this point: construct a straightforward JavaScript deploy script and run it through Hardhat.

Make a "deploy.js" file in the "scripts/" folder and put the following code in it:

async function main() {

    // Get our account (as deployer) to verify that a minimum wallet balance is available

    const [deployer] = await ethers.getSigners();

    console.log(`Deploying contracts with the account: ${deployer.address}`);

    console.log(`Account balance: ${(await deployer.getBalance()).toString()}`);

    // Fetch the compiled contract using ethers.js

    const NFT = await ethers.getContractFactory("NFT");

    // calling deploy() will return an async Promise that we can await on 

    const nft = await NFT.deploy();

    console.log(`Contract deployed to address: ${nft.address}`);

}

main()

.then(() => process.exit(0))

.catch((error) => {

    console.error(error);

    process.exit(1);

});

Validate The Smart Contract

Validating the smart contract is crucial as it protects the users and contributors to the Blockchain.

You can verify the contract's source code, bytecode and deployed address. 

To verify the contract's source code, copy and paste your contract into a text editor (like Notepad), then run it through the Etherscan Javascript API. 

You should see "Verified" next to a button that says "View Contract Source."  Click this button and you'll be able to view your smart contract's source code.

Another option is to use Arcana software development kits(SDKs) to create and transact Private NFTs.

Here’s what you need to use the Arcana option: 

  • The Developer Dashboard on Arcana so you can register and configure your dApp.
  • Deploy your own collection of NFTs if you don’t have a public AERC721 smart contract address
  • Integrate your dApp with MetaMask so you can get an Ethereum provider to get a signer for NFT minting

Now, here’s how to create private NFTs on Arcana:

  1. Integrate Arcana Storage SDK​: If you’ve met the required steps listed above, you may need to deploy your own NFT collection and mint it. 
  2. Select Arcana Network:​ Inform the dApp user to choose "Arcana Network" when setting up their MetaMask wallet. 
  3. Upload the NFT asset to Arcana Store​: Once your dApp has been integrated with Arcana Storage SDK, use the file uploader function to upload the NFT asset data file to Arcana Store.Then,  save the DID assigned to this NFT asset.
  4. Obtain makeMetaDataURL from Storage SDK: You can do this by specifying the title, description, uploading NFT asset's DID and a preview image, and using the makeMetaDataURL function.
  5. Change the Network in MetaMask: Inform the dApp user to change the network setting in MetaMask to the blockchain where you would like to mint the NFT.
  6. Mint the NFT: To do this, you’ll need a blockchain signer using ethers.js library 
  7. Change the Network in MetaMask: Change the network back to Arcana Network before linking the tokenID you received after minting with Arcana Store DID.
  8. Link NFT to DID in Arcana Store: You can use the linkNFT function of the Arcana Storage SDK to link your NFT
  9. Verify that the private NFT has been created by using Arcana NFT Viewer