{ "description":"This is my daughter's hand NFT.", "external_url":"https://example.com/?token_id=1", "image": <YOUR IPFS IMAGE 1.jpg>, "name":"Tearing off paper" }
{ "attributes":[ { "trait_type":"level", "value":3 }, { "trait_type":"stamina", "value":11.7 }, { "trait_type":"personality", "value":"sleepy" }, { "display_type":"boost_number", "trait_type":"aqua_power", "value":30 }, { "display_type":"boost_percentage", "trait_type":"stamina_increase", "value":15 }, { "display_type":"number", "trait_type":"generation", "value":1 } ], "description":"This is my daughter's hand NFT.", "external_url":"https://example.com/?token_id=2", "image": <YOUR IPFS IMAGE 2.jpg>, "name":"Playing with building blocks" }
3
1 2 3 4 5 6
{ "description":"This is my daughter's hand NFT.", "external_url":"https://example.com/?token_id=1", "image": <YOUR IPFS IMAGE 3.jpg>, "name":"Grabbing her dinner" }
// Helper method for fetching environment variables from .env functiongetEnvVariable(key: string, defaultValue?: string) { if (process.env[key]) { return process.env[key]; } if (!defaultValue) { throw`${key} is not defined and no default value was provided`; } return defaultValue; }
// Helper method for fetching a connection provider to the Ethereum network functiongetProvider(ethers: any) { return ethers.getDefaultProvider(getEnvVariable("NETWORK", "rinkeby"), { infura: getEnvVariable("INFURA_ID"), }); }
// Helper method for fetching a wallet account using an environment variable for the PK functiongetAccount(ethers: any) { returnnew ethers.Wallet(getEnvVariable("PRIVATE_KEY") ?? "", getProvider(ethers)); }
// Helper method for fetching a contract instance at a given address functiongetContract(contractName: string, hre: any) { /* // 如果你還不想發布到測試網路,可以用hardhat預設的account取代下面的getAccount() const accounts = await hre.ethers.getSigners(); const account = accounts[0] */ const account = getAccount(hre.ethers); returngetContractAt(hre, contractName, getEnvVariable("NFT_CONTRACT_ADDRESS") ?? "", account); }
task("mint", "Mints from the NFT contract") .addParam("address", "The address to receive a token") .setAction(asyncfunction (taskArguments, hre) { const contract = awaitgetContract("BabyHands", hre); const transactionResponse = await contract.mintTo(taskArguments.address, { gasLimit: 500_000, value: hre.ethers.utils.parseEther("0.08"), }); console.log(`Transaction Hash: ${transactionResponse.hash}`); });
task("set-base-token-uri", "Sets the base token URI for the deployed smart contract") .addParam("baseUrl", "The base of the tokenURI endpoint to set") .setAction(asyncfunction (taskArguments, hre) { const contract = awaitgetContract("BabyHands", hre); const transactionResponse = await contract.setBaseTokenURI( taskArguments.baseUrl, { gasLimit: 500_000, } ); console.log(`Transaction Hash: ${transactionResponse.hash}`); });
task("token-uri", "Fetches the token metadata for the given token ID") .addParam("tokenId", "The tokenID to fetch metadata for") .setAction(asyncfunction (taskArguments, hre) { const contract = awaitgetContract("BabyHands", hre); const response = await contract.tokenURI(taskArguments.tokenId, { gasLimit: 500_000, });