My Image
CoursesQuizzesProblemsContestsSmartBooks
Contest!

No results found

LOGINREGISTER
My ProgressCoursesQuizzesProblemsContestsSmartbooks
Published on 25 Aug 2022
NFT SMART CONTRACT
How to start making nft smart contract
img
Vikash Kumar
0
Like
84

Hello, World!

In this smart we will learn how can we make the nft  smart contract from basics   . So let's start

 

Pre requiste

  1. Kowledge  of the basics of the Solidity
  2. Know how  to use the remix

Code :

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";

contract FirstNft is ERC721, ERC721URIStorage, Ownable {
    using Counters for Counters.Counter;
    uint public MINT_PRICE = 0.05 ether;
    uint public MAX_SUPPLY = 100;
    Counters.Counter private _tokenIdCounter;
    constructor() ERC721("FirstNft", "FNFT") {}

    function _baseURI() internal pure override returns (string memory) {
        return "ipfs://FirstNFT/";
    }

    function safeMint(address to, string memory uri) public payable{

        // require(totalSupply()<MAX_SUPPLY,"Price is less than  the expected");

        require(msg.value>=MINT_PRICE,"Price is less than  the expected");
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri);
    }

    // The following functions are overrides required by Solidity.

    function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
        super._burn(tokenId);
    }

    function tokenURI(uint256 tokenId)
        public
        view
        override(ERC721, ERC721URIStorage)
        returns (string memory)
    {
        return super.tokenURI(tokenId);
    }
  
}

 

Working

There are lot's of function in  thiis code some of the important were as follows

  1. By using the symbol function we can see our symbol coin
  2. Token uri : By this we can see the token base id
  3. Owner of : For the particular Token you can see the Adress which owns it
  4. Safe mint : By this anyone can mint the nft
  5. safeTransferFrom : You can send particukar address token (nft) to the other address  .

 

Enjoyed the SmartBook?
Like
logo
contact@dapp-world.com
Katraj, Pune, Maharashtra, India - 411048

Follow Us

linkedintwitteryoutubediscordinstagram

Products

  • SmartBooks
  • Courses
  • Quizzes
  • Assessments

Support

  • Contact Us
  • FAQ
  • Privacy Policy
  • T&C

Backed By

ah! ventures

Copyright 2023 - All Rights Reserved.

Recommended from DAppWorld
img
1 May 2021
How to connect Ganache with Metamask and deploy Smart contracts on remix without
Set up your development environment with (Metamask + Ganache + Remix) and skip truffle :)
3 min read
11494
5
img
8 Jul 2021
How to interact with smart contarct from backend node js
call and send functions from backend server side using nodejs
3 min read
8069
2
img
18 Aug 2021
Send transaction with web3 using python
Introduction to web3.py and sending transaction on testnet
3 min read
6215
5
img
5 Aug 2021
Deploy Smart Contract on Polygon POS using Hardhat
how to deploy smart contracts on polygon pos chain using hardhat both mainnet and testnet ?
3 min read
5533
3