npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@solflare-wallet/nft-sdk

v1.8.0

Published

# @solflare-wallet/nft-sdk

Downloads

95

Readme

@solflare-wallet/nft-sdk

NFT SDK used in Solflare wallet.

This SDK accepts a list of mints, triggers fetching NFT metadatas, all JSONs, Metaplex groups, and does "smart" grouping of everything else using few different rules.

Contents:

Installation

$ npm install @solflare-wallet/nft-sdk

Examples

Initialize the library

  1. Use the default configuration:
import { SolflareNft } from '@solflare-wallet/nft-sdk';

const mints = [ new PublicKey(mint1), new PublicKey(mint2) ];
const solflare = new SolflareNft({ mints });
  1. Use other configuration options:
import { SolflareNft } from '@solflare-wallet/nft-sdk';

const solflare = new SolflareNft({
  mints,
  connection: web3connection // "https://api.mainnet-beta.solana.com" will be used if ommited
});

Ways to get the data

  1. SDK exposes .startFetching() method which starts fetching the data and returns a promise with all NFTs and groups. Waiting for this promise to resolve might take a lot of time for large number of NFTs, so try different method with listening for changes.
import { SolflareNft } from '@solflare-wallet/nft-sdk';

const solflare = new SolflareNft({ mints });

const response = await solflare.startFetching();

response = {
  nfts: [
    {
      id: 'mint-address-string',
      metadataAccount: MetadataAccount, // metaplex type
      updateAuthority: PublicKey,
      mint: PublicKey,
      name: 'NFT name',
      symbol: 'symbol',
      uri: 'https://uri ...',
      sellerFeeBasisPoints: 0,
      creators: Creators[], // metaplex type
      primarySaleHappened: true,
      isMutable: true,
      editionNonce: 253,
      tokenStandard: TokenStandard | null, // metaplex type
      collection: Collection | null, // metaplex type
      uses: Uses | null, // metaplex type
      metadata: JsonMetadata | null, // metaplex type, entire JSON object fetched from uri
      group: 'unique-group-identifier-address-or-slug' | null
    },
    // ...
  ],
  groups: [
    {
      id: 'unique-group-identifier-address-or-slug',
      name: 'Group name',
      image: 'uri of image used for group',
      count: 3, // number of NFTs in this group
      metaplex: true // true if grouped by verified Collection, otherwise false
    },
    // ...
  ]
}
  1. Fetch all data, but listen for change events and update each NFT that received an update
import { SolflareNft, STATUS } from '@solflare-wallet/nft-sdk';

const solflare = new SolflareNft({ mints });

solflare.startFetching();

solflare.on('message', ({ status, payload }) => {
  switch (status) {
    case STATUS.GLOBAL_START:
      console.log('Started fetching.');
      break;
    case STATUS.METADATA_FINISH:
      console.log('Fetched all Metaplex metadata accounts');
      console.log('payload', payload);
      // payload = {
      //   nfts: [ { ...nftData } ],
      //   groups: []
      // }
      break;
    case STATUS.JSON_FILE_SINGLE_FINISH:
      console.log('Fetched single JSON file');
      console.log('payload', payload);
      // payload = {
      //   nft: { SINGLE NFT THAT GOT UPDATED }
      //   nfts: [...],
      //   groups: [...]
      // }
      break;
    case STATUS.JSON_FILE_SINGLE_ERROR:
      console.log('Failed to fetch JSON file');
      console.log('payload', payload);
      // payload = {
      //   nft: { SINGLE NFT THAT FAILED LOADING JSON }
      //   nfts: [...],
      //   groups: [...]
      // }
      break;
    case STATUS.JSON_FILES_FINISH:
      console.log('Everything finished loading');
      console.log('payload', payload);
      // payload = {
      //   nfts: [...],
      //   groups: [...]
      // }
      break;
    case STATUS.GLOBAL_FINISH:
      console.log('Finished fetching.');
      break;
    default: break;
  }
});

Learn more