Follow transfers of a Fan Token

Tracking Fan Token movements on Chiliz Chain is a great way to monitor the activity of your favourite tokens. By using it as a building block for a potential dashboard, you can streamline data to provide insights into what's popular and what's not.

When tracking Fan Token™movements, you quickly run into a challenge: reading data directly from the blockchain is efficient for current status ("What is the balance of wallet X?"), but inefficient for historical data ("Show me every transfer involving wallet X over the last year").

To solve this, we can use subgraphs.

About subgraphs

A Subgraph is a custom API that extracts data from a blockchain, processes it, and stores it so it can be easily queried. Instead of asking the blockchain to scan millions of blocks every time you need data, a subgraph indexes specific events as they happen and stores them in a database.

Chiliz Chain supports industry-standard indexing protocols. You can choose the provider that best fits your project's needs:

  • The Grapharrow-up-right: The industry standard for decentralized indexing. It allows you to deploy your subgraph to a decentralized network of indexers.

  • Goldskyarrow-up-right: A high-performance, hosted indexing service. It is fully compatible with The Graph's code (you can often use the exact same code) but offers faster indexing speeds and real-time data streaming features.

Both tools use the same development framework, so most of the steps on this page can apply to both.

Let's see for instance how we could follow transfers of the PSG Fan Token...

0. Choose a tool

You can deploy a subgraph on Chiliz Chain using The Graph (decentralized network) or Goldsky (hosted indexer). The code structure is identical; only the deployment commands differ.

Of course, you can rely on their own docs:

1. Initialize a subgraph project

Both The Graph and Goldsky offer CLI-based methods to create your graph.

circle-info

The Graph has Subgraph Studioarrow-up-right, which you can connect to using your Web3, then create a subgraph through the interface.

Goldsky gives you a dashboardarrow-up-right when you create an account, from which you can create a subgraph.

Install the Graph CLI⁠

On your local machine, run the following:

circle-info

You can create a subgraph using the CLI tool from The Graph for either The Graph-decentralized subgraphs, or Goldsky-hosted subgraphs.

Goldsky has its own CLI tool, which you will need if you want to deploy on Goldsky (see below).

Initialize your subgraph⁠

You can copy this directly from your subgraph page to include your specific subgraph slug:

The --studio tag is optional.

In our PSG Fan Token example, we can use:

You’ll be prompted to provide some info on your subgraph, like this:

You need to have your contract verified on the block explorer, and the CLI will automatically obtain the ABI and set up your subgraph. The default settings will generate an entity for each event.

circle-exclamation
circle-info

When making changes to your subgraph, you will mostly work with three files:

  • The Manifest (subgraph.yaml): Defines what data sources your subgraph will index.

  • The Schema (schema.graphql): Defines what data you wish to retrieve from the subgraph.

  • AssemblyScript Mappings (mapping.ts): Translates data from your data sources to the entities defined in the schema.

Open subgraph.yaml and make sur your manifest file points to the correct network:

Compile your subgraph

Finally, compile your subgraph to ensure that there are no errors:

2. Deploy & Publish

Once your subgraph is built, choose your provider to deploy it.

The Graph

  1. Connect to Subgraph Studioarrow-up-right, create a subgraph, and copy your deploy key.

  2. Authenticate through the CLI: graph auth --studio <DEPLOY_KEY>

  3. Deploy your subgraph to Subgraph Studio: graph deploy --studio <SUBGRAPH_SLUG>

  4. Go to Studio, open your subgraph and click "Publish" to mint your subgraph to the decentralized network. It'll trigger a transaction through your wallet to publish your subgraph as an NFT on the Arbitrum One network.

Goldsky

  1. Go to Goldskyarrow-up-right, create an API key in "Project Settings", and log in via CLI.

  2. Install the goldsky command: curl https://goldsky.com | sh Then authenticate through the CLI: goldsky login

  3. Upload your subgraph to Goldsky: goldsky subgraph deploy / --path

Goldsky subgraphs are live immediately after deployment. No extra publishing step is required.

circle-info

You will be asked for a version label. You can enter something like v0.0.1, but you’re free to choose the format. Once that's done, you'll see the subgraph start to sync in the Studio page.

circle-info

The Graph's smart contracts are all on Arbitrum Onearrow-up-right, even though your subgraph is indexing data from Chiliz Chain.

3. Query your Subgraph

Congratulations! You can now start querying it by passing a GraphQL query into the subgraph’s query URL which can be found in the dashboard of your chosen service.

Example:

The Graph

https://gateway-arbitrum.network.thegraph.com/api/[APIKEY]/subgraphs/id/[ID]

Goldsky

https://api.goldsky.com/api/public/project_[KEY]/subgraphs/[SLUG]/1.0.0/gn

Now, you simply need to fill in your details to start sending GraphQL queries to this endpoint.

Appendices

Sample Query

This query shows all transactions of the PSG Fan Token.

Sample code

Passing this into the query URL returns this result:

Additional resources

For more information about querying data from your subgraph with GraphQL:

Last updated

Was this helpful?