├── Procfile ├── .gitignore ├── .env.sample ├── config.json ├── package.json ├── index.js └── README.md /Procfile: -------------------------------------------------------------------------------- 1 | web: node index.js -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | node_modules/ -------------------------------------------------------------------------------- /.env.sample: -------------------------------------------------------------------------------- 1 | SECRET_KEY=YOUR_API_KEY -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | {"load_csv_onetime":true,"loaded":true} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ExpressAPI", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node index.js" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "convert-csv-to-json": "^1.3.1", 15 | "cors": "^2.8.5", 16 | "dotenv": "^10.0.0", 17 | "express": "^4.17.1" 18 | }, 19 | "engines": { 20 | "node": "14.18.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const exp = require("express"); 2 | const app = exp(); 3 | const fs = require("fs") 4 | const { exit } = require("process"); 5 | const cors=require("cors"); 6 | require('dotenv').config() 7 | 8 | app.use(exp.json()); 9 | const corsOptions ={ 10 | origin:'*', 11 | credentials:true, 12 | optionSuccessStatus:200, 13 | } 14 | app.use(cors(corsOptions)) 15 | 16 | 17 | let csvToJson = require('convert-csv-to-json'); 18 | 19 | let rawdata = fs.readFileSync('config.json'); 20 | let config = JSON.parse(rawdata); 21 | 22 | 23 | if (!fs.existsSync('./whitelisted.csv')) { 24 | console.log("ERROR: No whitelisted.csv file has been found") 25 | exit(1) 26 | } 27 | if(!fs.existsSync('./whitelisted.json')){ 28 | csvToJson.fieldDelimiter(',') 29 | csvToJson.generateJsonFileFromCsv("whitelisted.csv", "whitelisted.json") 30 | config.loaded = true; 31 | console.log("No whitelisted.json detected, converting csv to json") 32 | } 33 | if(!config.load_csv_onetime){ 34 | csvToJson.fieldDelimiter(',') 35 | csvToJson.generateJsonFileFromCsv("whitelisted.csv", "whitelisted.json") 36 | console.log("Json reloaded: config is set csv_run_onetime = false") 37 | } 38 | else{ 39 | console.log("Skipping csv reload, config is set csv_run_onetime = true") 40 | if(!config.loaded){ 41 | config.loaded = true 42 | fs.writeFile('config.json', JSON.stringify(config), 'utf8', (err) =>{ if(err) console.log(err)}); 43 | csvToJson.fieldDelimiter(",") 44 | csvToJson.generateJsonFileFromCsv("whitelisted.csv","whitelisted.json") 45 | console.log("Data reloaded due to config loaded = false") 46 | } 47 | } 48 | 49 | 50 | 51 | 52 | app.get('/whitelisted', (req, res)=>{ 53 | let rawdata = fs.readFileSync('whitelisted.json'); 54 | let members = JSON.parse(rawdata); 55 | res.send(members) 56 | }) 57 | 58 | app.get('/whitelisted/member/:address', (req, res, value) => { 59 | let sent = false; 60 | let rawdata = fs.readFileSync('whitelisted.json'); 61 | let members = JSON.parse(rawdata); 62 | const user = members.find(c => c.member == req.params.address) 63 | if(!user){ 64 | res.status(404).send("the member was not found"); 65 | } 66 | res.send(user); 67 | }) 68 | 69 | app.put('/whitelisted/update/:address/:secret', (req, res) => { 70 | if(req.params.secret != process.env.SECRET_KEY){ 71 | res.status(404).send("Invalid Auth Key") 72 | return 73 | } 74 | let index = 0; 75 | let result = {} 76 | let rawdata = fs.readFileSync('whitelisted.json'); 77 | let members = JSON.parse(rawdata); 78 | members.forEach((whitelisted_user, i) => { 79 | if(whitelisted_user.member == req.params.address){ 80 | result = whitelisted_user 81 | index = i; 82 | } 83 | }); 84 | if(result == {}){ 85 | res.status(404).send("User does not exist") 86 | return 87 | } 88 | result.reserve = req.body.reserve 89 | members[index] = result; 90 | const data = JSON.stringify(members); 91 | fs.writeFile('whitelisted.json', data, 'utf8', (err) =>{ if(err) console.log(err)}); 92 | res.send(result) 93 | 94 | }) 95 | const port = process.env.PORT || 3000 96 | app.listen(port, ()=>console.log(`listening on port ${port}`)); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Whitelist_API 2 | 3 | 4 | ## This repo is meant to be used with https://github.com/CryptoOutcasts/Candy_Machine_Whitelist_Site 5 | ## after youre done with this repo and finalizing your API , you may proceed to Candy_Machine_Whitelist_Site 6 | This project is only experimental, use carefully. Im not responsible for any fatal errors for any project. 7 | Always use on testnet before using on mainnet 8 | This project works offchain and does not validate whitelisted users using on chain data ! 9 | This repo is intended to be used with Candy Machine Mint site, or with my repo Candy_Machine_Whitelist_Site 10 | 11 | 12 | ## How to run: 13 | Clone the repo (obviously) 14 | 15 | ### 1) Add your own environmental variables (.env) 16 | ``` 17 | SECRET_KEY=__MY_KEY__ 18 | ``` 19 | Your API authentication key used to prevent someone else from accessing the api and updating whitelisted users 20 | #### after you are done rename ".env.sample" to ".env" 21 | 22 | 23 | ### 2) create a csv containing the list of whitelisted users and reserves for each user 24 | 25 | #### REQUIREMENTS FOR CSV FILE: 26 | 1) Must be comma delimted 27 | 2) Must have two Columns: 1)member 2)reserve , Its important to name the two columns exactly like this 28 | ![example](https://i.imgur.com/PnJaoj2.png) 29 | ``` 30 | each row has a member which is the address of the user you wish to whitelist, reserve is how many nfts can they this address mint 31 | ``` 32 | 3) Must be named whitelisted.csv 33 | 4) Must be in the main directory, do not put in a seperate file called assets or similar. 34 | 35 | 36 | ### 3) Edit the config.json to your needs 37 | #### To reload the csv list everytime the script runs 38 | ```set load_csv_onetime = false``` 39 | #### If you wish to run the script once and not have it run everytime 40 | ``` 41 | set load_csv_one time = true 42 | and loaded = false 43 | ``` 44 | 45 | 46 | 47 | ### 4) Upload to a hosting server, we recommend heroku. if you decide to use heroku here are the steps to setting that up: 48 | if you prefer tutorials, this one is good and features two options: https://www.youtube.com/watch?v=Rz886HkV1j4&t=733s 49 | #### IMPORTANT: MAKE SURE TO FOLLOW THE STEPS FOR ADDING .ENV TO THE HOSTING SYSTEM (included in the video) 50 | #### ALL COMMANDS SHOULD BE RAN IN THE MAIN DIRECTORY 51 | Install the heroku CLI: https://devcenter.heroku.com/articles/heroku-cli 52 | #### ITS IMPORTANT THAT YOU SAVE ALL THE FILES YOU EDITED INORDER FOR GIT TO RECOGNIZE CHANGES 53 | 1. run: ```heroku login``` , and then login into your account. 54 | 2. run ```git init``` 55 | 3. run ```heroku create Your_Project_Name``` heroku will then supply you with two urls, one of which is the url of the API, the other is not important (the one with github in it) 56 | 4. run ```git add .``` 57 | 5. run ```git commit -m "first-commit``` 58 | 6. run ```git branch -M master``` 59 | 7. run ```git push heroku master``` 60 | 8. after that is done run ```heroku config:set SECRET_KEY=Your_API_Key``` 61 | #### Your_API_Key stands for the key you put in the env file in step 2 62 | 63 | Congratulations 🍰, you have now deployed your API online. 64 | #### to make sure everyting is working great: 65 | Grab the heroku url, or the url you hosted your api on. and then add /whitelisted to it 66 | ``` 67 | https://myherokyapp.herokuapp.com/whitelisted 68 | ``` 69 | You should see a list of your whitelisted members that you included in the csv file 70 | great that means your api is working. 71 | #### Grab the api key and heroku url and then integrate this with https://github.com/CryptoOutcasts/Candy_Machine_Whitelist_Site 72 | 73 | 74 | 75 | If you need anything you can contact me on Crypto Outcasts discord server: 76 | https://discord.gg/KTVYs7QAfP 77 | 78 | --------------------------------------------------------------------------------