To understand what the SubQuery dictionary is and how it works, it is important to understand what SubQuery is and how it works. If you already have an understanding, feel free to skip this step.
What is SubQuery?
SubQuery is a project that provides an SDK for developers to easily extract data from Substrate blockchains. For example, if you wanted to know how many accounts have made over 200 transactions or the total amount staked for a particular address, or anything else you care to wonder, you can do this easily and quickly with SubQuery.
Traditionally, you would have to create a node either locally or on a hosted infrastructure, then wait for it to synchronise and then code up your query asking for the data you need. With about 130GB of unstructured data and over almost 6 million blocks this could take days to synchronise.
What SubQuery does is fetch every block through the Polkadot API and places it in a buffer for later processing. The indexer (aka node) then takes the block out from the buffer, and while extracting the block data, checks whether the events and extrinsics (aka transactions) within the block matches the user-defined filter. As you can imagine, this can take a lot of time as the blockchain grows.
What is the SubQuery dictionary?
In an effort to be more efficient, the concept of a dictionary has been created. Firstly, the dictionary is just a regular SubQuery project. What it does is store all the blocks from the Polkadot chain into a database. In fact, when you run the dictionary project locally and connect it to a Postgres database, you will see subquery_1.events, subquery_1.extrinsics, and subquery_1.spec_versions tables created.
Below you can see the columns of each of the tables.
Once this project is fully synchronised with the Polkadot blockchain, it will contain all the blocks and the various event data. This is then indexed to increase database query speed.
This project is then hosted on “SubQuery Project” which is SubQuery’s hosting infrastructure
If you visit https://explorer.subquery.network/ and search for dictionary you should see the Polkadot Dictionary.
This dictionary has an exposed API of “https://api.subquery.network/sq/subquery/dictionary-polkadot“.
How to use the dictionary?
Now that we have the API of the SubQuery Dictionary project, we can include this API endpoint in any other project of our choice. To do this, include the dictionary key in the network section of the project with the value of https://api.subquery.network/sq/subquery/dictionary-polkadot