Giter Site home page Giter Site logo

dungeons-and-dragons-nft's Introduction

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.

dungeons-and-dragons-nft's People

Contributors

patrickalphac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dungeons-and-dragons-nft's Issues

unable to access 'https://github.com/ethereumjs/ethereumjs-abi.git/': GnuTLS recv error (-110): The TLS connection was non-properly terminated.

hi I enter comands in my Ubuntu below:
git clone https://github.com/PatrickAlphaC/dungeons-and-dragons-nft
cd dungeons-and-dragons-nft
yarn
but it shows error below:

warning @chainlink/test-helpers > @0x/subproviders > ganache-core > ethereumjs-vm > ethereumjs-blockchain > [email protected]: New package name format for new versions: @ethereumjs/ethash. Please update.
warning @chainlink/test-helpers > @0x/sol-trace > web3-provider-engine > eth-block-tracker > json-rpc-engine > babelify > babel-core > babel-register > [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
warning @chainlink/test-helpers > @0x/sol-trace > web3-provider-engine > eth-block-tracker > json-rpc-engine > babelify > babel-core > babel-runtime > [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
warning @chainlink/test-helpers > @0x/subproviders > ganache-core > patch-package > find-yarn-workspace-root > micromatch > snapdragon > [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
warning @chainlink/test-helpers > @0x/subproviders > ganache-core > patch-package > find-yarn-workspace-root > micromatch > snapdragon > source-map-resolve > [email protected]: https://github.com/lydell/resolve-url#deprecated
warning @chainlink/test-helpers > @0x/subproviders > ganache-core > patch-package > find-yarn-workspace-root > micromatch > snapdragon > source-map-resolve > [email protected]: See https://github.com/lydell/source-map-url#deprecated
warning @chainlink/test-helpers > @0x/subproviders > ganache-core > patch-package > find-yarn-workspace-root > micromatch > snapdragon > source-map-resolve > [email protected]: Please see https://github.com/lydell/urix#deprecated
error Command failed.
Exit code: 128
Command: git
Arguments: fetch --tags
Directory: /home/gilsun91/.cache/yarn/v6/.tmp/c8a1082f4d0cf2d24e10ae2d0b9c32e3
Output:
fatal: unable to access 'https://github.com/ethereumjs/ethereumjs-abi.git/': GnuTLS recv error (-110): The TLS connection was non-properly terminated.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

How to solve it? thank you.
By the way , there is no yarn.lock in this directory.

.env

Hi, Patrick

Can you please only leave the .env.example file and delete the .env one?
Us newbies might end up leaving our mneumonic exposed, because .gitignore does not ignore files that are already there on github.

Thanks for all the top-notch teaching.

Hey Patrick, I needed help on this one.

Running
truffle migrate --reset --network rinkeby

Compiling your contracts...

Compiling ./contracts/DungeonsAndDragonsCharacter.sol
Compiling ./contracts/Migrations.sol
Compiling @chainlink/contracts/src/v0.6/VRFConsumerBase.sol
Compiling @chainlink/contracts/src/v0.6/VRFRequestIDBase.sol
Compiling @chainlink/contracts/src/v0.6/interfaces/LinkTokenInterface.sol
Compiling @chainlink/contracts/src/v0.6/vendor/SafeMath.sol
Compiling @openzeppelin/contracts/GSN/Context.sol
Compiling @openzeppelin/contracts/access/Ownable.sol
Compiling @openzeppelin/contracts/introspection/ERC165.sol
Compiling @openzeppelin/contracts/introspection/IERC165.sol
Compiling @openzeppelin/contracts/math/SafeMath.sol
Compiling @openzeppelin/contracts/token/ERC721/ERC721.sol
Compiling @openzeppelin/contracts/token/ERC721/IERC721.sol
Compiling @openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
Compiling @openzeppelin/contracts/token/ERC721/IERC721Metadata.sol
Compiling @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol
Compiling @openzeppelin/contracts/utils/Address.sol
Compiling @openzeppelin/contracts/utils/EnumerableMap.sol
Compiling @openzeppelin/contracts/utils/EnumerableSet.sol
Compiling @openzeppelin/contracts/utils/Strings.sol
Compilation warnings encountered:

/home/lion/Desktop/blockchain/nft/dungeons-and-dragons-nft/contracts/DungeonsAndDragonsCharacter.sol:162:5: Warning: Function state mutability can be restricted to pure
function sqrt(uint256 x) internal view returns (uint256 y) {
^ (Relevant source part starts here and spans across multiple lines).

Artifacts written to /home/lion/Desktop/blockchain/nft/dungeons-and-dragons-nft/build/contracts
Compiled successfully using:

  • solc: 0.6.6+commit.6c089d02.Emscripten.clang

Duplicate contract names found for SafeMath.
This can cause errors and unknown behavior. Please rename one of your contracts.
Error: Unknown arguments format passed to new HDWalletProvider. Please check your configuration and try again
at Object.exports.getOptions (/home/lion/Desktop/blockchain/nft/dungeons-and-dragons-nft/node_modules/@truffle/hdwallet-provider/src/constructor/getOptions.ts:141:11)
at new HDWalletProvider (/home/lion/Desktop/blockchain/nft/dungeons-and-dragons-nft/node_modules/@truffle/hdwallet-provider/src/index.ts:53:9)
at Object.provider (/home/lion/Desktop/blockchain/nft/dungeons-and-dragons-nft/truffle-config.js:7:16)
at Object.getProvider (/usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:20:1)
at Object.create (/usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:13:1)
at TruffleConfig.get [as provider] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/config/dist/configDefaults.js:204:1)
at Object.detect (/usr/local/lib/node_modules/truffle/build/webpack:/packages/environment/environment.js:19:1)
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:205:1)
at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:136:1)
Truffle v5.1.67 (core: 5.1.67)
Node v15.5.0

Not transferring NFT smart contract to test opensea via setTokenURI and metadata file

Hi - thanks for this great resource it has been extremely useful in helping me build NFT smart contracts.

I have made it through every step but am having trouble at the last part - transferring to OpenSea.

scripts/set-token-uri.js works and produces the below output:

Let's set the tokenURI of your characters
{
  tx: '0xcc0bc3d1734b5af8d17cdb35db372e66b861933ba8c0531d4021655a4cdd5169',
  receipt: {
    blockHash: '0xc631dfd809ac2220649398301e77f79ecdafc9852695a38fce23479f63d6a1b1',
    blockNumber: 9107658,
    contractAddress: null,
    cumulativeGasUsed: 1761662,
    effectiveGasPrice: '0x3b9aca09',
    from: '0x03485453f0b0511dd6bd4173ad05093b1e0313de',
    gasUsed: 49245,
    logs: [],
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    status: true,
    to: '0xc2c90f5b3a757625c55635901542c3b488cc9788',
    transactionHash: '0xcc0bc3d1734b5af8d17cdb35db372e66b861933ba8c0531d4021655a4cdd5169',
    transactionIndex: 14,
    type: '0x0',
    rawLogs: []
  },
  logs: []
}
0xcc0bc3d1734b5af8d17cdb35db372e66b861933ba8c0531d4021655a4cdd5169
Truffle v5.4.0 (core: 5.4.0)
Node v12.22.4

However when I plugin what I think is the smart contract address for OpenSea test net at 'to:0xc2c90f5b3a757625c55635901542c3b488cc9788' above.. the page that results at OpenSea finally doesn't hold any content?[https://testnets.opensea.io/assets/0xc2c90f5b3a757625c55635901542c3b488cc9788/0](https://testnets.opensea.io/assets/0xc2c90f5b3a757625c55635901542c3b488cc9788/0)

Also the contractAddress field is null ?

I feel i may need to go back a step or two. The .json metadata file and the image file are both at IPFS and pinned.

Any ideas much appreciated. Thank you!

Try to verify and contract and having the following error.

Installed the truffle-verify-plugin
and run command truffle run verify DungeonsAndDragonsCharacter --network rinkeby --license MIT

Giving following error:
Verifying DungeonsAndDragonsCharacter
Cannot find module '@chainlink/contracts/src/v0.6/VRFConsumerBase.sol'

I need help please Patrick

Hello Patrick, I'm a newbie on smart contract and I need urgent help. I followed this repo https://github.com/PatrickAlphaC/dungeons-and-dragons-nft.
It worked on rinkeby perfectly. I saw this repo only works on testnet but I deployed my smart contract to mainnet :(( and already paid the fee. It's my mistake, sorry. When running scripts/generate-character.js file, it says that error 'execution reverted'. Can I continue deploy my nft to mainnet using this repo? Please help me :(( I funded my contract with Chainlink. Sorry for my bad english.

Screen Shot 2021-12-24 at 00 23 55

Thank your for your awesome tutorials

d&d not deploying to network

when i run truffle migrate --reset --network rinkeby its not stopping and after completing 50 blocks i got timeout Error.

i tried configuring provider object like this:
rinkeby: {
provider: () => {
return new HDWalletProvider(MNEMONIC, rinkebyNodeUrl);
},
network_id: "4",
gas: 5000000,
networkCheckTimeout: 1000000,
timeoutBlocks: 200,
},

but its still not working, how can i solve this issue?
Screenshot (15)

get-character.js

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.

I don't see calling of getCharacterOverView method in the get-character.js. Should we changing dnd.characters(0) to '1' to set the first character array?

Thanks

ERC721: operator query for nonexistent token

Hi :) When I run "set-token-uri.js", it gives that error "ERC721: operator query for nonexistent token". I need this repo to create my NFT by example. Please help :).
Also, There is another question: What are RINKEBY_VRF_COORDINATOR, RINKEBY_LINKTOKEN, RINKEBY_KEYHASH?
Here is the error image.
Screen Shot 2021-12-23 at 02 40 59

Error: Transaction: 0x12624ab93********** exited with an error (status 0) after consuming all gas

Hey, @PatrickAlphaC i have cloned latest code of this repo.

So, i successfully deployed the D&D character: 0xA0813f82C27c18d2a0f9582Cb3a38919C43D9b29.

But, when i tired to execute funding script i got this error:
image

Transaction: 0x12624ab938d0756cc33a9cbc9dc9168a5895cee29dd09157c7d96b4f874dd1a5.

Even with manual funding i'm getting error:
image

And after that transaction just fails.

Can you please help me out with that.
Thank you.

Problem running `generate-character.js`

I managed to fund the contract but when I try to run the generate-character script truffle exec scripts/generate-character.js --network rinkeby I get this error:

const tx = await dnd.requestNewRandomCharacter("The Chainlink Knight")

StatusError: Transaction: 0xXXXXX exited with an error (status 0). 
    at module.exports (dungeons-and-dragons-nft/scripts/generate-character.js:6:24)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

The console output seems to indicate that there is an issue with the requestNewRandomCharacter method but to the best of my knowledge it is called correctly. Any support will be much appreciated!

fund-contract.js invalid opcode: INVALID

Hi ,after did the procedure "Clone The Repo and migrate" successfully and then "Generate a character", I enter comand below, it shows invalid information:

~/nft2/dungeons-and-dragons-nft-master$ pwd
/home/gilsun91/nft2/dungeons-and-dragons-nft-master
~/nft2/dungeons-and-dragons-nft-master$ truffle exec scripts/fund-contract.js --network rinkeby
Using network 'rinkeby'.

Chainlink Token Address:  0x01BE23585060835E02B77ef475b0Cc51aA1e0709
Funding contract: 0x0D553cb0AE3E56DCDEF188347977A31AA8b9768f
invalid opcode: INVALID
Truffle v5.5.3 (core: 5.5.3)
Node v16.14.0

So ,what is the problem and how to solve it ? Thank you .

Dynamic variable experience

Hi Patrick,

I am new into this world, and this could be a trivial question. But, I do not see how is experience parameter/variable of the NFT changed. How? Where?

Sorry, but you can explain a little this?

Thanks in advance,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.