Catalog npm
Back to packageRELEASE DETAILS

1.0.0

npm

@0xessential/use-metadata

NFT metadata fetching

hooksreactreact-hooks
Published19 Sept 2022
Direct dependencies42
Transitive dependenciesNot calculated

README

Current package documentation

use-metadata

React hook for fetching metadata for NFTs serially across multiple providers.

NFT metadata indexing services face an immense challenge in covering every edge case for every NFT on multiple blockchains.

This React hook allows developers to specify an array of indexing services, and each will be queried in order until a successful response is returned. If no indexing service returns suitable metadata, the hook will call the contract directly for tokenURI and then fetch that URL.

Install

 yarn add @0xessential/use-metadata

MetadataProvider

Import

Import the <MetadataProvider> to wrap any components that depend on the useMetadata hook.

  // _app.tsx
  import type { AppProps } from 'next/app';
  import { MetadataProvider, infura } from '@0xessential/use-metadata';
  import React from 'react';

  function MyApp({ Component, pageProps }: AppProps) {
    return (      
      <MetadataProvider>
        <Component {...pageProps} />
      </MetadataProvider>
    );
  }

  export default MyApp;

Configure

Each supported indexer provides a configuration function that accepts arguments for authentication and network support. You must pass at least one indexer to the <MetadataProvider>.

Indexers will be queried in the order you provide them in MetadataProvider configuration.

We suggest first implementing the rpc indexer - this is a last resort service that fetches the tokenURI from the NFT contract via an RPC provider and then fetches the metadata with fetch.

Then add configuration for the indexing services you use.

rpc

The rpc indexer provides a fallback that fetches an NFT's tokenURI from the NFT contract via an RPC provider.

This should be included last in your array of indexers, but is a sensible configuration to start with.

The rpc configuration expects a URL for each network you support in your dapp.

  //...
  import { MetadataProvider, rpc } from '@0xessential/use-metadata';
  //...

  function MyApp({ Component, pageProps }: AppProps) {
    return (      
      <MetadataProvider indexers={[
        rpc({
          '1': process.env.MAINNET_RPC_URL,
          '137': process.env.POLYGON_RPC_URL
        })
      ]}>
        <Component {...pageProps} />
      </MetadataProvider>
    );
  }

  return MyApp;

Alchemy

Alchemy requires an API key per network your dApp supports. Configuration is passed as an object keyed by chain ID with objects as values with apiKey and network.

  //...
  import { MetadataProvider, alchemy } from '@0xessential/use-metadata';
  import { Network } from 'alchemy-sdk';
  //...

  function MyApp({ Component, pageProps }: AppProps) {
    return (      
      <MetadataProvider indexers={[
        alchemy({
          '1': {
            apiKey: process.env.ALCHEMY_ETH_MAINNET_API_KEY,
            network: Network.ETH_MAINNET,
          },
          '137': {
            apiKey: process.env.ALCHEMY_POLYGON_MAINNET_API_KEY,
            network: Network.MATIC_MAINNET,
          }
        })
      ]}>
        <Component {...pageProps} />
      </MetadataProvider>
    );
  }

  return MyApp;

1. Set a secret in an environment variable

The authentication token/credentials have to be made available in the CI service via environment variables. For more information, see "Authentication for plugins".

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 42

