> For the complete documentation index, see [llms.txt](https://brick-protocol.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://brick-protocol.gitbook.io/docs/fundamentals/indexer.md).

# Indexer

The Brick indexer source can be found [here](https://github.com/ricardocr987/brick/tree/master/indexer/brick)

Based on the [Aleph Indexer Framework](https://github.com/aleph-im/aleph-indexer-framework), it is currently configured to be posting specific Aleph Messages for the Fishnet dApp, for which Brick was initially developed for:

{% embed url="<https://fishnet.tech/>" %}
An upcoming marketplace for quant data.
{% endembed %}

A more general version of the indexer should be available [here](https://github.com/aleph-im/aleph-indexer-library/tree/main/packages/brick)

## Querying the Indexer

To run the indexer locally, follow these steps:

1. Open `indexer/brick/.env.defaults` and set the SOLANA RPC.
2. From root you can run the indexer with: `npm run start:indexer`

When the indexer started, the indexer usually starts at <https://localhost:8080>. There you can query it through the GraphiQL UI or using the [sdk](https://brick-protocol.gitbook.io/docs/fundamentals/typescript-sdk#how-to-query-from-the-indexer-using-the-sdk).

### Transactions:

Provides user purchases and sales, discriminate sales and purchases by checking the signer of the event.

```graphql
{
    transactions(user: "rikiFB2VznT2izUT7UffzWCn1X4gNmGutX7XEqFdpRR") {
        id
        timestamp
        type
        account
        signer
        ... on RegisterBuyCnftEvent {
            info {
                systemProgram
                tokenProgramV0
                rent
                logWrapper
                bubblegumProgram
                compressionProgram
                tokenMetadataProgram
                signer
                seller
                marketplaceAuth
                marketplace
                product
                paymentMint
                productMint
                buyerTransferVault
                sellerTransferVault
                marketplaceTransferVault
                bountyVault
                sellerReward
                sellerRewardVault
                buyerReward
                buyerRewardVault
                metadata
                masterEdition
                treeAuthority
                merkleTree
                params {
                    amount
                    name
                    symbol
                    uri
                }
            }
        }
        ... on RegisterBuyCounterEvent {
            info {
                systemProgram
                tokenProgramV0
                rent
                signer
                seller
                marketplaceAuth
                marketplace
                product
                payment
                paymentMint
                buyerTransferVault
                sellerTransferVault
                marketplaceTransferVault
                bountyVault
                sellerReward
                sellerRewardVault
                buyerReward
                buyerRewardVault
                amount
            }
        }
        ... on RegisterBuyTokenEvent {
            info {
                systemProgram
                tokenProgramV0
                tokenProgram2022
                signer
                seller
                marketplaceAuth
                marketplace
                product
                productMint
                paymentMint
                buyerTokenVault
                buyerTransferVault
                sellerTransferVault
                marketplaceTransferVault
                bountyVault
                sellerReward
                sellerRewardVault
                buyerReward
                buyerRewardVault
                amount
            }
        }
        ... on RegisterBuyEvent {
            info {
                systemProgram
                tokenProgramV0
                rent
                signer
                seller
                marketplaceAuth
                marketplace
                product
                payment
                paymentMint
                buyerTransferVault
                sellerTransferVault
                marketplaceTransferVault
                bountyVault
                sellerReward
                sellerRewardVault
                buyerReward
                buyerRewardVault
                amount
            }
        }
    }
}
```

### Events

Provides you the instruction history of an specific account (can be a user o a program account).

<pre class="language-graphql"><code class="lang-graphql"><strong>{
</strong><strong>  events(account: "5WnQLqDpc35PodFDBH6ZAWzDonvt4SF9R9wHq7mhMBG") {
</strong>    id
    timestamp
    type
    account
    signer
    ... on AcceptAccessEvent {
      info {
        systemProgram
        tokenProgram2022
        associatedTokenProgram
        rent
        signer
        receiver
        marketplace
        request
        accessMint
        accessVault
      }
    }
    ... on AirdropAccessEvent {
      info {
        systemProgram
        tokenProgram2022
        associatedTokenProgram
        rent
        signer
        receiver
        marketplace
        accessMint
        accessVault
      }
    }
    ... on EditProductEvent {
      info {
        signer
        product
        paymentMint
        productPrice
      }
    }
    ... on EditMarketplaceEvent {
      info {
        signer
        marketplace
        rewardMint
        discountMint
        params {
          fee
          feeReduction
          sellerReward
          buyerReward
          useCnfts
          deliverToken
          transferable
          chainCounter
          permissionless
          rewardsEnabled
          feePayer
        }
      }
    }
    ... on InitBountyEvent {
      info {
        systemProgram
        tokenProgramV0
        associatedTokenProgram
        rent
        signer
        marketplace
        rewardMint
        bountyVault
      }
    }
    ... on InitMarketplaceEvent {
      info {
        systemProgram
        tokenProgram2022
        tokenProgramV0
        rent
        signer
        marketplace
        accessMint
        rewardMint
        discountMint
        bountyVault
        params {
          fee
          feeReduction
          sellerReward
          buyerReward
          useCnfts
          deliverToken
          transferable
          chainCounter
          permissionless
          rewardsEnabled
          accessMintBump
          feePayer
        }
      }
    }
    ... on InitProductTreeEvent {
      info {
        tokenMetadataProgram
        logWrapper
        bubblegumProgram
        compressionProgram
        tokenProgramV0
        associatedTokenProgram
        rent
        signer
        marketplace
        product
        productMint
        paymentMint
        accessMint
        productMintVault
        accessVault
        masterEdition
        metadata
        merkleTree
        treeAuthority
        params {
          firstId
          secondId
          productPrice
          maxDepth
          maxBufferSize
          name
          metadataUrl
          feeBasisPoints
        }
      }
    }
    ... on InitProductEvent {
      info {
        systemProgram
        tokenProgram2022
        rent
        signer
        marketplace
        product
        productMint
        paymentMint
        accessMint
        accessVault
        params {
          firstId
          secondId
          productPrice
          productMintBump
        }
      }
    }
    ... on InitRewardVaultEvent {
      info {
        systemProgram
        tokenProgramV0
        associatedTokenProgram
        rent
        signer
        marketplace
        reward
        rewardMint
        rewardVault
      }
    }
    ... on InitRewardEvent {
      info {
        systemProgram
        tokenProgramV0
        rent
        signer
        marketplace
        reward
        rewardMint
        rewardVault
      }
    }
    ... on RegisterBuyCnftEvent {
      info {
        systemProgram
        tokenProgramV0
        rent
        logWrapper
        bubblegumProgram
        compressionProgram
        tokenMetadataProgram
        signer
        seller
        marketplaceAuth
        marketplace
        product
        paymentMint
        productMint
        buyerTransferVault
        sellerTransferVault
        marketplaceTransferVault
        bountyVault
        sellerReward
        sellerRewardVault
        buyerReward
        buyerRewardVault
        metadata
        masterEdition
        treeAuthority
        merkleTree
        params {
          amount
          name
          symbol
          uri
        }
      }
    }
    ... on RegisterBuyCounterEvent {
      info {
        systemProgram
        tokenProgramV0
        rent
        signer
        seller
        marketplaceAuth
        marketplace
        product
        payment
        paymentMint
        buyerTransferVault
        sellerTransferVault
        marketplaceTransferVault
        bountyVault
        sellerReward
        sellerRewardVault
        buyerReward
        buyerRewardVault
        amount
      }
    }
    ... on RegisterBuyTokenEvent {
      info {
        systemProgram
        tokenProgramV0
        tokenProgram2022
        signer
        seller
        marketplaceAuth
        marketplace
        product
        productMint
        paymentMint
        buyerTokenVault
        buyerTransferVault
        sellerTransferVault
        marketplaceTransferVault
        bountyVault
        sellerReward
        sellerRewardVault
        buyerReward
        buyerRewardVault
        amount
      }
    }
    ... on RegisterBuyEvent {
      info {
        systemProgram
        tokenProgramV0
        rent
        signer
        seller
        marketplaceAuth
        marketplace
        product
        payment
        paymentMint
        buyerTransferVault
        sellerTransferVault
        marketplaceTransferVault
        bountyVault
        sellerReward
        sellerRewardVault
        buyerReward
        buyerRewardVault
        amount
      }
    }
    ... on RequestAccessEvent {
      info {
        systemProgram
        rent
        signer
        marketplace
        request
      }
    }
    ... on UpdateTreeEvent {
      info {
        payer
        signer
        marketplace
        product
        treeAuthority
        merkleTree
        logWrapper
        systemProgram
        bubblegumProgram
        compressionProgram
        params {
          maxDepth
          maxBufferSize
        }
      }
    }
    ... on WithdrawRewardEvent {
      info {
        tokenProgramV0
        signer
        marketplace
        reward
        rewardMint
        receiverVault
        rewardVault
      }
    }
  }
}
</code></pre>

### Brick Accounts

The current state and human-readable content of all program accounts can be queries like this:

```graphql
{
  accounts {
    address
    type
    data {
      ...on Marketplace {
        authority
        tokenConfig {
          useCnfts
          deliverToken
          transferable
          chainCounter
        }
        permissionConfig {
          accessMint
          permissionless
        }
        feesConfig {
          discountMint
          fee
          feeReduction
          feePayer
        }
        rewardsConfig {
          rewardMint
          bountyVaults
          sellerReward
          buyerReward
          rewardsEnabled
        }
      }
      ...on Product {
        authority
        firstId
        secondId
        marketplace
        productMint
        merkleTree
        sellerConfig {
          paymentMint
          productPrice
        }
        bumps {
          bump
          mintBump
        }
      }
      ...on Reward {
        authority
        marketplace
        rewardVaults
        bumps {
          bump
          vaultBumps
        }
      }
      ...on Access {
        authority
        marketplace
        bump
      }
      ...on Payment {
        units
        bump
      }
    }
  }
}

```

###
