The Graph: index your smart contract to build powerful dapps - @impranavm_ at @ETHDubaiConf
ETHDubai 2022 · March 2022 · 17:40
This session introduces indexing smart-contract data with The Graph to build decentralized applications.
Speakers
Topics
From ETHDubai 2022, hosted by DeFi Dubai.
Transcript
anyways we'll be discussing about the graph yesterday we had a live demo as to how do we create a subgraph and today we'll be discussing what's the mechanism you know how to index blockchains in the most decentralized ways right so it's like we we normally say that the graph in general as an analogy is like what google does to web true is what the graph does to web pre right but we'll understand what's the nuances that we'll have to make sure for for the indexing in web3 to happen right it has to be decentralized plus there are lots of call handlers to be handled and 100 different things so we'll be understanding technically how you know
the graph is able to index such a complex structure like a blockchain which has a linked list a block in it and different different transactions to actually make things works and of course in the most decentralized fashion all right i hope uh you have fun uh so basically like you know it's it's it's a very well saying that currently we have built ethereum right and we are deploying decentralized applications on ethereum and having a lot of fun but the biggest problem is that currently with just 0.65 of the world population using web3 we are still broke right what that means is that even if there is a
short like you know increment in the population of people using web3 infrastructure starts breaking and the reason behind that is that we have not done things the right way most probably what we have done is used ethereum as a apy aggregator for us and called ourselves a decentralized application but that's not how it works a decentralized application is not just decentralized by making your application deploy on something like ethereum or any of these blockchains it has to be there has to be no single point of failures to make a decentralized application a decentralized application what that means is that whatever information is coming inside that particular blockchain
has to be in a life fashion whatever information is going outside from that blockchain has to be in a decentralized fashion that's what the graph does whatever uh what we call as notification that's pushed to your particular application as a mobile thing has to happen in a decentralized fashion whatever hosting domains everything that you're doing has to happen in a decentralized fashion and that's why we cannot host our ethereum decentralized applications on centralized stuff i know it is tough to make a web 3 stack of its own but that's what we require right i personally believe that eventually web 3 will be the new internet but if we just compare the statistics
right now only zero point six five percent of the world uses in uh uh web3 while 70 percent of the world uses internet right so if we have to reach that kind of mass adoption we'll have to make these kind of like you know conscious choices so that we are fault proof as well as you know making the internet happen in the most decent life sufficient way possible so as of now uh there are lots and lots of single points of failures that exist and that's why the web 3 stack the infrastructure layer of web 3 is being built although it's a little unfortunate that you know we had ethereum and we had we had aws s2 and things like that to start
off things but i think we'll eventually have to migrate our you know infrastructure knowledge our building knowledge our stack knowledge and that's why the graph is developing something with is a part of the web3 stack and is used to index blockchains what that means is that whatever information you store inside a particular blockchain that has to be posted outside to the world right in a decent lives fashion and that's for what we use the graph is you create a subgraph of your particular application right put it on a decentralized graph network get the information outside via graphql api and use that to put in the
front end that is what the graph does all right we will discuss a little detailing of how this happens and why is it decentralized but i'll start with this so as of now what people do in current dap architecture is that they have centralized entities uh known as servers which are either like you know indexing a particular application and then putting things outside to the world and that's not something that we want right again if a server fails everything fails in web 2 why these things still work is first of all it's centralized and secondly it is being run by data centers in the world while it's just three or four people with a s2 server which are running it in
a web 3 world when mass adoption happens these servers start failing and then we are like oh we are still early we'll have to wait we'll have no that's not how it is that's why like you know this is a wrong way to index a blockchain second uh way to index a blockchain which is not uh centralized but it's super slow is that you start tracking every event that happens in a blockchain you start keep a check of whatever is like you know happening in a particular blockchain and get that to your particular application so if i want to know that okay 10 days ago i did a trade on uni swap and converted my usdt to ethereum and i run a program like this it will
take me five more days to get the result right again that's not the correct way of having a ui in those sense although it is decentralized but right uh if i start opening a page today and it opens after five days i'm sure it will it will be of very less use to me so that's again a wrong way to do it and again it looks like this as shabby as it can be if we directly you know query a particular blockchain and try to get information that we want not the correct way not the best use and always will be like rupturing the rpc like anything making 100 different calls for a single transaction not the most proficient way to making things happen
right and that is the reason we have something like the graph the graph indexes blockchain like no other you create sub graphs for your particular application right put it on a decentralized uh decentralized network currently only supporting ethereum and it will be indexed by 150 odd indexes that we have on the network this not just gives you decentralization but also makes your application indexable and that's what we want right now right in web 2 we do more reads than we do rights right i give this example that on instagram for example
how many post pictures do we post it's like one in thousands right i mean one in 10 days if somebody looks like me maybe 100 days right but how many reads do we do we do it every day thousand times the world right now of blockchain is focusing on uh doing the layer two stuff doing the right stuff on the blockchain and that is only possible because the read is happening efficiently using the graph if the reads start failing we'll have to scale them up and that's not possible why our server will have to use the graph to make the reads 100x more scalable than we are trying to do for laters with the modular structures and stuff like
that and that's why the graph has eventually become an essential part of the web3 stack to end index any blockchain if you are making a decentralized application you will have to use the graph to get your blockchain indexed and putting things outside to the world so this is the architecture of the graph and this is how it looks like i don't want to go in details but i'll just tell you in a very very short simple manner that okay you write a smart contract it has events the events are seen by a graph node they actually listen to the events that for your particular smart contract and store it in a database
right and uh that database is truly processed so that you can query that database using graphql apis all right i know it might be a little hard to take in but do click a photo of this this is a marvelous architecture through which we have been able to achieve scale like no other and that's why because of this architecture this is how from from from something like this we have been able to query a blockchain just like this beautiful simple elegant as it can be right so as i told you indexing web 2 is like okay we have
google we need to scrape every part of the data in the google get the information out and put that to the world that is possible in web 2 because there is central entity doing that it has all the rights to do whatever it wants if it wants to index something it will if it does not want to it will not but because of this we lose the autonomy to the internet right and that's why we need something which is decentralizing the indexing layer as well we just don't want to decentralize the information going inside layer we also want to decentralize the information coming outside layer otherwise what will happen is that we are back to what we were centralization
censorship and all the hundred problems that exist because of that right so as of now like just to solve that confusion the graph has a hosted service and the graph network the hosted service is a sas product it was the first product market fit uh to make any decentralized app application happen but definitely it was a sas but now the graph has the graph network right which is currently live on ethereum and you can index a blockchain in a decentralized fashion using the graph network if you use ethereum right now the graph currently powers most of the d5 as well as nft architecture that
exists in the world and i told you it is not easy to create an indexer of your own right and that's why you have to use something like the graph which is taking care of the indexing bit with the graph node created with the whole architecture of you know the 150 indexers 1000 delegators you know 6 600 odd curators to making your indexing your particular sub graph indexing possible and that's why we have something like the graph the graph this this particular page you all might have seen what is it anybody this is uni swap info page
and if you go to the networking part you will see it is api.the graph.com subgraph slash uni swap v3 which powers all the information that is coming to this particular page so that's the importance of the graph in a web3 stack all right so this is a great way to actually understand how it works right in a particular block there are hundreds of transactions happening but let's say you have deployed a smart contract which only caters to the green part right you have a uniswap smart contract that you have deployed right and all the unisop transactions that are happening are only the green bit the others are
other like you know application transactions that are happening and you just want the green bit right for that you have to use the graph so that graph node using the yaml file that you create can cater to this green part segregate everything else put it in the best data base possible and query it to your particular api using the graphq to your particular front end using the graphql api so this is most about it i know when you're creating a web3 stack there are different different challenges that occur firstly scaling of course right indexing of subgraph which is as heavy
as uh uni swap quick swap all these indexing something which is as fast as polygon or phantom with the one second block time is really really tough because just imagine every event that is fired you have to get the graph node information and then put it outside it is very very quick one second thing right while in ethereum you are given seven seconds to process that data and put that stuff outside so we have identified that definitely indexing performance is something that we have to work on if it takes a quick sub subgraph to you know index 10 days we have developed a core team at the graph which has streaming first figment edge in node the
company i represent as well as uh the guild to making this happen and for the same reason we have been you know trying different different architectures out to make it happen and the r d road map recently released which definitely suggests how we will make it happen eventually how will we index a blockchain which is as fast as using a centralized indexer but with the power of decentralization so that people don't have to give up their developer experience they don't have to give up their like you know a convenience and they don't have to give up performance for the name of decentralization decentralization is something that should happen in the back end it should be very well pronounced
but it should only be shown as effects and not as something we capitalize on and you know create philosophies about and that's why the graph is a product in making we are live on 27 evm chains as well as the graph recently released a non-evm chain integration with with near and soon we are going to come up with our weave as well as solana integration that figment team is working on as well as doing some data sourcing so that we can get off chain data to the graph using something like let's say ceramic that's all from my side i'm really sorry i was late but i hope i could make you understand that you if you are making a web 3 app
you have to use the web3 stack thank you thank you very much i've got one question so what about indexing test nets the graph indexes rink by as well as all the ethereum test nets as well as all the evm chain test nets like polygon mumbai as well as phantom test net as well as bsc testnet which is chapel so yeah do you have any problems with like phantom etc because so for example uh if you can find the testnet nft marketplace like on openc which works for ethereum uh testnets as well as mumbai but for phantom there is no such tool
it's it's it's more so like a phantom chain decision to you know not have such kind of a thing but the best part about creating a subgraph on the hosted services that it's a free service you can create it make changes a huge mastic to do the testing the unit testing and you know still come out with things so that's the reason why the graph is created such that that if there are issues you can always do something like grafting to have your you know subgraphs indexed all the time i know it's as i told you right creating a layer one right now is one of the easiest things you can do just create one have a economic model which is same as ethereum have a token and boom
but if you're creating a web3 stack which really matters if you are creating something which empowers ethereum and all the infrastructure of web3 you will have to do innovation and that's what the graph has been doing from the network economics to even doing state channel payments using something like connect state channel payments right so thank you very much any more questions [Music] all right maybe it was too good yeah but i really like the speech and i really want to use your service as well probably for some nft stuff on phantom because yeah this is the niche that i see that's not occupied yet
definitely definitely and with the data source filing that is coming you will be able to index the metadata as well as well as query that using full text search so watch out yeah really good thank you very much you