# Get Active Listings of a Wallet

Tensor has two programs which contains active listings.

* Tensor Swap stores active listings in <mark style="color:yellow;">SingleListing</mark> account
* Tensor cNFT stores listing data in <mark style="color:yellow;">ListState</mark> account.

{% hint style="success" %}
Cross program query is possible here. You can query both programs in a single graphQL call.
{% endhint %}

With Shyft's SuperIndexer, you can query accounts data through GraphQL. We will be applying a where filter on owner field of the accounts data. This will give us all active listings for that owner (wallet).

#### Tensor Cross Program Query

We will query both Tensor programs, cNFT and Tensor Swap in a single call, and see the power of cross program queries, thanks to GraphQL APIs.

You can directly copy paste this code on <mark style="color:yellow;">replit</mark> and see it in action.

{% tabs %}
{% tab title="Code Snippet" %}

```typescript
import { gql, GraphQLClient } from "graphql-request";

const endpoint = 'https://programs.shyft.to/v0/graphql/?api_key=YOUR-KEY';

const graphQLClient = new GraphQLClient(endpoint, {
  method: `POST`,
  jsonSerializer: {
    parse: JSON.parse,
    stringify: JSON.stringify,
  },
});

async function getAllListingsOnTensor(walletAddr:string) {
    //you can select the fields as per your requirement
    const query = gql`
      query MyQuery {
        TENSOR_CNFT_listState(
          where: {owner: {_eq: ${JSON.stringify(walletAddr)}}}
        ) {
          _lamports
          amount
          assetId
          currency
          expiry
          makerBroker
          owner
          privateTaker
          rentPayer
          version
        }
        Tensor_SingleListing(
          where: {owner: {_eq: ${JSON.stringify(walletAddr)}}}
        ) {
          bump
          lamports
          nftMint
          owner
          price
        }
      }
    `;

  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
  
}

//replace with the wallet address you want to query
getAllListingsOnTensor('5GAPWPNhsQWZ9V61cdSUY4Dy4qm1shN2tddB1gibz5zM')

```

{% endtab %}

{% tab title="Response" %}

```json
{
  "data": {
    "TENSOR_CNFT_listState": [
          {
        "_lamports": 3097200,
        "amount": 400000,
        "assetId": "6nhX4Wrwv7uz2tQMRd2zqVWX1fCqGFkLJhUf5SGz89To",
        "currency": null,
        "expiry": 1738680228,
        "makerBroker": null,
        "owner": "5GAPWPNhsQWZ9V61cdSUY4Dy4qm1shN2tddB1gibz5zM",
        "privateTaker": null,
        "rentPayer": "5GAPWPNhsQWZ9V61cdSUY4Dy4qm1shN2tddB1gibz5zM",
        "version": 1
      },
      {
        "_lamports": 3097200,
        "amount": 400000,
        "assetId": "BQA4rqkuQBUmjjFAyv2yXmUUCjPQwUs8ConeDWDMrdHX",
        "currency": null,
        "expiry": 1738191064,
        "makerBroker": null,
        "owner": "5GAPWPNhsQWZ9V61cdSUY4Dy4qm1shN2tddB1gibz5zM",
        "privateTaker": null,
        "rentPayer": "5GAPWPNhsQWZ9V61cdSUY4Dy4qm1shN2tddB1gibz5zM",
        "version": 1
      },
      
      < More responses . . . >
      
    ],
    "Tensor_SingleListing": [
      {
        "bump": 254,
        "lamports": 1900080,
        "nftMint": "Cg1TcQRrUNHV8WaGQqJ3MWVDvZQhDRVHjnKra76DisBe",
        "owner": "11112wxKZWNDvECQ2hFq9u2Ly9KLc8EEkt5P86S43gu",
        "price": 90000000
      },
      {
        "bump": 255,
        "lamports": 1900080,
        "nftMint": "Ckw7VnBWCe1Tx27XfodgQEbntCiBisTbVBXG5Rd96vNC",
        "owner": "11112wxKZWNDvECQ2hFq9u2Ly9KLc8EEkt5P86S43gu",
        "price": 120000000
      },
      
      < More responses ... >
    ]
  }
}
```

{% endtab %}
{% endtabs %}

#### Active Listings for Tensor Swap (normal NFTs)

