Code Monkey home page Code Monkey logo

rarity-analyser's Introduction

Cool Rarity

Cool Rarity is an open source package for easy rarity score calculation.

Cool Rarity was born in a Hackathon hosted by PunkScape, made with love by Fukuball. It is easy to configure for developers and easy to use for users, any ERC721 NFT collection with OpenSea metadata stardard can use Cool Rarity as the rarity score calculation tool. If you have the collection metadata in hand, you can depoly Cool Rarity as your collection rarity tool in minues!

Here's the demo:

Prerequisites

Cool Rarity was built using Node.js, so you have to install:

  • Node.js (v14.x)
  • NPM

I personally use Yarn and NVM, so you can consider install them too:

  • Yarn
  • NVM

Run Cool Rarity locally

Step 1: Clone from GitHub

$ git clone https://github.com/fukuball/rarity-analyser.git

Step 2: Configure collection data

You should have the collection metadata on hand, or you can use the default collection.json provided by Cool Rarity, be sure your collection metadata is formated like the default collection.json.

Put your collection metadata json file (all token metadata in one json file!) in config folder, the same location as the default collection.json, then open the config.js in the folder, modify it for your collection.

Here's the content of config.js:

{
    app_name: 'Cool Rarity',
    app_description: 'A cool rarity tool.',
    collection_file_name: 'collection.json',
    collection_contract_address: '0x5537d90a4a2dc9d9b37bab49b490cf67d4c54e91',
    collection_name: '10k One Day Punks',
    collection_description: '10k "One Day I\'ll Be A Punk"-punks – a homage to the one and only CryptoPunks. Holding a OneDayPunk will give you early access to PunkScapes and reserve a profile on the PunkScape website.',
    sqlite_file_name: 'database.sqlite',
    ga: 'G-BW69Z04YTP',
    main_og_image: 'https://onedaypunk-rarity-tool.herokuapp.com/images/og.png'
}
  • app_name: You can name your rarity app here.
  • collection_file_name: Your NFT collection metadata file name, the metadata file you put in config folder.
  • collection_contract_address: Your NFT collection smart contract address, will use to show the "View on OpenSea" link.
  • collection_name: Your NFT collection name.
  • sqlite_file_name: SQLite database file name, no need to change.
  • ga: If you want to use Google Analytic, then change to your code.
  • main_og_image: You can set default open graph image here.

Step 3: Install package

$ yarn install

When package installed, postinstall script will be tiggered, and the ./cmd/rarity_analyze.js will run for the first install. This will take some time for the rarity score calculation. (generally in minues)

Final Step: Run

$ DEBUG=rarity-analyser:* yarn start-dev

Then open: http://localhost:3000/ on your web browser. Yes! Now you see the rarity website of your NFT collection!

Extra

You can generate collection-rarities.json file by using this command:

yarn rarity-output-json

The collection-rarities.json file will store in config folder.

Deploy to Heroku

Step 1: Prerequisites

Step 2: Login and Create App

In your Cool Rarity folder:

$ heroku login
$ heroku create your_app_name

Final Step: Deploy

$ git push heroku main

If you have any update want to deploy to Heroku, just use this final step to deploy to Heroku.

Use One Click Heroku Deploy

Here you can deploy this rarity tool to Heroku in one click, just be sure you have the Heroku account.

Deploy

Tasks

Hackathon Tasks

  • The app lets the deployer configure a collection json file like this one: collection.json
  • Take all metadata items and analyse their attributes.
  • Derive a rarity score for each attribute of each NFT item. Example: Property "Type", Attribute "Ape"; 24 of 10000 have this attribute/property combination; rarity_score = 1/(24/10000) = 416.67
  • Derive a rarity score for each NFT in the collection. The rarity score for each NFT is the sum of all attributes.
  • Account for missing trait_types of an NFT.
  • Account for the trait_count of an NFT.
  • Calculate the Rarity Score for each token (SUM of all rare trait attributes / missing traits / trait counts).
  • Compute and store a collection-rarities.json file which can be exported for use elsewhere for the given collection.

