Skip to content

An open-source, lightweight, and portable spam classifier for cNFTs on Solana

License

Notifications You must be signed in to change notification settings

filtoor/cnft-spam-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cnft-spam-filter

An open-source, lightweight, and portable spam classifier for cNFTs on Solana with 96% accuracy.

Can run anywhere that webassembly runs: on a server, in a lambda function, and even running entirely in your browser:

demo.1.mp4

Also included is the model training code and data, so you can train and bring your own model if the default model is not performing well.

Feature extraction is done with a combination of on-chain data and OCR using the tesseract.js library. Classification is done with naive bayes and a hand-picked set of spam and ham cNFTs.

Live Example

You can try a live (heavily rate limited) example of the library running on AWS Lambda here:

https://api.filtoor.xyz/classify?address=A1xhLVywcq6SeZnmRG1pUzoSWxVMpS6J5ShEbt3smQJr

Try a new cNFT by replacing the address={...} parameter. The classifier will either spit out "spam" or "ham" (or "error" if something went wrong).

If you'd like to use this API in your production project, please DM me to get set up!

Installation

First, install the library:

npm i cnft-spam-filter

then import the requisite function:

const { extractAndClassify } = require("cnft-spam-filter")

or

import { extractAndClassify } from "cnft-spam-filter"

Finally, call the function wherever you want to classify:

const classification = await extractAndClassify(assetId, rpcUrl);

Note that you'll need to bring your own rpcUrl that supports the DAS api--I recommend Helius for their generous free plan https://www.helius.dev/.

Examples

You can find a few lightweight examples of how to use the library in different environments in the /examples folder of the repository.

cnft-spam-filter aims to be portable, so you can run it in pretty much any environment that you want.

Training

You can train your own model and pass it to classify(tokens, model). Code for this is in the /train folder.

You'll see spam_ids.json and ham_ids.json there; these are the cNFTs used to train the model.

Testing

You can test the accuracy of a model using the code in the /test folder. Make sure that your training set and test set do not overlap. It should spit out a confusion matrix as well as all of the mistakes made:

10

Usage in Production

If you want to use cnft-spam-filter in production, I recommend setting up a caching layer so that you don't have to analyze each cNFT multiple times. This should be done at your own app level: you can use redis, a database, localstorage--whatever you want.

Contributing

Feel free to open pull requests to contribute if you think this is interesting! I will try to get to them as best as I can. There are definitely some tasks that need to be implemented.

License

All code is released under the MIT license -- go crazy.

Solana/USDC donations are appreciated but not required by any means:

solarnius.sol

About

An open-source, lightweight, and portable spam classifier for cNFTs on Solana

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published