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

Transfer an NFT

PreviousAPI UsageNextCore Concepts

Last updated 1 year ago

Was this helpful?

The final core capability of the sample app is the ability to transfer NFTs to users. This is accomplished via the mutation, which:

  • Takes in the ID of the NFT or NFTModel to transfer

  • Mints the NFT if it hasn't already been minted, and

  • Transfers the minted NFT to the user's wallet

Since these can be time-consuming operations, the transfer API schedules the work to happen asynchronously, and returns back the NFT that will be transferred to the user. The NFT's field tells you what is going on.

Unlike the other APIs we have seen so far that are run in the context of the logged-in user, the transferAPI is . As a result, you will need to call transfer from your application's backend.

const TRANSFER = gql`
  mutation transferNFTToUser($nftModelId: ID!, $userId: ID!) {
    transfer(nftModelId: $nftModelId, userId: $userId) {
      id
    }
  }
`;
const handler: NextApiHandler = async (req, res) => {
  const { nftModelId, userId } = req.query;

  if (req.method !== "POST") {
    res.status(405).end();
    return;
  }

  const signedIn = !!getToken({ req });
  if (!signedIn) {
    res.status(401).send("You must be signed in to transfer NFTs");
  }

  if (!nftModelId) {
    res.status(400).send("nftModelId is required");
    return;
  }

  const client = await getBackendGraphQLClient();
  const sdk = getSdk(client);

  const data = await sdk.transferNFTToUser({
    nftModelId: nftModelId as string,
    userId: userId as string,
  });

  res.status(200).json(data);
};

Follow the sample app's structure for an example on how to invoke the transfer mutation, or read further on how to invoke.

You now have everything you need to get startedβ€”except the NFTs themselves! So let's discuss the Niftory Admin Portal next, where you can set up your NFT collections and manage your app.

πŸ‘©β€πŸ’»
transfer
status
privileged
Transfer handler in application backend
Niftory APIs in your backend