Additional Tasks

  • Search by ID and sort by rarity or ID.
  • Put OpenSea link and offlicial site link.
  • Endpoint of JSON rarity data for every punk.
  • Test with other ERC721 collection metadata.
  • Matrix page.
  • Similarity analysis, create one page to show top 12 similar for every punk.

Other Rarity Tools

Our Friends (One Day Punk) - Also making cool tools!

Other

Support

Thanks to [PunkScape](https://punkscape.xyz) Community for this initiative.

rarity-analyser's People

Contributors

4nt1m4tt3r avatar fukuball 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

Watchers

 avatar

rarity-analyser's Issues

SqliteError: no such table: undefined at return this[cppdb].prepare(sql, this, false);

The rarity app is running fine on localhost. this script is failing.

rarity-analyser-main$ yarn rarity-output-json
yarn run v1.22.17
$ node ./cmd/rarity_output_json.js
Process punk: #1

/mnt/c/Users/family/rarity-tool-git/rarity-analyser-main/node_modules/better-sqlite3/lib/methods/wrappers.js:5
return this[cppdb].prepare(sql, this, false);
^
SqliteError: no such table: undefined
at Database.prepare (/mnt/c/Users/family/rarity-tool-git/rarity-analyser-main/node_modules/better-sqlite3/lib/methods/wrappers.js:5:21)
at Object.exports.punk (/mnt/c/Users/family/rarity-tool-git/rarity-analyser-main/modules/jsondata.js:18:22)
at /mnt/c/Users/family/rarity-tool-git/rarity-analyser-main/cmd/rarity_output_json.js:33:46
at Array.forEach ()
at Object. (/mnt/c/Users/family/rarity-tool-git/rarity-analyser-main/cmd/rarity_output_json.js:28:7)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
rarity-analyser-main$

Deploy on different EVM

Hey 👋 question here how do you deploy it to a different Blockchain EVM ( network) like fantom

Ignore certain trait types

Hi, loving your work! Could there possibly be a way to ignore certain trait types in the rarity calculations? I have a collection where certain trait types are unique to every NFT - so don't really form part of the rarity of each piece. Thanks.

Rarity output json

Hello, thanks for the contribution! I’m stacked on an error when I push ‘yarn rarity-output-json’. Seems It doesn’t find the path of the database. Could you help me?

Rarity calculation question

Hi @fukuball, love the project. Got a question about the calculations!

When you say the following:

Account for missing trait_types of an NFT.
Account for the trait_count of an NFT.
rarity_score = 1/(24/10000) = 416.67
Calculate the Rarity Score for each token (SUM of all rare trait attributes / missing traits / trait counts).

a) What exactly do you mean by accounting for it? Does it mean that you count how many traits are missing per NFT?
b) Can you provide me a full example of the final rarity score calculation or let me know if my explanation below is correct?

For every trait, we calculate the rarity score ( 1/(trait_type_count/collection_size) ), then we divide that by the number of missing traits (let's say 1 in this instance), and then, at last, we divide by the number of trait categories available in the collection (for example, BAYC has 7 total).

So in total, that would be (BAYC example with the Eyes trait "Blue Beams"):

rarity_score = (1/(trait_type_count/collection_size)) / num_missing_traits / num_traits_in_collection. 
rarity_score = (1/(49/10000)) / 1 / 7. 

Edit: Or is it the number of traits in the NFT instead of the number of missing traits?

rarity_score = (1/(trait_type_count/collection_size)) / num_traits_in_token / num_traits_in_collection. 
rarity_score = (1/(49/10000)) / 6 / 7. 

c) How does your trait normalization work? I see you are defining some mean values, but I am having a hard time deciphering how exactly they are used.

d) Is your rarity calculations equal to the ones on rarity.tools v2 without additional weighting?

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.