{% tabs %}
{% tab title="Code Snippet" %}

```typescript
import { gql, GraphQLClient } from "graphql-request";

const endpoint = `https://programs.shyft.to/v0/graphql/?api_key=YOUR-KEY`;

const graphQLClient = new GraphQLClient(endpoint, {
  method: `POST`,
  jsonSerializer: {
    parse: JSON.parse,
    stringify: JSON.stringify,
  },
});

async function getAllListingsByWallet(walletAddr:string) {
    //you can select the fields as per your requirement
    const query = gql`
        query MyQuery {
        Tensor_SingleListing(
          where: {owner: {_eq: ${JSON.stringify(walletAddr)}}}
        ) {
          price
          owner
          nftMint
          pubkey
        }
      }
    `;

  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
  
}
//replace with the wallet address you want to query
getAllListingsByWallet('5GAPWPNhsQWZ9V61cdSUY4Dy4qm1shN2tddB1gibz5zM')

```

{% endtab %}

{% tab title="Response" %}

```json
{
  "data": {
    "Tensor_SingleListing": [
      {
        "price": 45000000,
        "owner": "zzxXBMGiFLFYcgLnkprTqdyjhxBPgcLtaWc5fFzBqdV",
        "nftMint": "7tsPokpSTfMAbMKD14ZFgenaBJoUfR8GcjYMn5gxeaXj",
        "pubkey": "4naCM3QuP5AJKPteN4Vk9w7erDQenkPVGELUgu9MgnMV"
      },
      {
        "price": 64000000,
        "owner": "zzxXBMGiFLFYcgLnkprTqdyjhxBPgcLtaWc5fFzBqdV",
        "nftMint": "9BBo8Lhzfwwp9QQ44c9UdeRFpAXHWPUjbFW8w5WiM8Mq",
        "pubkey": "2RdfT92x2srBurLaoMWwLmGa8VBoNydzM1aCERipUavG"
      },
      {
        "price": 117000000,
        "owner": "zzxXBMGiFLFYcgLnkprTqdyjhxBPgcLtaWc5fFzBqdV",
        "nftMint": "3LS2gUfrwssJ2HKRgyGjGXtpZsKPZKLti72fzsiGeCCr",
        "pubkey": "FztQW9rC9q5RoUY3AEfomPsn5kcvRjGnKX2UR7HsHtRs"
      },
      {
        "price": 51000000,
        "owner": "zzxXBMGiFLFYcgLnkprTqdyjhxBPgcLtaWc5fFzBqdV",
        "nftMint": "GSYPsCMah6jHcCV8VzKwKFeB4YhJwJh61omWgmL865r1",
        "pubkey": "DbEgfum573jipNbMTiXBf9PymgfPVcWBo1a6nSW687Pz"
      },
      {
        "price": 87000000,
        "owner": "zzxXBMGiFLFYcgLnkprTqdyjhxBPgcLtaWc5fFzBqdV",
        "nftMint": "9JC7CWEUDf4DURMFRXnxRLphVsvXJygK7obufe1LLAGu",
        "pubkey": "GJ9WCmyTBpo7x8qxWtabSTm7PSYwnJ1WSuWEjVKVQndH"
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}

#### Active Listings for Tensor cNFT

You can also query compressed NFT listings on Tensor, using the following code.

```typescript
import { gql, GraphQLClient } from "graphql-request";

const endpoint = 'https://programs.shyft.to/v0/graphql/?api_key=YOUR-KEY';

const graphQLClient = new GraphQLClient(endpoint, {
  method: `POST`,
  jsonSerializer: {
    parse: JSON.parse,
    stringify: JSON.stringify,
  },
});

async function getAllListingsByWallet(walletAddr:string) {
    //you can select the fields as per your requirement
    const query = gql`
      query MyQuery {
        TENSOR_CNFT_listState(
          where: {owner: {_eq: ${JSON.stringify(walletAddr)}}}
        ) {
          version
          rentPayer
          pubkey
          owner
          assetId
          expiry
          amount
        }
      }
    `;

  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
  
}
//replace with the wallet address you want to query
getAllListingsByWallet('5GAPWPNhsQWZ9V61cdSUY4Dy4qm1shN2tddB1gibz5zM')

```
