Loading...
Hello, World!
In this smart we will learn how can we make the nft smart contract from basics . So let's start
// 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);
}
}
There are lot's of function in thiis code some of the important were as follows