- Notifications
You must be signed in to change notification settings - Fork275
PatrickAlphaC/dungeons-and-dragons-nft
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This repo is a starting point for creating:
- NFTs built with verifiable RNG using theChainlink VRF
- Create dynamic NFTs that change based on real world data.By using decentralized oracles to get data.
- Adding your randomized NFTs to theOpenSea Marketplace
Skip down todeploy To Opensea - to see how to add a tokenURI
We will easily create our own NFT on the Rinkeby Chain. We can edit the name of the character in thegenerate-character.js
script.
This will create a character with 6 attributes from 0 - 99:
- uint256 strength;
- uint256 dexterity;
- uint256 constitution;
- uint256 intelligence;
- uint256 wisdom;
- uint256 charisma;
And then:
- uint256 experience;
- string name;
Right now this repo only works with rinkeby. Run the following.
You'll need aMNEMONIC
and a rinkebyRINKEBY_RPC_URL
environment variable. YourMNEMONIC
is your seed phrase of your wallet. You can find anRINKEBY_RPC_URL
from node provider services likeInfura
Then, you can create a.env
file with the following.
MNEMONIC='cat dog frog....'RINKEBY_RPC_URL='www.infura.io/asdfadsfafdadf'
Or, set them in abash_profile
file or export them directly into your terminal. You can learn more aboutenvironment variables here.
To run them directly in your terminal, run:
export MNEMONIC='cat dog frog....'export RINKEBY_RPC_URL='www.infura.io/asdfadsfafdadf'
Then you can get started with:
git clone https://github.com/PatrickAlphaC/dungeons-and-dragons-nftcd dungeons-and-dragons-nftyarntruffle migrate --reset --network rinkeby
This will deploy your D&D NFT!
You can now try it out:
truffleexec scripts/fund-contract.js --network rinkebytruffleexec scripts/generate-character.js --network rinkebytruffleexec scripts/get-character.js --network rinkeby
This will create a new character with random stats!Depending how often you deploy, you can pick which character by changing thednd.getCharacterOverView(1)
command inget-character.js
to swap the0
out with whatevertokenId
of the character you like.
This will give you the overview of your NFT. You'll seeBN
since the call returns big numbers, you can cast them to ints to see what they are.... Or you could go one step farther
You can get anEtherscan API key for free and interact with the NFTs on chain. Then setETHERSCAN_API_KEY
as an environment variable.
yarn add truffle-plugin-verifytruffle run verify DungeonsAndDragonsCharacter --network rinkeby --license MIT
This will verify and publish your contract, and you can go to theRead Contract
section of etherscan that it gives you.
Otherwise, you can useoneclickdapp and just add the contract address and ABI. You can find the ABI in thebuild/contracts
folder. Just remember it's not the whole file that is the ABI, just the section that saysABI
.
Once we have our NFTs created, we need to give them atokenURI
. TokenURIs are the standard for showing the data of NFTs to the world. This makes it easier to store things like images since we don't have to waste the gas of adding them on-chain.
TheTokenURI represents a URL or other unique identifier, and it is an.json
file with a few parameters.
{ "name": "Name for it ", "description": "Anything you want", "image": "https://ipfs.io/ipfs/HASH_HERE?file.png", "attributes": [...]}
We are going to be storing these images and meta data in IPFS. You'll need both:
IPFS is a peer to peer network for storing files. It's free and open sourced, and we can use it to host our tokenURI. The IPFS companion let's us view IPFS data nativly in our browsers like Brave or Chrome. And Pinata allows us to keep our IPFS files up even when our node is down (don't worry about that for now)
Once our IPFS node is up, we can start adding files to it. We first want to upload the image of our NFT. What does this D&D character look like? Add it to your IPFS node and then "Pin" it. Once pinned, you can get the CID of the pinned file, and make sure it stays pinned by pinning it on your Pinata account. Don't worry, it's free! This will just help keep the data up even when our IPFS node is down.
Once we have the image pinned and up, we can get the link for that image. It'll look a little something like this:
https://ipfs.io/ipfs/QmTgqnhFBMkfT9s8PHKcdXBn1f5bG3Q5hmBaR4U6hoTvb1?filename=Chainlink_Elf.png
This is a real link, and if you click it and nothing renders, your IPFS companion might not be working, or your IPFS node is down.
Once we have our image, we can add it to our metadata.json
file, and add our stats in there. You can see some samples in themetadata
folder. We want to use the values of our characters that we got off-chain, so be sure to verify what the random numbers you got on etherscan! Once we have the .json metadata file, we want to add that to IPFS as well, and pin it too!
This metadata json file is going to be ourtokenURI
, so we will modify ourset-token-uri.js
with thetokenId
of the NFT we are giving a picture to, and adding the ipfs tokenURI.
Then we just run it like:
truffle exec scripts/set-token-uri.js --network rinkeby
Now, we can get the address of our NFT and head on over to the opensea testnet marketplace to see if we did it correctly. If done correctly, it'll looksomething like this.
Here is the link for adding your testnet NFT contract to be viewed on opensea.
About
#chainlink #nft
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.