mint-nft.jsfile and add the following lines of code:
mint-nft.jsand see your ABI printed to the console navigate to your terminal and run
mintNFTsmart contract function takes in a tokenURI parameter that should resolve to a JSON document describing the NFT's metadata— which is really what brings the NFT to life, allowing it to have configurable properties, such as a name, description, image, and other attributes.
mint-nft.jsfile, add the following:
nonce(will explain below).
.envfile —if you completed part 1 of the tutorial, our .
envfile should now look like this:
mintNFT(tokenData)and create our transaction by doing the following:
PUBLIC_KEYfrom the .env file.
nonce. The nonce specification is used to keep track of the number of transactions sent from your address— which we need for security purposes and to prevent replay attacks. To get the number of transactions sent from your address, we use getTransactionCount.
transactionwith the following info:
'from': PUBLIC_KEY: The origin of our transaction is our public address
'to': contractAddress: The contract we wish to interact with and send the transaction
'nonce': nonce: The account nonce with the number of transactions sent from our address
'gas': estimatedGas: The estimated gas needed to complete the transaction
'maxPriorityFeePerGas': estimatedFee: The estimated fee to bid per gas.
'data': nftContract.methods.mintNFT(PUBLIC_KEY, tokenURI).encodeABI(): The computation we wish to perform in this transaction— which in this case is minting an NFT
mint-nft.jsfile should look like this now:
web3.eth.sendSignedTransactionwill give us the transaction hash, which we can use to make sure our transaction was mined and didn't get dropped by the network. You'll notice in the transaction signing section, we've added some error checking so we know if our transaction successfully went through.
node scripts/mint-nft.jsto deploy your NFT. After a couple of seconds, you should see a response like this in your terminal :
mint-nft.jsyou can mint as many NFT's as your heart (and wallet) desires! Just be sure to pass in a new
tokenURIdescribing the NFT's metadata --otherwise, you'll just end up making a bunch of identical ones with different IDs.