Created
June 20, 2022 00:36
-
-
Save danicuki/6f023edfd76e52e4c558abd3d75b871d to your computer and use it in GitHub Desktop.
NFT Collection - Código fim da Seção 1
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 main = async () => { | |
const nftContractFactory = await hre.ethers.getContractFactory("MyEpicNFT") | |
const nftContract = await nftContractFactory.deploy() | |
await nftContract.deployed() | |
console.log("Contrato implantado em:", nftContract.address) | |
// Chama a função. | |
let txn = await nftContract.makeAnEpicNFT() | |
// Espera ela ser minerada. | |
await txn.wait() | |
console.log("Cunhou NFT #1") | |
txn = await nftContract.makeAnEpicNFT() | |
// Espera ela ser minerada. | |
await txn.wait() | |
console.log("Cunhou NFT #2") | |
} | |
const runMain = async () => { | |
try { | |
await main() | |
process.exit(0) | |
} catch (error) { | |
console.log(error) | |
process.exit(1) | |
} | |
} | |
runMain() |
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: UNLICENSED | |
pragma solidity ^0.8.1; | |
// Primeiro importamos alguns contratos do OpenZeppelin. | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
import "hardhat/console.sol"; | |
// Nós herdamos o contrato que importamos. Isso significa que | |
// teremos acesso aos métodos do contrato herdado. | |
contract MyEpicNFT is ERC721URIStorage { | |
// Mágica dada pelo OpenZeppelin para nos ajudar a observar os tokenIds. | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIds; | |
// Nós precisamos passar o nome do nosso token NFT e o símbolo dele. | |
constructor() ERC721 ("ChavesNFT", "CHAVO"){ | |
console.log("Esse eh meu contrato de NFT! Tchu-hu"); | |
} | |
// Uma função que o nosso usuário irá chamar para pegar sua NFT. | |
function makeAnEpicNFT() public { | |
// Pega o tokenId atual, que começa por 0. | |
uint256 newItemId = _tokenIds.current(); | |
// Minta ("cunha") o NFT para o sender (quem ativa o contrato) usando msg.sender. | |
_safeMint(msg.sender, newItemId); | |
// Designa os dados do NFT. | |
_setTokenURI(newItemId, "https://jsonkeeper.com/b/9WB6"); | |
console.log("Uma NFT com o ID %s foi mintada para %s", newItemId, msg.sender); | |
// Incrementa o contador para quando o próximo NFT for mintado. | |
_tokenIds.increment(); | |
} | |
} |
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 main = async () => { | |
const nftContractFactory = await hre.ethers.getContractFactory("MyEpicNFT") | |
const nftContract = await nftContractFactory.deploy() | |
await nftContract.deployed() | |
console.log("Contrato implantado em:", nftContract.address) | |
// Chama a função. | |
let txn = await nftContract.makeAnEpicNFT() | |
// Espera ela ser minerada. | |
await txn.wait() | |
// Minta outra NFT por diversão. | |
txn = await nftContract.makeAnEpicNFT() | |
// Espera ela ser minerada. | |
await txn.wait() | |
} | |
const runMain = async () => { | |
try { | |
await main() | |
process.exit(0) | |
} catch (error) { | |
console.log(error) | |
process.exit(1) | |
} | |
} | |
runMain() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment