Last active
January 20, 2023 18:57
-
-
Save shobhitic/20a785d2c3421445bcc2fcb177798c2e to your computer and use it in GitHub Desktop.
Free Mint NFT Smart Contract + UI - https://www.youtube.com/watch?v=5tSKO9WjF7E
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
// Made by @Web3Club | |
pragma solidity ^0.8.4; | |
import "erc721a/contracts/ERC721A.sol"; | |
contract FreeMintToken is ERC721A { | |
uint256 public constant USER_LIMIT = 10; | |
uint256 public constant MAX_SUPPLY = 10_000; | |
constructor() ERC721A("FreeMintToken", "FMT") {} | |
function mint(uint256 quantity) external { | |
require(_totalMinted() + quantity <= MAX_SUPPLY, "Not more supply left"); | |
require(_numberMinted(msg.sender) + quantity <= USER_LIMIT, "User limit reached"); | |
// add allowlist verification here | |
_mint(msg.sender, quantity); | |
} | |
function _baseURI() internal view virtual override returns (string memory) { | |
return "ipfs://QmWiQE65tmpYzcokCheQmng2DCM33DEhjXcPB6PanwpAZo/"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Freemint</title> | |
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script> | |
</head> | |
<body> | |
<p>Wallet Address - <span id="wallet-address"></span></p> | |
<button id="connect-wallet-btn">Connect</button> | |
<input type="number" max="10" name="quantity" id="quantity-input" value="10"> | |
<button id="mint-btn">Mint</button> | |
<script type="text/javascript"> | |
var account = null; | |
var contract = null; | |
const connect = async () => { | |
if (window.ethereum) { | |
await window.ethereum.send('eth_requestAccounts'); | |
window.web3 = new Web3(window.ethereum); | |
var accounts = await web3.eth.getAccounts(); | |
account = accounts[0]; | |
document.getElementById('wallet-address').textContent = account; | |
contract = new web3.eth.Contract(ABI, ADDRESS) | |
document.getElementById('mint-btn').onclick = mint | |
} | |
} | |
const mint = async () => { | |
if (contract) { | |
const quantity = document.getElementById('quantity-input').value; | |
await contract.methods.mint(quantity).send({ from: account }) | |
alert('Mint successful') | |
} | |
} | |
document.getElementById('connect-wallet-btn').onclick = connect | |
const ADDRESS = "0x03f5292d4757e6e6fad1ec7fdf3e99ff55b81035" // Add your own address here | |
const ABI = [ | |
{ | |
"inputs": [], | |
"stateMutability": "nonpayable", | |
"type": "constructor" | |
}, | |
{ | |
"inputs": [], | |
"name": "ApprovalCallerNotOwnerNorApproved", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "ApprovalQueryForNonexistentToken", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "ApproveToCaller", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "BalanceQueryForZeroAddress", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "MintERC2309QuantityExceedsLimit", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "MintToZeroAddress", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "MintZeroQuantity", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "OwnerQueryForNonexistentToken", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "OwnershipNotInitializedForExtraData", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "TransferCallerNotOwnerNorApproved", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "TransferFromIncorrectOwner", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "TransferToNonERC721ReceiverImplementer", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "TransferToZeroAddress", | |
"type": "error" | |
}, | |
{ | |
"inputs": [], | |
"name": "URIQueryForNonexistentToken", | |
"type": "error" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "owner", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "approved", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "Approval", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "owner", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "operator", | |
"type": "address" | |
}, | |
{ | |
"indexed": false, | |
"internalType": "bool", | |
"name": "approved", | |
"type": "bool" | |
} | |
], | |
"name": "ApprovalForAll", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"internalType": "uint256", | |
"name": "fromTokenId", | |
"type": "uint256" | |
}, | |
{ | |
"indexed": false, | |
"internalType": "uint256", | |
"name": "toTokenId", | |
"type": "uint256" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "from", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "to", | |
"type": "address" | |
} | |
], | |
"name": "ConsecutiveTransfer", | |
"type": "event" | |
}, | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "from", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "address", | |
"name": "to", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "Transfer", | |
"type": "event" | |
}, | |
{ | |
"inputs": [], | |
"name": "MAX_SUPPLY", | |
"outputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "USER_LIMIT", | |
"outputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "to", | |
"type": "address" | |
}, | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "approve", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "owner", | |
"type": "address" | |
} | |
], | |
"name": "balanceOf", | |
"outputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "getApproved", | |
"outputs": [ | |
{ | |
"internalType": "address", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "owner", | |
"type": "address" | |
}, | |
{ | |
"internalType": "address", | |
"name": "operator", | |
"type": "address" | |
} | |
], | |
"name": "isApprovedForAll", | |
"outputs": [ | |
{ | |
"internalType": "bool", | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "quantity", | |
"type": "uint256" | |
} | |
], | |
"name": "mint", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "name", | |
"outputs": [ | |
{ | |
"internalType": "string", | |
"name": "", | |
"type": "string" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "ownerOf", | |
"outputs": [ | |
{ | |
"internalType": "address", | |
"name": "", | |
"type": "address" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "from", | |
"type": "address" | |
}, | |
{ | |
"internalType": "address", | |
"name": "to", | |
"type": "address" | |
}, | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "safeTransferFrom", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "from", | |
"type": "address" | |
}, | |
{ | |
"internalType": "address", | |
"name": "to", | |
"type": "address" | |
}, | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
}, | |
{ | |
"internalType": "bytes", | |
"name": "_data", | |
"type": "bytes" | |
} | |
], | |
"name": "safeTransferFrom", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "operator", | |
"type": "address" | |
}, | |
{ | |
"internalType": "bool", | |
"name": "approved", | |
"type": "bool" | |
} | |
], | |
"name": "setApprovalForAll", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "bytes4", | |
"name": "interfaceId", | |
"type": "bytes4" | |
} | |
], | |
"name": "supportsInterface", | |
"outputs": [ | |
{ | |
"internalType": "bool", | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "symbol", | |
"outputs": [ | |
{ | |
"internalType": "string", | |
"name": "", | |
"type": "string" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "tokenURI", | |
"outputs": [ | |
{ | |
"internalType": "string", | |
"name": "", | |
"type": "string" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [], | |
"name": "totalSupply", | |
"outputs": [ | |
{ | |
"internalType": "uint256", | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "from", | |
"type": "address" | |
}, | |
{ | |
"internalType": "address", | |
"name": "to", | |
"type": "address" | |
}, | |
{ | |
"internalType": "uint256", | |
"name": "tokenId", | |
"type": "uint256" | |
} | |
], | |
"name": "transferFrom", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
} | |
] | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment