paint-brush
GraphQL, the Universal Query Protocol, and the Free TON Blockchainby@freetonhouse
263 reads

GraphQL, the Universal Query Protocol, and the Free TON Blockchain

by EverscaleJune 13th, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

GraphQL is a protocol that defines an algorithm for searching information in a database. It was born in the depths of good old Facebook as a response to the request of users and developers. GraphQL, adapted by TON Labs developers, is also used in the Free TON blockchain. The graphical interface of this protocol makes it possible to make a search query across the entire blockchain. For example, who and from which address made the transfer, data on the size of the stake, the share of personal contribution from the total investment in the DePool.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail

Coin Mentioned

Mention Thumbnail
featured image - GraphQL, the Universal Query Protocol, and the Free TON Blockchain
Everscale HackerNoon profile picture
In short, GraphQL is a protocol that defines an algorithm for searching information in a database. It was born in the depths of good old Facebook as a response to the request of users and developers. The challenge faced by the creators was to optimize the algorithm for processing search queries on the platform.

Before touching on the use of GraphQL in one of new blockchain platform - Free TON, let's talk about the protocol using a simple example. Let's say you want to find out who constantly likes posts about particular political party activities or to summarize people who put a laughing emoji under serious texts about harassment and violence. Recall that based on search queries on Facebook arrays of information about the preferences and attitudes of users, the use of which provides interest groups with tools of influence. 

Initially, the existing query algorithm allowed storing the received data as duplicate information, distributed by its characteristics on different servers. The optimization of this algorithm was the development of a syntax that describes to the user how data should be queried, then processes the databases, and finally provides the user with information sorted according to the query. This intermediary client is called GraphQL.

GraphQL, adapted by TON Labs developers, is also used in the Free TON blockchain. There, it is an additional protocol layer, which can perform several complex operations: to collect information from various databases, process it and return to the client in a single request. 

Technically, it looks like this. Each full node contains all information about all blockchain transactions. GraphQL acts as a protocol to it, which is additionally installed by the owner of the node. The graphical interface of this protocol makes it possible to make a search query across the entire blockchain. For example, who and from which address made the transfer, data on the size of the stake, the share of personal contribution from the total investment in the DePool. GraphQL is installed on a full node of the owner's choice.

The convenience for the user is that with GraphQL he can extract a large set of complex data with just one request to the service. Also, using the input fields, it can immediately determine in what form it wants to receive information.

This gives the protocol flexibility: for example, you can select all the transactions for a single account, or you can trace the dynamics of the processes in the complex by adding new fields. There is also a subscription feature, which allows you to receive information about changes in any parameter, for example, information about transactions from a certain address — a kind of notification.

There are also advantages for developers: GraphQL is a certain level of abstraction for the user, behind which the developer can hide a complex architecture, editable database.

SDK Product Owner at TON Labs, Ekaterina Pantaz, Answers Questions

Ekaterina noted that initially, users were inclined to use the more familiar REST API, but in the end, everyone quickly got involved and there were no problems specifically with GraphQL.

How was the work on the API based on the GraphQL protocol?

The TON Labs development team added basic blockchain access when developing the API (application programming interface), which allows to get information on blocks, transactions, messages and accounts, as well as to send external messages to the blockchain.

API functions have been expanded to find SUM, COUNT, MIN and MAX by data, and the Counterparties function has been added, which returns a list of addresses with which the account has ever interacted, sorted by the time of the last interaction. 

What changes are planned in working with the GraphQL protocol?

TON Labs is currently working on exchanges module that will allow to easily add TON to any exchange. 

The API already allows you to get all the proofs to prove the data it returns, and soon functionality will be added to the SDK, with which it will be easy to do this.

Do you have data on how many nodes and full nodes this protocol is installed on?

There are no such data now. We have three full nodes and I know other validators have a couple of nodes, but I do not have a complete list.

 Is there any monetization algorithm planned?

Yes, there will be a contest of design economical system for Web Free Node soon with good prize money - 115 000 TON Crystal ( about 45 000 USD).