Native requirements
42 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@zoralabs/zdk
Environment
{
  "local_name": "@zoralabs/zdk",
  "alias": false,
  "peer_metadata": null
}
^2.1.8runtime
alchemy-sdk
Environment
{
  "local_name": "alchemy-sdk",
  "alias": false,
  "peer_metadata": null
}
^2.0.4runtime
ethers
Environment
{
  "local_name": "ethers",
  "alias": false,
  "peer_metadata": null
}
^5.7.1runtime
nft-react
Environment
{
  "local_name": "nft-react",
  "alias": false,
  "peer_metadata": null
}
^0.5.10runtime
react
Environment
{
  "local_name": "react",
  "alias": false,
  "peer_metadata": null
}
^16.14.0runtime
@commitlint/cli
Environment
{
  "local_name": "@commitlint/cli",
  "alias": false,
  "peer_metadata": null
}
^13.1.0development
@commitlint/config-conventional
Environment
{
  "local_name": "@commitlint/config-conventional",
  "alias": false,
  "peer_metadata": null
}
^13.1.0development
@rollup/plugin-commonjs
Environment
{
  "local_name": "@rollup/plugin-commonjs",
  "alias": false,
  "peer_metadata": null
}
^20.0.0development
@rollup/plugin-json
Environment
{
  "local_name": "@rollup/plugin-json",
  "alias": false,
  "peer_metadata": null
}
^4.1.0development
@rollup/plugin-node-resolve
Environment
{
  "local_name": "@rollup/plugin-node-resolve",
  "alias": false,
  "peer_metadata": null
}
^13.0.4development
@rollup/plugin-typescript
Environment
{
  "local_name": "@rollup/plugin-typescript",
  "alias": false,
  "peer_metadata": null
}
^8.5.0development
@semantic-release/changelog
Environment
{
  "local_name": "@semantic-release/changelog",
  "alias": false,
  "peer_metadata": null
}
^5.0.1development
@semantic-release/git
Environment
{
  "local_name": "@semantic-release/git",
  "alias": false,
  "peer_metadata": null
}
^9.0.0development
@testing-library/react-hooks
Environment
{
  "local_name": "@testing-library/react-hooks",
  "alias": false,
  "peer_metadata": null
}
^7.0.1development
@types/jest
Environment
{
  "local_name": "@types/jest",
  "alias": false,
  "peer_metadata": null
}
^26.0.24development
@types/react
Environment
{
  "local_name": "@types/react",
  "alias": false,
  "peer_metadata": null
}
^18.0.20development
@typescript-eslint/eslint-plugin
Environment
{
  "local_name": "@typescript-eslint/eslint-plugin",
  "alias": false,
  "peer_metadata": null
}
^2.34.0development
commitizen
Environment
{
  "local_name": "commitizen",
  "alias": false,
  "peer_metadata": null
}
^4.2.4development
cz-conventional-changelog
Environment
{
  "local_name": "cz-conventional-changelog",
  "alias": false,
  "peer_metadata": null
}
^3.3.0development
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
^6.8.0development
eslint-config-airbnb-typescript
Environment
{
  "local_name": "eslint-config-airbnb-typescript",
  "alias": false,
  "peer_metadata": null
}
^7.2.1development
eslint-config-prettier
Environment
{
  "local_name": "eslint-config-prettier",
  "alias": false,
  "peer_metadata": null
}
^6.15.0development
eslint-plugin-import
Environment
{
  "local_name": "eslint-plugin-import",
  "alias": false,
  "peer_metadata": null
}
^2.23.4development
eslint-plugin-jsx-a11y
Environment
{
  "local_name": "eslint-plugin-jsx-a11y",
  "alias": false,
  "peer_metadata": null
}
^6.4.1development
eslint-plugin-prettier
Environment
{
  "local_name": "eslint-plugin-prettier",
  "alias": false,
  "peer_metadata": null
}
^3.4.0development
eslint-plugin-react
Environment
{
  "local_name": "eslint-plugin-react",
  "alias": false,
  "peer_metadata": null
}
^7.24.0development
eslint-plugin-react-hooks
Environment
{
  "local_name": "eslint-plugin-react-hooks",
  "alias": false,
  "peer_metadata": null
}
^4.2.0development
git-cz
Environment
{
  "local_name": "git-cz",
  "alias": false,
  "peer_metadata": null
}
^4.7.6development
husky
Environment
{
  "local_name": "husky",
  "alias": false,
  "peer_metadata": null
}
^7.0.1development
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
^25.5.4development
lint-staged
Environment
{
  "local_name": "lint-staged",
  "alias": false,
  "peer_metadata": null
}
^11.1.1development
prettier
Environment
{
  "local_name": "prettier",
  "alias": false,
  "peer_metadata": null
}
^2.3.2development
react-test-renderer
Environment
{
  "local_name": "react-test-renderer",
  "alias": false,
  "peer_metadata": null
}
^16.14.0development
rimraf
Environment
{
  "local_name": "rimraf",
  "alias": false,
  "peer_metadata": null
}
^3.0.2development
rollup
Environment
{
  "local_name": "rollup",
  "alias": false,
  "peer_metadata": null
}
^2.55.1development
rollup-plugin-filesize
Environment
{
  "local_name": "rollup-plugin-filesize",
  "alias": false,
  "peer_metadata": null
}
^9.1.1development
rollup-plugin-peer-deps-external
Environment
{
  "local_name": "rollup-plugin-peer-deps-external",
  "alias": false,
  "peer_metadata": null
}
^2.2.4development
rollup-plugin-sourcemaps
Environment
{
  "local_name": "rollup-plugin-sourcemaps",
  "alias": false,
  "peer_metadata": null
}
^0.6.3development
rollup-plugin-terser
Environment
{
  "local_name": "rollup-plugin-terser",
  "alias": false,
  "peer_metadata": null
}
^7.0.2development
semantic-release
Environment
{
  "local_name": "semantic-release",
  "alias": false,
  "peer_metadata": null
}
^17.4.4development
ts-jest
Environment
{
  "local_name": "ts-jest",
  "alias": false,
  "peer_metadata": null
}
^25.5.1development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^4.8.3development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-cp5MfCq/Yc0CuVWp4Cq/dRNIatcVaGFNrgEuTyScoBHYq6LOuDd4u2Foi75WURSULoHmcKCcMmdkjUV3tafBdw==",
  "shasum": "8b2ee51c902d503ce5c5f1adbe06b47120078e85",
  "tarball": "https://registry.npmjs.org/@0xessential/use-metadata/-/use-metadata-1.0.0.tgz",
  "fileCount": 26,
  "unpackedSize": 11981398,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEQCIEmsJFSDuDZsatFbORZQ76eoYpll7WSHJ8Bn0w2yfr+aAiA282r025ArK4lMg3eaTosVzb5DrXwwt9MTqu184TVOyw=="
    }
  ],
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjJ7iwACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqDXw/9HitcWsLmDBBWFvl9cQdQAQ0IJbCfaqPjs+h7RY6T/7jpjVCB\r\nmOtZrD8vWohZXLkyKgDZW4ge1zZi5KArfIdDdaRatD7kGdvOovDloLHGOKKR\r\nQQLfNdmxQFNM+8fy+N9dTtdHWeTtXxi2bzUvABtFV+loYHWVv8BCuHgMNuuk\r\nXijWLTCEDcA8nenIiRz1Vfu2jgM1CH/VZbewcTE7r61HWu/qdwuKD7PmSBJ4\r\n/LZCxL80GxQP9Fpg6fsbAbYLR9a9zB/mMPjK36PXXsl5Qwgr1tfAs2Gi4l1B\r\nuvUJwVVu2y5NR24jJQbzZbO2mxqWSXL+eXsY09SavQdLewDQ7vK9suUl2+hL\r\nGNQzNIMQasW5tHNMwhxaQRFbuGmcoZOXck6Khse7dF5LRWdaaB0agedWFoFF\r\niDw9mGFaHAlC48Dnj0SB3hiEoDTDTb1dvK8y7m7YEqQ2g8vuBPdm6pDzxmw3\r\nnnnIQKi+rBD2MNKBrp4IIRBNbtMycmUnTlkOj7hJpoc7+29DIZ6Yper++YZF\r\nC+1HJT9VqZEoQdVGmx5u1fL/64EJ7g0IQWN6HQJzhvcavu3/qMHr725vhC3u\r\nF83Nd+hv2MkJ2y2dyu+cq8GS5p8v9eyAqKdwGf0289WVOfu43ILBddUElQqJ\r\nySfW3f9axUX2SFwje17SpKdcQyonhWjCJRo=\r\n=1mcD\r\n-----END PGP SIGNATURE-----\r\n"
}

Repository

PENDING
0xessential/use-metadata

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 23:07 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:2f4f2b3bde2e098e4fd06c40b91762164865f6929ceb53cd91c50f9fc75c1bc7

Other collected versions

1.1.219 Sept1.1.119 Sept1.1.019 SeptView all collected versions →