• Stars
    star
    603
  • Rank 74,294 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

#chainlink #nft

Chainlink Random Character Creation

This repo is a starting point for creating:

  1. NFTs built with verifiable RNG using the Chainlink VRF
  2. Create dynamic NFTs that change based on real world data. By using decentralized oracles to get data.
  3. Adding your randomized NFTs to the OpenSea Marketplace

Skip down to deploy 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 the generate-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;

Quickstart

Right now this repo only works with rinkeby. Run the following.

Setup Environment Variables

You'll need a MNEMONIC and a rinkeby RINKEBY_RPC_URL environment variable. Your MNEMONIC is your seed phrase of your wallet. You can find an RINKEBY_RPC_URL from node provider services like Infura

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 a bash_profile file or export them directly into your terminal. You can learn more about environment 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:

Clone The Repo and migrate

git clone https://github.com/PatrickAlphaC/dungeons-and-dragons-nft
cd dungeons-and-dragons-nft
yarn
truffle migrate --reset --network rinkeby

This will deploy your D&D NFT!

Generate a character

You can now try it out:

truffle exec scripts/fund-contract.js --network rinkeby
truffle exec scripts/generate-character.js --network rinkeby
truffle exec 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 the dnd.getCharacterOverView(1) command in get-character.js to swap the 0 out with whatever tokenId of the character you like.

This will give you the overview of your NFT. You'll see BN since the call returns big numbers, you can cast them to ints to see what they are.... Or you could go one step farther

See it on etherscan or oneclickdapp

You can get an Etherscan API key for free and interact with the NFTs on chain. Then set ETHERSCAN_API_KEY as an environment variable.

yarn add truffle-plugin-verify
truffle run verify DungeonsAndDragonsCharacter --network rinkeby --license MIT

This will verify and publish your contract, and you can go to the Read Contract section of etherscan that it gives you.

Otherwise, you can use oneclickdapp and just add the contract address and ABI. You can find the ABI in the build/contracts folder. Just remember it's not the whole file that is the ABI, just the section that says ABI.

Deploy to Opensea

Once we have our NFTs created, we need to give them a tokenURI. 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.

The TokenURI 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:

  1. IPFS
  2. IPFS companion
  3. Pinata

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 the metadata 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 our tokenURI, so we will modify our set-token-uri.js with the tokenId 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 look something like this.

Here is the link for adding your testnet NFT contract to be viewed on opensea.

More Repositories

1

nft-mix

Solidity
803
star
2

hardhat-security-fcc

Solidity
410
star
3

all-on-chain-generated-nft

A repo for generating random NFTs with metadata 100% on chain!
JavaScript
356
star
4

dao-template

TypeScript
244
star
5

full-stack-web3-metamask-connectors

180
star
6

chainlink_defi

Build a defi yield farmable dApp. Get started here.
JavaScript
157
star
7

rwa-creator

Solidity
133
star
8

smart-contract-frameworks

A list of smart contract frameworks
C
119
star
9

hardhat-smartcontract-lottery-fcc

JavaScript
118
star
10

hardhat-nft-marketplace-fcc

JavaScript
114
star
11

hardhat-nft-fcc

JavaScript
101
star
12

simple-storage-fcc

Solidity
99
star
13

ethers-simple-storage-fcc

JavaScript
88
star
14

unstoppable-ui

JavaScript
87
star
15

async-python

Shows how to use async requests vs requests
Python
87
star
16

hardhat-fund-me-fcc

JavaScript
83
star
17

defi-stake-yield-brownie

Solidity
78
star
18

smartcontract-lottery

Solidity
75
star
19

PatrickAlphaC

75
star
20

hardhat-simple-storage-fcc

JavaScript
74
star
21

aave_brownie_py

Solidity
61
star
22

nextjs-smartcontract-lottery-fcc

JavaScript
60
star
23

foundry-play

Solidity
59
star
24

fund-me-fcc

Solidity
56
star
25

pokemon-nft

Pokémon NFTs
Solidity
54
star
26

defi-stake-yield-brownie-freecode

Solidity
53
star
27

simple_storage

Solidity
51
star
28

erc20-brownie

Solidity
50
star
29

fund_me

