We go through creating 2 different kinds of NFTs.
- An IPFS Hosted NFT
- An SVG NFT (Hosted 100% on-chain)
- git
- You'll know you did it right if you can run
git --version
and you see a response likegit version x.x.x
- You'll know you did it right if you can run
- foundry
- You'll know you did it right if you can run
forge --version
and you see a response likeforge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)
- You'll know you did it right if you can run
git clone [email protected]:lokichoggio/nft.git
cd nft
forge install
forge build
If you can't or don't want to run and install locally, you can work with this repo in Gitpod. If you do this, you can skip the clone this repo
part.
make anvil
This will default to your local node. You need to have it running in another terminal in order for it to deploy.
make deploy
We talk about 4 test tiers in the video.
- Unit
- Integration
- Forked
- Staging
This repo we cover #1 and #3.
forge test
or
forge test --fork-url $SEPOLIA_RPC_URL
forge coverage
- Setup environment variables
You'll want to set your SEPOLIA_RPC_URL
and SEPOLIA_PRIVATE_KEY
as environment variables. You can add them to a .env
file, similar to what you see in .env.example
.
SEPOLIA_PRIVATE_KEY
: The private key of your account (like from metamask). NOTE: FOR DEVELOPMENT, PLEASE USE A KEY THAT DOESN'T HAVE ANY REAL FUNDS ASSOCIATED WITH IT.- You can learn how to export it here.
SEPOLIA_RPC_URL
: This is url of the goerli testnet node you're working with. You can get setup with one for free from Alchemy
Optionally, add your ETHERSCAN_API_KEY
if you want to verify your contract on Etherscan.
- Get testnet ETH
Head over to faucets.chain.link and get some tesnet ETH. You should see the ETH show up in your metamask.
- Deploy (IPFS NFT)
make deploy ARGS="--network sepolia"
- Deploy (SVG NFT)
make deploySvg ARGS="--network sepolia"
To get the base64 of an image, you can use the following command:
echo "data:image/svg+xml;base64,$(base64 -i ./images/dynamicNft/happy.svg)"
Then, you can get the base64 encoding of the json object by placing the imageURI into happy_image_uri.json
then running:
echo "data:application/json;base64,$(base64 -i ./images/dynamicNft/happy_image_uri.json)"
You can estimate how much gas things cost by running:
forge snapshot
And you'll see and output file called .gas-snapshot
To run code formatting:
forge fmt
svg test
echo "data:image/svg+xml;base64,$(base64 -i ./images/dynamicNft/happy.svg)"
data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjAwIDIwMCIgd2lkdGg9IjQwMCIgIGhlaWdodD0iNDAwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxjaXJjbGUgY3g9IjEwMCIgY3k9IjEwMCIgZmlsbD0ieWVsbG93IiByPSI3OCIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLXdpZHRoPSIzIi8+CiAgPGcgY2xhc3M9ImV5ZXMiPgogICAgPGNpcmNsZSBjeD0iNjEiIGN5PSI4MiIgcj0iMTIiLz4KICAgIDxjaXJjbGUgY3g9IjEyNyIgY3k9IjgyIiByPSIxMiIvPgogIDwvZz4KICA8cGF0aCBkPSJtMTM2LjgxIDExNi41M2MuNjkgMjYuMTctNjQuMTEgNDItODEuNTItLjczIiBzdHlsZT0iZmlsbDpub25lOyBzdHJva2U6IGJsYWNrOyBzdHJva2Utd2lkdGg6IDM7Ii8+Cjwvc3ZnPg==
echo "data:application/json;base64,$(base64 -i ./images/dynamicNft/happy_image_uri.json)"
data:application/json;base64,eyJuYW1lIjoiTW9vZCBORlQiLCAiZGVzY3JpcHRpb24iOiJBbiBORlQgdGhhdCByZWZsZWN0cyB0aGUgbW9vZCBvZiB0aGUgb3duZXIsIDEwMCUgb24gQ2hhaW4hIiwgImF0dHJpYnV0ZXMiOiBbeyJ0cmFpdF90eXBlIjogIm1vb2RpbmVzcyIsICJ2YWx1ZSI6IDEwMH1dLCAiaW1hZ2UiOiJkYXRhOmltYWdlL3N2Zyt4bWw7YmFzZTY0LFBITjJaeUIyYVdWM1FtOTRQU0l3SURBZ01qQXdJREl3TUNJZ2QybGtkR2c5SWpRd01DSWdJR2hsYVdkb2REMGlOREF3SWlCNGJXeHVjejBpYUhSMGNEb3ZMM2QzZHk1M015NXZjbWN2TWpBd01DOXpkbWNpUGdvZ0lEeGphWEpqYkdVZ1kzZzlJakV3TUNJZ1kzazlJakV3TUNJZ1ptbHNiRDBpZVdWc2JHOTNJaUJ5UFNJM09DSWdjM1J5YjJ0bFBTSmliR0ZqYXlJZ2MzUnliMnRsTFhkcFpIUm9QU0l6SWk4K0NpQWdQR2NnWTJ4aGMzTTlJbVY1WlhNaVBnb2dJQ0FnUEdOcGNtTnNaU0JqZUQwaU5qRWlJR041UFNJNE1pSWdjajBpTVRJaUx6NEtJQ0FnSUR4amFYSmpiR1VnWTNnOUlqRXlOeUlnWTNrOUlqZ3lJaUJ5UFNJeE1pSXZQZ29nSUR3dlp6NEtJQ0E4Y0dGMGFDQmtQU0p0TVRNMkxqZ3hJREV4Tmk0MU0yTXVOamtnTWpZdU1UY3ROalF1TVRFZ05ESXRPREV1TlRJdExqY3pJaUJ6ZEhsc1pUMGlabWxzYkRwdWIyNWxPeUJ6ZEhKdmEyVTZJR0pzWVdOck95QnpkSEp2YTJVdGQybGtkR2c2SURNN0lpOCtDand2YzNablBnPT0ifQ==
deploy to sepolia
make deploy ARGS="--network sepolia"
contract: 0x0816F697114384117B98C7B064375b66a5A7072e
cast call 0x0816F697114384117B98C7B064375b66a5A7072e "name()(string)" --rpc-url $SEPOLIA_RPC_URL --private-key $SEPOLIA_PRIVATE_KEY
Dogie
cast call 0x0816F697114384117B98C7B064375b66a5A7072e "symbol()(string)" --rpc-url $SEPOLIA_RPC_URL --private-key $SEPOLIA_PRIVATE_KEY
DOG
cast call 0x0816F697114384117B98C7B064375b66a5A7072e "getTokenCounter()(uint256)" --rpc-url $SEPOLIA_RPC_URL --private-key $SEPOLIA_PRIVATE_KEY
0
cast send 0x0816F697114384117B98C7B064375b66a5A7072e "mintNft(string)" "ipfs://bafybeig37ioir76s7mg5oobetncojcm3c3hxasyd4rvid4jqhy4gkaheg4/?filename=0-PUG.json" --rpc-url $SEPOLIA_RPC_URL --private-key $SEPOLIA_PRIVATE_KEY
tx: 0xea85922f4d2d4b7066f0212243606b2e1934c2c6453602a2f9229d01f89d575d
cast call 0x0816F697114384117B98C7B064375b66a5A7072e "tokenURI(uint256)(string)" 0 --rpc-url $SEPOLIA_RPC_URL --private-key $SEPOLIA_PRIVATE_KEY
ipfs://bafybeig37ioir76s7mg5oobetncojcm3c3hxasyd4rvid4jqhy4gkaheg4/?filename=0-PUG.json
cast call 0x0816F697114384117B98C7B064375b66a5A7072e "balanceOf(address)(uint256)" 0x8021f00c28C0e43788AE1a11f1F97eBf80d131bD --rpc-url $SEPOLIA_RPC_URL --private-key $SEPOLIA_PRIVATE_KEY
1
make deployMood ARGS="--network sepolia"
contract: 0x683455455A9f0C06db22D32b85271495A819BE28
make mintMoodNft ARGS="--network sepolia"
tx: 0xc1a622ead0c836b883e468739dec8d4269b07892c41c99267f375d448b2e0959
make flipMoodNft ARGS="--network sepolia"
tx: 0x290959120c6c50292178ec2d05bef962cd740850351b736db3a1fe531f21996b