Last active
August 13, 2022 01:06
-
-
Save tatsuyasusukida/f45bf704cea1e404b999a26302d7fd55 to your computer and use it in GitHub Desktop.
π΅ How to mint your own ERC-72 NFT
This file contains hidden or 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
API_URL="https://eth-rinkeby.alchemyapi.io/v2/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
PRIVATE_KEY="0000000000000000000000000000000000000000000000000000000000000000" | |
ETHERSCAN_API_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
CONTRACT_ADDRESS="0x0000000000000000000000000000000000000000" | |
TOKEN_URI="https://gateway.pinata.cloud/ipfs/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" |
This file contains hidden or 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
main() | |
async function main () { | |
try { | |
const SusukidaNFT = await ethers.getContractFactory('SusukidaNFT') | |
const susukidaNFT = await SusukidaNFT.deploy() | |
console.info(`Contract deployed to address: ${susukidaNFT.address}`) | |
console.info(`https://rinkeby.etherscan.io/address/${susukidaNFT.address}`) | |
} catch (err) { | |
console.error(err) | |
} | |
} |
This file contains hidden or 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
/** @type import('hardhat/config').HardhatUserConfig */ | |
require('dotenv').config() | |
require('@nomiclabs/hardhat-ethers') | |
require('@nomiclabs/hardhat-etherscan') | |
module.exports = { | |
solidity: "0.8.9", | |
defaultNetwork: "rinkeby", | |
networks: { | |
hardhat: {}, | |
rinkeby: { | |
url: process.env.API_URL, | |
accounts: [`0x${process.env.PRIVATE_KEY}`], | |
}, | |
}, | |
etherscan: { | |
apiKey: process.env.ETHERSCAN_API_KEY, | |
}, | |
}; |
This file contains hidden or 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
{ | |
"attributes" : [ | |
{ | |
"trait_type" : "Birthday", | |
"value" : "August 27th" | |
} | |
], | |
"description" : "My name is Tatsuya Susukida.", | |
"image" : "https://gateway.pinata.cloud/ipfs/QmToKYwMn35YeuK4J5Rn7pkuWG7Kq65rTdBATDCDR9cvpW", | |
"name" : "Tatsuya Susukida" | |
} |
This file contains hidden or 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
const {abi} = require('../artifacts/contracts/SusukidaNFT.sol/SusukidaNFT.json') | |
main() | |
async function main () { | |
try { | |
const {API_URL, PRIVATE_KEY, CONTRACT_ADDRESS, TOKEN_URI} = process.env | |
const provider = new ethers.providers.JsonRpcProvider(API_URL) | |
const signer = new ethers.Wallet(PRIVATE_KEY, provider) | |
const contract = new ethers.Contract(CONTRACT_ADDRESS, abi, signer) | |
const tx = await contract.mintNFT(signer.address, TOKEN_URI) | |
await tx.wait() | |
console.info(`https://rinkeby.etherscan.io/tx/${tx.hash}`) | |
} catch (err) { | |
console.error(err) | |
} | |
} |
This file contains hidden or 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 | |
pragma solidity ^0.8.9; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract SusukidaNFT is ERC721URIStorage, Ownable { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIds; | |
constructor() ERC721("SusukidaNFT", "SNFT") {} | |
function mintNFT(address recipient, string memory tokenURI) | |
public onlyOwner | |
returns (uint256) | |
{ | |
_tokenIds.increment(); | |
uint256 newItemId = _tokenIds.current(); | |
_mint(recipient, newItemId); | |
_setTokenURI(newItemId, tokenURI); | |
return newItemId; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment