• Stars
    star
    184
  • Rank 209,187 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 3 years ago
  • Updated almost 2 years ago

Reviews

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

Repository Details

Scrapes nft floor prices and additional information from opensea. Used for https://nftfloorprice.info

Opensea Scraper

DISCLAIMER: You can get accurate realtime floor prices from this official opensea API endpoint: https://api.opensea.io/api/v1/collection/{slug}/stats:

const axios = require("axios");

async function getFloorPrice(slug) {
  try {
    const url = `https://api.opensea.io/collection/${slug}/stats`;
    const response = await axios.get(url);
    return response.data.stats.floor_price;
  } catch (err) {
    console.log(err);
    return undefined;
  }
}

await getFloorPrice("lostpoets");
await getFloorPrice("treeverse");
await getFloorPrice("cool-cats-nft");

If you need floor prices, please use the official API (see above ๐Ÿ‘†๐Ÿ‘†๐Ÿ‘†). This scraper still can be used to scrape additional information about offers (tokenId, name, tokenContractAddress and offerUrl) as well as the ranking.

Install

npm install opensea-scraper

Usage

โ„น slug is the human readable identifier that opensea uses to identify a collection. It can be extracted from the URL: https://opensea.io/collection/{slug} slug

โ„น options is an object with the following keys

  • debug [Boolean] launches chromium locally, omits headless mode (default: false)
  • logs [Boolean]: display logs in the console (default: false)
  • sort [Boolean]: sorts the offers by lowest to highest (default: true)
  • additionalWait [Number]: time to wait (in milliseconds) after page was loaded before the scraping starts (default: 0)
  • browserInstance [PuppeteerBrowser]: bring your own browser instance for more control
const OpenseaScraper = require("opensea-scraper");

// which nft project to scrape?
const slug = "cool-cats-nft";

// options
const options = {
  debug: false,
  logs: false,
  sort: true,
  additionalWait: 0,
  browserInstance: undefined,
}

// get basic info (from the opensea API)
const basicInfo = await OpenseaScraper.basicInfo(slug);

// get offers from opensea. Each offer includes the 
// floor price, tokenName, tokenId, tokenContractAddress
// and offerUrl
// scrapes only the first 20 offers from opensea.
let result = await OpenseaScraper.offers(slug, options);
console.dir(result, {depth: null}); // result object contains keys `stats` and `offers`

// get offers from opensea using a custom link
// Opensea supports encoding filtering in the URL so 
// this method is helpful for getting a specific asset 
// (for example floor price for a deadfellaz with  
// a purple fur trait)
let url = "https://opensea.io/collection/deadfellaz?search[sortAscending]=true&search[sortBy]=PRICE&search[stringTraits][0][name]=Body&search[stringTraits][0][values][0]=Purple%20Fur&search[toggles][0]=BUY_NOW";
result = await OpenseaScraper.offersByUrl(url, options);
// result object contains keys `stats` and `offers`
console.dir(result, {depth: null}); 

// DISCLAIMER: FUNCTION `offersByScrolling`
// IS CURRENTLY NOT WORKING (!!!) see [issue#36](https://github.com/dcts/opensea-scraper/issues/36)
// get offersByScrolling from opensea. This is an 
// alternative method to get the same data as with
// the function `offers`, with the only difference 
// that the data is here scraped actively by scrolling 
// through the page. This method is not as efficient
// as the `offers` method, but it can scrape more 
// than 20 offers. You could even scrape a whole 
// collection with ~10k spots (this is not recommended 
// though).
// IMPORTANT: if you need less than 20 offers, 
// please use the function `offers()` instead
let resultSize = 40; 
result = await OpenseaScraper.offersByScrolling(slug, resultSize, options);
// result object contains keys `stats` and `offers`
console.dir(result, {depth: null}); 

// DISCLAIMER: FUNCTION `offersByScrollingByUrl`
// IS CURRENTLY NOT WORKING (!!!) see [issue#36](https://github.com/dcts/opensea-scraper/issues/36)
// get offersByScrollingByUrl from opensea using a 
// custom link instead of the slug. the same logic 
// applies as in `offersByScrolling()`
// Opensea supports encoding filtering in the URL so 
// this method is helpful for getting a specific asset 
// (for example floor price for a deadfellaz with  
// a purple fur trait)
// IMPORTANT: if you need less than 20 offers, 
// please use the function `offersByUrl()` instead
url = "https://opensea.io/collection/deadfellaz?search[sortAscending]=true&search[sortBy]=PRICE&search[stringTraits][0][name]=Body&search[stringTraits][0][values][0]=Purple%20Fur&search[toggles][0]=BUY_NOW";
resultSize = 40;
result = await OpenseaScraper.offersByScrollingByUrl(url, resultSize, options);
// result object contains keys `stats` and `offers`
console.dir(result, {depth: null}); 

