# Token Ownership Claiming

In this example, let's assume a user wants to claim a Ticket to an event based on ownership of a NFT. Your goal is to:

* List out all NFTs that have been delegated to a particular wallet
* Process that NFT Token ID as claimed by:
  * Checking ownership of that NFT
  * If the wallet does not own the NFT, check to make sure the NFT has been delegated to that user
* Give the wallet the Ticket

### User experience steps

1. The first step is to get all the incoming delegations from the wallet that wants to claim the ticket. You can do this the following ways:<br>

   **Contract/Javascript SDK:** [`getIncomingDelegations(address)`](/technical-documentation/javascript-sdk/fetch-delegations.md)

   **REST API:** [Delegations by wallet](/technical-documentation/rest-api/v2.md#delegations-by-wallet) where `to` is the wallet address in question<br>

2. Filter out these delegations to only include the NFT Contract you are looking to claim tickets for.<br>

   <pre class="language-javascript"><code class="lang-javascript">// A rough example
   <strong>const filteredDelegations = incomingDelegations.filter(delegation => {
   </strong>    return delegation.type === "ALL" ||
       delegation.type === "CONTRACT" &#x26;&#x26; delegation.contract === NFT_CONTRACT ||
       delegation.type === "ERC721"  &#x26;&#x26; delegation.contract === NFT_CONTRACT
   })
   </code></pre>

3. Get all the NFT's of each unique `from` address in the above list.<br>

   ```javascript
   const delegatedWallets = [...new Set(filteredDelegations.map(delegation => delegation.from))];
   ```

4. For each `delegatedWallet`, list all of their NFT's that are from the contract you are claiming for. Then the user can decide which Token ID to claim the ticket for.\
   \
   There are many external API's to accomplish this. Alchemy offers a simple solution here called [getNFTsForOwner](https://docs.alchemy.com/reference/getnftsforowner-v3).<br>

5. Once the user has selected a token they want to claim a ticket for, the user will most likely send this selection to a backend request. We need to double check that the user has actually delegated this token to the wallet or that the wallet owns this NFT token.
   * Make sure the token id has not been claimed before.
   * Does the wallet submitting the request own this NFT? You can do this by checking the `ownerOf(tokenId)` on the contract level.
   * If not, double check that the wallet who delegated this token owns the NFT
   * If so, double check that this specific token id has been delegated to the requestor. \
     \
     **Contract/Javascript SDK:** Use the `checkDelegateForERC721` in the SDK or contract\
     **REST API:** Use the [v2/check/erc721](/technical-documentation/rest-api/v2.md#delegation-checks) endpoint<br>

6. Process the ticket! You'll want to mark this specific token id as claimed so no one else can claim this token.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.delegate.xyz/integrate-in-your-project/token-ownership-claiming.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
