Niftory Docs
  • What is Niftory?
  • Get your API Keys
  • 👩‍💻API
    • Niftory Web3 API
    • SDK QuickStart
      • Using the SDK in React
      • Using the SDK from the Server
    • API Quickstart
      • Create your first Wallet
      • API calls with Sample Content
      • Mint your first NFT
    • API Cheat Sheet
    • Niftory Sample App
      • Explore the Sample App
      • Anatomy of a Niftory App
        • Getting Authenticated
        • GraphQL Client Setup
        • API Usage
        • Transfer an NFT
    • 💡Core Concepts
      • Niftory Data Model
      • Authentication
        • Using Your API Key
        • Configuring Your App
        • Privileged Authentication
      • App and AppUser
      • NFTs
        • Creating NFTs
        • Querying NFTs
        • Transferring NFTs
        • Minting NFTs
      • Wallets
        • Create a Niftory Wallet
        • Register External Wallets
        • Query Wallets
      • Contract
      • User Auth (Client-Side)
    • Your Niftory Account
  • 🧑‍💼Admin Portal
    • Niftory Admin Portal
    • 🚀Guides
      • Setting Up Your Org
      • Create Your First NFT
    • 🗺️Explore
      • Org and Apps
      • NFT Collection
        • Sets
        • Collectibles
        • NFTs
    • 💼Use Cases
      • For Engineers
      • For Designers
      • For Business Users
  • 📖Reference
    • GraphQL & Auth Endpoints
    • API Reference
    • SDK API Reference
Powered by GitBook
On this page

Was this helpful?

  1. API
  2. SDK QuickStart

Using the SDK in React

First, make sure you've installed the Niftory SDK on your project with:

yarn add @niftory/sdk

Now, you need to wrap your entire app with a NiftoryProvider and pass in an instance of NiftoryClient as follows:

  import { NiftoryProvider } from "@niftory/sdk/react"
  import { NiftoryClient } from "@niftory/sdk"

  // _app.tsx
  const authToken = "YOUR_AUTH_TOKEN"
  const client = useMemo(() => {
    return new NiftoryClient({
      appId: process.env.NEXT_PUBLIC_CLIENT_ID,
      environmentName: process.env.NEXT_PUBLIC_ENV,
      apiKey: process.env.NEXT_PUBLIC_API_KEY,
      authToken,
    })
  }, [authToken])

  return (
    <NiftoryProvider client={client}>
     ....
    </NiftoryProvider>)

Now, you now call the exported react hooks as follows:

import { useWalletQuery, useRegisterWalletMutation, useNiftoryClient } from "@niftory/sdk/react"

const MyComponent = () => {
  // Query
  const [userWalletResponse, reExecuteQuery] = useWalletQuery()
  // Mutation
  const [{ data, fetching }, registerWallet] = useRegisterWalletMutation()
  // Use client directly
  const niftoryClient = useNiftoryClient()

  if (userWalletResponse.fetching) {
    return <div>...Loading</div>
  }

  const { wallet } = userWalletResponse.data

  return (
    <>
      {wallet && <p>Your wallet address is {wallet.address}</p>}{" "}
      {<button onClick={() => registerWallet({ address: "0x123456" })}>Register Wallet</button>}
    </>
  )
}

For examples of react usage, you can check out our sample apps using the Niftory SDK:

PreviousSDK QuickStartNextUsing the SDK from the Server

Last updated 1 year ago

Was this helpful?

Note: This client created above uses and you need to pass in your usersauthToken after your user is authenticated. API calls that do not require user authorization (generally queries like nftModels) will still function if authToken isn't provided. Important Note: In typescript projects, to use the react imports (providers and hooks) you might need your compilerOptions in tsconfig moduleResolution to be set as nodenext

The hooks are always named in the format useQuery for queries and useMutation for mutations. For APIName, you can view Niftory API docs .

👩‍💻
user auth
[APIName]
[APIName]
here
https://github.com/Niftory/niftory-samples