// scrape all slugs, names and ranks from the top collections from the rankings page
// "type" is one of the following:
//   "24h": ranking of last 24 hours: https://opensea.io/rankings?sortBy=one_day_volume
//   "7d": ranking of last 7 days: https://opensea.io/rankings?sortBy=seven_day_volume
//   "30d": ranking of last 30 days: https://opensea.io/rankings?sortBy=thirty_day_volume
//   "total": scrapes all time ranking: https://opensea.io/rankings?sortBy=total_volume
// "chain" is one of the following: "ethereum", "matic", "klaytn", "solana"
//    if chain is unset, all chains will be selected by default
const type = "24h"; // possible values: "24h", "7d", "30d", "total"
const chain = "solana";
const ranking = await OpenseaScraper.rankings(type, chain, options);

Debugging

To investigate an issue turn on logs and debug mode (debug: true and logs: true):

const result = await OpenseaScraper.offers("treeverse", {
  debug: true,
  logs: true
});

Bring your own puppeteer

if you want to customize the settings for your puppeteer instance you can add your own puppeteer browser instance in the options. ๐Ÿšง IMPORTANT: I recommend using stealth plugin as otherwise you most likely won't be able to scrape opensea. If you find a way without using the stealth plugin please report in the form of an issue!

const puppeteer = require('puppeteer-extra');
// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());

const myPuppeteerInstance = await puppeteer.launch(myCustomSettings);

const result = await OpenseaScraper.offer("cool-cats-nft", {
  browserInstance: myPuppeteerInstance
});

Demo

npm run demo

Run local console / REPL

To test the functions in an REPL node environment that has OpenseaScraper service preloaded simply run:

node --experimental-repl-await -i -e "$(< init-dev-env.js)"

I recommend saving an alias:

alias consl='node --experimental-repl-await -i -e "$(< init-dev-env.js)"';

Contribute

Open PR or issue if you would like to have more features added.

Donations ๐Ÿ™

Thanks for your support!
BTC: bc1qq5qn96ahlqjxfxz2n9l20kem8p9nsz5yzz93f7
ETH: 0x3e4503720Fb8f4559Ecf64BE792b3100722dE940

nftfloorprice.info ๐Ÿ””

Simple NFT floor price alerts. Easily track all your NFTs and receive realtime email alerts with: https://nftfloorprice.info

More Repositories

1

blackjack-cli

Play a casual game of blackjack in the terminal. Written in Rust. ๐Ÿ‚ฑ๐Ÿ‚ซ
Rust
11
star
2

timeline-component

WebComponent that visualizes historical data as an interactive histogram. Written with lit-element.
JavaScript
6
star
3

holochain-hackathon-barcelona

repo used during holochain hackathon in barcelona (15.11.2019 - 17.11.2019)
HTML
5
star
4

sonicPi-compositions

some compositions (can be played in sonicPi)
Ruby
5
star
5

font-converter-ubuntu

convert any OTF (open type format) font to WOFF, WOFF2, EOT and TTF. Because online converters never work.
Shell
5
star
6

Reko

Reko is a mobile first webapp that allows you to store recommendations for movie, documentaries and series from your friends in one place.
Ruby
4
star
7

12startups12months

idea gathering
3
star
8

bullpitch

a drinking game for founders full of shit
JavaScript
3
star
9

oscListener

OSC-Listener that displays recieved OSC-messages to a canvas. For debugging or setting up a OSC-connection.
Java
3
star
10

connect4-cli

Play a casual game of connect4 in the terminal.
Rust
3
star
11

adventofcode

doing the adventofcode 2022
JavaScript
2
star
12

rust-bootcamp

LEARNING RUST, join us here: https://ubiquitous-dandelion-895.notion.site/Rust-Bootcamp-04b8ddd8f8494c4daa7dcc64f6ab90d9
Rust
2
star
13

radix.meme

The first memecoin launchpad on Radix with instant liquidity using a bonding curve.
TypeScript
2
star
14

OscRemoteControl

Control your computers keyboard and mouse remotely with your smartphone via TouchOSC. App build with processing (runs on Java).
Processing
2
star
15

algotecture-landing

algotecture blockchain - internet of buildings frontend mockup
Ruby
1
star
16

cellular-automata-demo

GUI that lets user play with different types of cellular automata. Written in matlab.
MATLAB
1
star
17

qwop-AI

Algorithm that learns to play QWOP game.
Ruby
1
star
18

LiistComponents

storybook with all LIIST components build with lit-element
JavaScript
1
star
19

WagmiBanners

Create beautiful NFT banners for Twitter.
SCSS
1
star
20

LiistChromeExtension

Chrome Extension for Liist.com to save places directly from google maps.
JavaScript
1
star
21

coinrocketapp.com

worlds fastest cryptocurrency portfolio tracker. No registration, no download, fast loadtimes! ๐Ÿš€
JavaScript
1
star
22

react-firebase-boilerplate

Boilerplate for Firebase Setup (Firestore, Hosting and Storage) with React.js
JavaScript
1
star