Coder Social home page Coder Social logo

sekmet / zora-nft-hooks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ourzora/nft-hooks

0.0 0.0 0.0 1.16 MB

NFT Data Fetching Hooks with Zora contract data

License: GNU General Public License v3.0

Shell 0.05% JavaScript 0.05% TypeScript 99.90%

zora-nft-hooks's Introduction

@zoralabs/nft-hooks

Simple React hooks to load Zora NFT data. Includes on-chain data, NFT metadata, and tools for fetching NFT content if needed.

Put together, these power implementations of the zNFT protocol on any website.

This library consists of a data fetch class and associated React hooks to load NFT data is an easy, efficient manner. The API both batches and caches requests, meaning you can use the hooks across a page without needing to worry about significant performance penalties.

๐Ÿ‘ฏ See also: @zoralabs/nft-components a complimentary library to this one to render NFT data on a webpage.

Install:

yarn add @zoralabs/nft-hooks

Then you can import and use the hooks in your react application:

import {useZNFT, useNFTMetadata} from "@zoralabs/nft-hooks";

function MyNFT() {
  const {data} = useZNFT("20");
  const {metadata} = useNFTMetadata(data && data.metadataURI);
  
  return (
    <div>
      <h3>{metadata.title}</h3>
      <p>{metadata.description}</p>
      <p>Owned by: {data.owner.id}</p>
    </div>
  );
}

All hooks:

Hook Usage
useNFT Fetches on-chain NFT data using a configured backend strategy
useNFTQuery Queries for NFTs using a configured backend strategy
useNFTMetadata Fetches off-chain metadata (not required for most indexers)
useNFTContent Fetches off-chain content (useful for some text content, but less often used)

Configuration:

To set the network configuration, wrap the hooks used with the NFTFetchConfiguration component.

import {Networks, NFTFetchConfiguration, Strategies} from '@zoralabs/nft-hooks';

const zdkStrategy = Strategies.ZDKFetchStrategy();

function NFTGallery() {
  return (
    <NFTFetchConfiguration strategy={zdkStrategy} network={Networks.MAINNET}>
      <NFTList>
    </NFTFetchConfiguration>
  );
}

Data sources:

Provided strategies are:

  1. ZDKFetchStrategy from the zora indexer (recommended)
  2. ZoraV2Indexer strategy from the legacy zora indexer (deprecated)
  3. ZoraGraphStrategy strategy from the zora subgraph (not recommended)
  4. EtherActorStrategy using ether.actor as a nft backend (not recommended)
  5. OpenseaStrategy using opensea's api as a nft backend (not recommended)

Links direct to zora.co interfaces, but can be overridden to directly use the zdk instead.

Development:

  1. git clone https://github.com/ourzora/nft-hooks
  2. cd nft-hooks
  3. npm i -g yarn if you don't have yarn installed
  4. yarn
  5. yarn run test test your code

Pull requests and tickets are accepted for issues and improvements to this library.

zora-nft-hooks's People

Contributors

iainnash avatar olegakbarov avatar dblodorn avatar javamonn avatar neokry avatar

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.