Solidity
48
star
30

storage-factory-fcc

Solidity
45
star
31

web3_py_simple_storage

Python
45
star
32

nextjs-nft-marketplace-moralis-fcc

JavaScript
44
star
33

lens-blog

A minimal example of using Lens Protocol to build a blog
JavaScript
39
star
34

nextjs-nft-marketplace-thegraph-fcc

JavaScript
39
star
35

hardhat-erc20-fcc

JavaScript
38
star
36

html-js-ethers-connect

JavaScript
37
star
37

nft-demo

Python
37
star
38

defi_py_mix

Solidity
36
star
39

storage_factory

Solidity
35
star
40

hardhat-defi-fcc

Solidity
35
star
41

aave_web3_py

web3.py way to interact with aave
Python
35
star
42

denver-security

Solidity
34
star
43

html-fund-me-fcc

JavaScript
32
star
44

graph-nft-marketplace-fcc

TypeScript
32
star
45

sc-language-comparison

Solidity
31
star
46

smartcontract-upgrades-example

JavaScript
28
star
47

foundry-smart-contract-lottery-f23

Solidity
27
star
48

nextjs-ethers-metamask-connect

JavaScript
26
star
49

brownie_fund_me

Solidity
25
star
50

weather-nft

chainlink weather nfts
Solidity
24
star
51

brownie_simple_storage

Python
23
star
52

chainlink-the-graph

JavaScript
22
star
53

flashloan-forta-py

Python
22
star
54

chainlink-hardhat

JavaScript
20
star
55

upgrades-mix

Solidity
19
star
56

multicall-js

JavaScript
19
star
57

signatureVerification

Solidity
18
star
58

openweathermap_cl_ea

JavaScript
17
star
59

denver-security-challenges

Solidity
17
star
60

multicall

Python
16
star
61

hardhat-upgrades-fcc

JavaScript
16
star
62

hardhat-dao-fcc

TypeScript
15
star
63

ai-stablecoin

Solidity
15
star
64

staking-ui-demo

JavaScript
15
star
65

decentralized-raffle

TypeScript
15
star
66

ipfs_cl_ea

IPFS Chainlink External Adapter
JavaScript
14
star
67

get-all-transactions

Python
14
star
68

hardhat-simple-storage

JavaScript
13
star
69

aave_brownie_py_freecode

Solidity
13
star
70

hardhat-events-logs

JavaScript
12
star
71

nextjs-moralis-metamask-connect

JavaScript
12
star
72

hardhat-metamorphic-upgrades-fcc

JavaScript
12
star
73

defi-dapp

TypeScript
12
star
74

battle-game

JavaScript
11
star
75

foundry-vyper

A package for deploying and compiling vyper code in foundry
Solidity
11
star
76

fuzzing-example

Solidity
10
star
77

vyper-chain-info

Python
10
star
78

vrf_pizza

lol
Solidity
10
star
79

dapptools-demo

Solidity
10
star
80

nextjs-web3-react-metamask-connect

JavaScript
10
star
81

eth-global-live-audit

Solidity
10
star
82

filecoin_cl_ea

JavaScript
9
star
83

puppy-raffle-smartcon

Solidity
9
star
84

ape-fund-me-v23

Python
8
star
85

erc20-brownie-py

Python
8
star
86

brownie-events-logs

Python
7
star
87

patrickalphac.com

TypeScript
7
star
88

send_blob

Python
7
star
89

unfinished-defi-workshop

JavaScript
6
star
90

vrf_pizza_front_end

lol
CSS
6
star
91

gcp-weather

Solidity
6
star
92

nextjs-web3modal-metamask-connect

JavaScript
6
star
93

smartcon-hacker-house-hunt-rules

6
star
94

hardhat-fund-me-forked-fcc

JavaScript
5
star
95

geo_db_brownie

Solidity
5
star
96

clever-lottery-web3

JavaScript
5
star
97

scavenger-hunt

TypeScript
5
star
98

nextjs-ethers-introduction-fcc

JavaScript
5
star
99

vheader

A tool for making perfect vyper headers, inspired by transmissions11
Rust
5
star
100

nextjs-usedapp-metamask-connect

JavaScript
5
star