• Stars
    star
    349
  • Rank 117,660 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated about 2 years ago

Reviews

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

Repository Details

A repo for generating random NFTs with metadata 100% on chain!

Random NFT logo


All On Chain Generated NFT

This is a repo that shows 2 things:

  1. How to create NFTs with metadata that is 100% on-chain
  2. How we can generate random art on-chain using the SVG method

Inspired by the NFT Brownie Mix

About SVGs

SVG means "Scalable Vector Graphics", and is an XML language and can be used to create an image either by specifying all the lines and shapes necessary, by modifying already existing raster images, or by a combination of both.

We can then base64 encode this SVG string into a URL that we can set as the imageURI in our NFT tokenURI. Like this triangle

You can learn everything about SVG parameters and try some examples here.

We are going to use the following path data commands because they each only take 2 parameters

M = moveto
L = lineto 

However, there are a lot more. You can see sample SVGs in the img folder. These get base64 encoded to URLs. You can see an example of a randomly generated base64 URL here.

Requirements

Installation

Set your RINKEBY_RPC_URL environment variable.. You can get one for free at Infura's site. You'll also need to set the variable PRIVATE_KEY which is your private key from you wallet, ie MetaMask. This is needed for deploying contracts to public networks.

You can set these in your .env file if you're unfamiliar with how setting environment variables work. Check out our .env example. If you wish to use this method to set these variables, update the values in the .env.example file, and then rename it to '.env'

WARNING WARNING WARNING

Don't commit and push any changes to .env files that may contain sensitive information, such as a private key! If this information reaches a public GitHub repository, someone can use it to check if you have any Mainnet funds in that wallet address, and steal them!

.env example:

RINKEBY_RPC_URL='www.infura.io/asdfadsfafdadf'
PRIVATE_KEY='abcdef'
MAINNET_RPC_URL="https://eth-mainnet.alchemyapi.io/v2/your-api-key"

bash example

export RINKEBY_RPC_URL='www.infura.io/asdfadsfafdadf'
export PRIVATE_KEY='cat dog frog...'
export MAINNET_RPC_URL="https://eth-mainnet.alchemyapi.io/v2/your-api-key"

If you plan on deploying to a local Hardhat network that's a fork of the Ethereum mainnet instead of a public test network like Kovan, you'll also need to set your MAINNET_RPC_URL environment variable. and uncomment the forking section in hardhat.config.js. You can get one for free at Alchemy's site..

You can also use a MNEMONIC instead of a PRIVATE_KEY environment variable by uncommenting the section in the hardhat.config.js, and commenting out the PRIVATE_KEY line.

Then you can install all the dependencies

git clone https://github.com/patrickalphac/all-on-chain-generated-nft
cd all-on-chain-generated-nft

then

npm install

Or

yarn

Quickstart / Deploy

Deployment scripts are in the deploy directory. If required, edit the desired environment specific variables or constructor parameters in each script, then run the hardhat deployment plugin as follows. If no network is specified, it will default to the Kovan network.

SVGNFT Deployment

This will deploy to a local hardhat network.

npx hardhat deploy --tags svg

To deploy to testnet:

You'll need testnet ETH in your wallet

npx hardhat deploy --network rinkeby --tags svg

Random SVG Deployment

This will deploy to a local hardhat network.

npx hardhat deploy --tags rsvg

To deploy to testnet:

You'll need testnet LINK and ETH in your wallet

npx hardhat deploy --network rinkeby --tags rsvg

This will also call the create function after deploying and request a random number from a Chainlink node. And it will call finishMint to finalize the minting.

Create NFT & View on OpenSea

Once deployed, each will look something like this:

SVGNFT Opensea Random SVG Opensea Another Random SVG Opensea

Important notes for SVGs

  1. Make sure all the double quotes are single quotes

Using SVGs will allow you to make all the drawings directly on-chain, and store them on chain too! For example, you could store an SVG as a string, and then edit it to change your drawings.

Other Notes

  1. I wasn't able to make data:image/png types work as an imageURI, but hypothetically it should.

Test

Tests are located in the test directory, and are split between unit tests and integration tests. Unit tests should only be run on local environments, and integration tests should only run on live environments.

To run unit tests:

npx harhat test

Verify on Etherscan

You'll need an ETHERSCAN_API_KEY environment variable. You can get one from the Etherscan API site.

npx hardhat verify --network <NETWORK> <CONTRACT_ADDRESS> <CONSTRUCTOR_PARAMETERS>

example:

npx hardhat verify --network kovan 0x9279791897f112a41FfDa267ff7DbBC46b96c296 "0x9326BFA02ADD2366b30bacB125260Af641031331"

Linting

yarn lint:fix

More Repositories

1

nft-mix

Solidity
803
star
2

dungeons-and-dragons-nft

#chainlink #nft
JavaScript
603
star
3

hardhat-security-fcc

