/js

Primary LanguageTypeScriptApache License 2.0Apache-2.0

Overview

Getting Started

yarn add @underdog-protocol/js

Example

Add API Route

// pages/api/underdog/[...underdog].ts

import { NextUnderdog, NetworkEnum } from "@underdog-protocol/js";

export default NextUnderdog({
  apiKey: process.env.UNDERDOG_API_KEY,
  network: NetworkEnum.Devnet,
});

Add React Hook

// components/Component/index.tsx

import { useNft, GetNftInput } from "@underdog-protocol/js"

export default function Component() {
  const { nft, loading, refetch } = useNft({
    type: {
      transferable: false,
      compressed: true,
    },
    projectId: 1,
    nftId: 0,
  });

  if (!nft || loading) return null;

  return <p>{nft.name}</p>;
}

Cache Underdog State

// pages/_app.tsx

import { AppProps } from "next/app";
import { UnderdogProvider } from "@underdog-protocol/js";

export default function App({ Component, pageProps }: AppProps) {
  return (
    <UnderdogProvider>
      <Component {...pageProps} />
    </UnderdogProvider>
  );
}