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. Niftory Sample App
  3. Anatomy of a Niftory App

GraphQL Client Setup

PreviousGetting AuthenticatedNextAPI Usage

Last updated 1 year ago

Was this helpful?

The sample uses to interact with Niftory's GraphQL endpoints.

For production use-cases, we recommend using or clients.

Revisit for starting with GraphQL.

POST https://graphql.api.niftory.com

Your production GraphQL Endpoint for all Niftory Requests.

\

Targets blockchain prod.

Headers

Name
Type
Description

X-Niftory-API-Key**

String

Your Niftory API Key

Authorization

String

Bearer token containing the user's JWT. See

.

{
    // Response
}

POST https://graphql.api.staging.niftory.com

Your staging GraphQL Endpoint for all Niftory Requests.

\

Targets blockchain testnet.

Headers

Name
Type
Description

X-Niftory-API-Key**

String

Your Niftory API Key

Authorization

String

Bearer token containing the user's JWT. See

.

{
    // Response
}

No matter what client library you use, the 3 things you need to make requests to the Niftory API are:

You can use the Niftory API in staging mode, which doesn't affect your production data, and executes blockchain transactions on testnet. The API endpoint you use -- api.staging.niftory.com vs. api.niftory.com determines the mode.

We strongly recommend you use the API's staging endpoint until you are ready to deploy your app to production.

/**
 * Creates a graphQL client for use in the browser, using the user's auth token for authentication
 * @param url The URL of the GraphQL API
 * @param apiKey The API key
 * @param session The user session
 * @returns The graphQL client
 */
export function getFrontendGraphQLClient(
  url: string,
  apiKey: string,
  session: Session | null
) {
  return new GraphQLClient(url, {
    headers: {
      "X-Niftory-API-Key": apiKey,
      Authorization: session?.authToken ? `Bearer ${session.authToken}` : "",
    },
  });
}
export function getGraphQLClient(
  url: string,
  apiKey: string,
  session: Session | null
) {
  return createClient({
    url: url,
    fetchOptions: {
      headers: {
        "X-Niftory-API-Key": apiKey,
        Authorization: session?.authToken ? `Bearer ${session.authToken}` : "",
      },
    },
  });
}

export const GraphQLClientProvider = ({
  children,
}: {
  children: React.ReactNode;
}) => {
  const { data: session } = useSession();

  const graphqlClient = getGraphQLClient(
    process.env.NEXT_PUBLIC_API_PATH as string,
    process.env.NEXT_PUBLIC_API_KEY as string,
    session
  );

  return <Provider value={graphqlClient}>{children}</Provider>;
};

👩‍💻
GraphQL Client with graphql-request
GraphQL Client with URQL
Your app's API Key
Authenticating the User
Authenticating the User
graphql-request
urql
Apollo
An auth token, for scenarios that require authentication
our rationale
URL of the Niftory API service