Solidity
400
star
4

dao-template

TypeScript
239
star
5

full-stack-web3-metamask-connectors

177
star
6

chainlink_defi

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

smart-contract-frameworks

A list of smart contract frameworks
C
119
star
8

hardhat-smartcontract-lottery-fcc

JavaScript
113
star
9

hardhat-nft-marketplace-fcc

JavaScript
112
star
10

hardhat-nft-fcc

JavaScript
99
star
11

simple-storage-fcc

Solidity
93
star
12

unstoppable-ui

JavaScript
88
star
13

async-python

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

hardhat-fund-me-fcc

JavaScript
82
star
15

ethers-simple-storage-fcc

JavaScript
82
star
16

defi-stake-yield-brownie

Solidity
78
star
17

smartcontract-lottery

Solidity
75
star
18

PatrickAlphaC

75
star
19

hardhat-simple-storage-fcc

JavaScript
68
star
20

aave_brownie_py

Solidity
61
star
21

foundry-play

Solidity
58
star
22

nextjs-smartcontract-lottery-fcc

JavaScript
57
star
23

pokemon-nft

PokΓ©mon NFTs
Solidity
54
star
24

defi-stake-yield-brownie-freecode

Solidity
53
star
25

fund-me-fcc

Solidity
52
star
26

simple_storage

Solidity
51
star
27

erc20-brownie

Solidity
50
star
28

fund_me

Solidity
48
star
29

web3_py_simple_storage

Python
45
star
30

storage-factory-fcc

Solidity
44
star
31

nextjs-nft-marketplace-moralis-fcc

JavaScript
44
star
32

lens-blog

A minimal example of using Lens Protocol to build a blog
JavaScript
40
star
33

nextjs-nft-marketplace-thegraph-fcc

JavaScript
39
star
34

nft-demo

Python
38
star
35

hardhat-erc20-fcc

JavaScript
37
star
36

html-js-ethers-connect

JavaScript
36
star
37

defi_py_mix

Solidity
36
star
38

storage_factory

Solidity
35
star
39

aave_web3_py

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

rwa-creator

Solidity
35
star
41

hardhat-defi-fcc

Solidity
34
star
42

graph-nft-marketplace-fcc

TypeScript
32
star
43

sc-language-comparison

Solidity
30
star
44

denver-security

Solidity
28
star
45

smartcontract-upgrades-example

JavaScript
28
star
46

html-fund-me-fcc

JavaScript
27
star
47

foundry-smart-contract-lottery-f23

Solidity
27
star
48

brownie_fund_me

Solidity
25
star
49

nextjs-ethers-metamask-connect

JavaScript
24
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

openweathermap_cl_ea

JavaScript
17
star
57

multicall-js

JavaScript
17
star
58

hardhat-upgrades-fcc

JavaScript
17
star
59

denver-security-challenges

Solidity
16
star
60

ai-stablecoin

Solidity
15
star
61

multicall

Python
15
star
62

staking-ui-demo

JavaScript
15
star
63

decentralized-raffle

TypeScript
15
star
64

ipfs_cl_ea

IPFS Chainlink External Adapter
JavaScript
14
star
65

hardhat-dao-fcc

TypeScript
14
star
66

get-all-transactions

Python
14
star
67

signatureVerification

Solidity
14
star
68

aave_brownie_py_freecode

Solidity
13
star
69

hardhat-events-logs

JavaScript
12
star
70

hardhat-simple-storage

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

vyper-chain-info

Python
10
star
77

vrf_pizza

lol
Solidity
10
star
78

dapptools-demo

Solidity
10
star
79

nextjs-web3-react-metamask-connect

JavaScript
10
star
80

filecoin_cl_ea

JavaScript
9
star
81

ape-fund-me-v23

Python
8
star
82

fuzzing-example

Solidity
8
star
83

eth-global-live-audit

Solidity
8
star
84

erc20-brownie-py

Python
8
star
85

puppy-raffle-smartcon

Solidity
7
star
86

brownie-events-logs

Python
7
star
87

unfinished-defi-workshop

JavaScript
6
star
88

vrf_pizza_front_end

lol
CSS
6
star
89

patrickalphac.com

TypeScript
6
star
90

nextjs-web3modal-metamask-connect

JavaScript
6
star
91

smartcon-hacker-house-hunt-rules

6
star
92

hardhat-fund-me-forked-fcc

JavaScript
5
star
93

geo_db_brownie

Solidity
5
star
94

clever-lottery-web3

JavaScript
5
star
95

scavenger-hunt

TypeScript
5
star
96

nextjs-ethers-introduction-fcc

JavaScript
5
star
97

nextjs-usedapp-metamask-connect

JavaScript
5
star
98

gcp-weather

Solidity
4
star
99

hackathon_scraper

Python
4
star
100

pizza_cl_ea

JavaScript
4
star