Emerge from Crypto Winter Victorious and Sip Pixelated Drinks in Paradise (đˇ bobbyg603)
Definition đ
âThe term âcrypto winterâ refers to a cryptocurrency market that is underperforming. The term is analogous to a stock market bear market. Crypto winter is characterized by negative sentiment and lower average asset values across a broad range of digital currencies.â ââDiksha Sharma
Crypto Winter đĽś
Itâs November 2022 and cryptocurrency markets have been getting hammered as of late. The FTX catastrophe has monopolized headlines and many news outlets are, once again, declaring cryptocurrency dead.
Despite sentiment on cryptocurrency turning sour, crypto winter is the best time for developers and creators to dive into new projects. Crypto winter is when the âget rich quickâ people retreat into their caves and those who understand cryptocurrencyâs transformational potential start to hunt for the next big project.
On Your Mark đ
In this tutorial, we are going to develop a suite of basic Node.js tools for deploying an NFT contract to Ethereum. We will leverage Alchemy, Hardhat, and Pinata to build and deploy an ERC-721 token contract that can be viewed in a Metamask wallet.
This tutorial has been condensed from an Ethereum.org post to focus on the âhowâ behind deploying an NFT. If youâd like more information about the âwhyâ behind various steps in this article please see the original blog article or leave a comment below.
A companion repo for this tutorial is available via the link below.
Get Set đŹ
Before we can develop our contract we need to get familiar with the tooling. Weâll be using Alchemy and alchemy-sdk-js to build code that interacts with the Ethereum blockchain. Pinata is an IPFS pinning service that weâll use to host the image for our NFT. Hardhat provides tools for developing and testing smart contracts on Ethereum. Metamask is a crypto wallet and gateway to blockchain apps.
Before continuing the tutorial, please create an Alchemy account. By using this link you can start for free, and weâll both earn platform credit if you decide to upgrade in the future.
Additionally, youâll want to create a Pinata account to host the image for your NFT on the decentralized IPFS network.
Finally, youâll want to download the Metamask and export a copy of your accountâs public address and private key. Donât share your privates with anyone!
Go!đŚ
Out of the gate, the first order of business is creating a new app on Alchemy making sure to select the Goerli test network. Once weâve created a new app, weâll want to copy the HTTPS API URL.
The next obstacle we need to navigate is acquiring some ETH on the Goerli test network. To get your ETH for testing, navigate to the Goerli Faucet provided by Alchemy.
Switch to the Goerli test network in Metamask tapping the Wallet button at the top of the app to reveal the list of test networks. Ensure that you received some test ETH from the faucet in the previous step.
On your desktop, create a folder and initialize a new Node.js project.
mkdir nft && cd nft && npm init
Add development dependencies.
npm i --save-dev hardhat @nomiclabs/hardhat-ethers ethers@^5.0.0 ts-node typescript
Add production dependencies.
npm i @alch/alchemy-web3 @openzeppelin/contracts dotenv
Create a new Hardhat project.
npx hardhat
Create directories to store contracts
and scripts
.
mkdir contracts scripts
In the contracts folder create MyNFT.sol
.
In your projectâs root directory, create a .env
file to hold your environment variables and secrets. Do not check this file into source control!
API_URL="https://eth-goerli.g.alchemy.com/v2/your-api-key"
PRIVATE_KEY="your-metamask-private-key"
PUBLIC_KEY="your-metamask-public-key"
In your projectâs root directory, create hardhat.config.ts
.
Hardhat Config File
Letâs compile our MyNFT.sol
contract.
npx hardhat compile
Create a deployment script deploy.ts
in the scripts folder.
Run your deployment script to deploy your compiled MyNFT contract to the Goerli test network. Copy your contract deployment address.
npx hardhat --network goerli run scripts/deploy.ts
# Contract deployed to address: 0x4C5266cCc4b3F426965d2f51b6D910325a0E7650
Our NFT will represent a piece of generated art. You can generate an image yourself (using DALL-E 2 or Stable Diffusion) or you can use this articleâs header image.
Once youâve selected an image, upload the image to Pinata and copy the fileâs CID
.
Create a nft-metadata.json
file you your projectâs root replacing your-ipfs-image-CID
with the CID
you copied from a previous step. Upload nft-metadata.json
to Pinata and make note of its CID
.
{
"attributes": [
{
"trait_type": "Planet",
"value": "Earth"
}
],
"description": "Astronaut enjoying a drink at a tropical resort.",
"image": "ipfs://your-ipfs-image-CID",
"name": "Captain Cook"
}
Now itâs time to mint a new NFT! Letâs create mint-nft.ts
in the scripts folder. Be sure to replace the values of your-contract-address
and your-ipfs-metadata-CID
with the values you copied in previous steps.
Mint your NFT!
npx ts-node scripts/mint-nft.ts
Finally, add your NFT to Metamask so you can show it off to your friends.
Mainnet đď¸
â ď¸ Be careful! Creating a new NFT contract is expensive. At the time of writing the transaction fee was 0.0267 ETH or ~$30.52. Minting an NFT is cheaper and costs approximately 0.001 ETH or ~$1.50.
You can repeat the process on the Ethereum Mainnet by making the following changes:
Replace the
API_URL
value in.env
with an HTTPS API URL of Ethereum Mainnet Alchemy App.Deploy your contract to the Ethereum Mainnet
npx hardhat run scripts/deploy.ts
Replace the
contractAddress
value inscripts/mint-nft.ts
with the new Mainnet contract addressMint a new NFT
npx ts-node scripts/mint-nft.ts
Now that you have an NFT on the Ethereum Mainnet you can things like set your Twitter profile picture to a hexagonal NFT and display your NFTs on OpenSea.
Congrats! đ
Youâve taken the first step on your journey into NFT development! If you have any cool ideas for an NFT project or are unsure where to go next, please leave a comment below or message me on TwitterâââIâd love to hear about your next project!
Want to Connect? đ
If you found the information in this tutorial useful please subscribe on Hashnode, follow me on Twitter, and/or subscribe to my YouTube channel.