DAPPCON 2019: Workshop - GraphQL, Archive Data and Underutilized APIs w/ E.G. Galano (Infura)

DappCon 2019 · August 2019 · 24:54

At a DappCon 2019 workshop, a member of the Infura team covers GraphQL, archive data, and underused Ethereum APIs, showing developers how to pull historical blockchain state more efficiently. The session walks through querying archive nodes and integrating Infura's infrastructure into dApp backends. It gives developers practical techniques for working with Ethereum data beyond the most commonly used endpoints.

Speakers

Topics

From DappCon 2019, hosted by Dappcon Berlin.

Transcript

I'll go ahead and get started the first part of this is really me just kind of giving you an overview so hi everybody I'm eg I work at consensus on the inferior project wanted to do a workshop today to go over the new graph QL API that's available for the etherium clients and some work that we did previously that's very related to it called fql if you're not too familiar with graph QL I'm going to start by giving an overview of graph QL and how you interact with it and what the differences are and what are the benefits of using graph QL and then I'll talk a little bit more about

some other things that are good to know if you're building applications on aetherium such as the whole concept of archive data what archive data is whether or not you need it whether or not your applications need to access it and then we'll talk about some other underutilized api's so yeah so this is the overview like I said graph QL we're gonna talk about the transaction pool and the impact of the transaction pool on applications that you're building so because we're building things in a peer-to-peer network that's eventually consistent we're going to talk a little bit about how you can use the data in

the pending transaction pool to improve these or experience of your app then go a little bit into what's available with the tracing ap is that the nodes provided for you as a developer and then the functions that are already available with ENS and how ENS can help improve the user experience all right so these are two lengths I'm gonna switch over to my browser and just kind of walk you through a few documentation pages but these are the two links that you'll need for like the interactive portion of this which is HACC - fql in Fira dot io this is something that's going to take you to

a graph QL playground where we can play around with with some sample queries unless you're running your own node you're going to have to use a third-party provider like in fira to be able to access the chain data today so if in case you don't already have an account you can go to in fear dot io and sign up even if you see that now we're no longer just a free service we have like these paid tiers we wanted to make sure that we're not preventing new entrants in the ecosystem from being able to access the etherium data so if you sign up there's this quartz here that's perfectly capable of handling the

requests for things that we're going to be doing today things that we're going to be building at the hackathon this weekend but one of the things that you're going to need in some of these examples is this endpoint URL which this is the one I created for this demo here of the main net and Pio address you can also target a few other networks here Robson Cove in rank V and Gurley if you want to be building something on a test net and this is the project ID that you're usually going to have to configure your URL with so graph QL so this is this is the playground and this is a sample

query that we have for graph QL really quick how many people here have tried using graph QL before okay so about three or four people in the room so I'll start with an overview were we're all pretty comfortable with like traditional API is restful api is JSON RPC api's and Facebook came out with graph QL as a way to make sure that we're efficiently querying data it's it's a more flexible language so you don't find yourself doing something like polling for a list of people and then from each of those

people getting more information back then you need maybe you only needed to know their age or May you only needed to know their name but instead you're getting like an entire object back full of lots of data that you are just throwing away and so in terms of data over the wire it's pretty inefficient for building an application and and B besides that you might need to do a lot of successive calls to get more information that's related to that right so maybe you needed to find relations to that person like what's their association with you know a company and then you pull the company's information and then you need to pull other people within that company these kinds of graph relationships are what graph QL was

meant to be able to query efficiently and so this is an example of that I can actually start this by walking you through this specific one so so this playground here is the graph QL Explorer that kind of built into this project and you start out the query and the shape of the query matches the shape of the response so this block here is the first thing that you're going to be querying you want to return the block and this tag is going to return the latest block then you can let me pull it up so the latest block is going to contain all of

the information that's what what you would typically see on either scan right it's like time stamp and block hash and the difficulty and all of the transactions and all that information and maybe all you actually wanted was the block number or all you actually wanted was like the the miner address and instead you're getting a back all of this so what graph tool allows you to do is filter that really to only return what you want so maybe what you wanted was just a parent and that's it and then so you can make that there you go so maybe all you wanted was

the parent hash and so what I've done here is I've created the latest block and then what I'm trying to get from that is the parent hash the the simplest example here would be all I wanted from the latest block was the latest block number right if if you start inspecting the traffic that is going across your browser as you're using these different applications that are using JSON RPC you'll find that a lot of our applications are pretty wasteful in terms of the amounts of queries that they're making and the amount of data that's actually required in these for what the application is trying to present to the user this example that I

just have up here when we first started is a great one so this is going to return the latest block number and then it's going to pull all of the transactions from that latest block and then it's going to return the sender from that transaction along with the balance of that that sender's address yeah yeah so this was one query you can see that this is this is every single

transaction there's an item in here for every single transaction that was just in the latest block but instead of returning the transaction I asked it to return the address of the sender and that sender is balanced if I had tried to do this for in in JSON RPC instead of graph QL I would have had to make multiple RPC requests over the wire for each transaction so first I would have pulled the block then I would have built this list of transactions and I know I would have made independent JSON RPC requests to get the balance for each of these addresses and instead of this was done in one query so it's it's something that especially if you're building a

mobile application has a significant impact on on the user experience for your for your user any questions on this so far okay so this is the graph 12 Voyager it's this great tool for being able to explore a schema that's available for a graph QL API so you're able to do some pretty cool stuff with this you can directly paste a schema in here what I did was there's this introspection tool whenever you're using whether it's our graph QL API or some other graph QL API

for a service that you're using you can copy this introspection query and then when you put it into this Explorer right here and then run it it's going to give you back this schema description and then you can put this schema description into the graph QL Voyageur and then it gives you this great view of the relationships between these entities so you can really have a good idea of how you can traverse this data so I'll zoom in and kind of walk you through it really quick so the top level query is going to be able to return several different things to you it can

return an account it can return the block block offset multiple blocks a transaction and from each of those you can see these different relationships here of how you can nest these queries and start including more data so if you're in trying to include a block you can pull transactions from that specific block or this one's really useful it's transactions involving so it's a way of being able to filter based on transactions that have these specific logs or transactions that are only coming from these addresses and then from that so here's the logs there's

this extended inter oh go ahead how do you find the schema so here on this playground there's there's this schema right here on the side which is like built-in documentation for how you can traverse this the this this specific tool that I'm using here is this graph QL Voyageur and you can take this schema that was returned by this introspection query so sorry let me do that again uh-oh yeah okay so yeah all right so

what you do is you up here you hit change schema move to the introspection tab and hit copy introspection query now when you go to the playground yeah yeah so you're going to have to do this next step to be able to get that because you get this introspection query right here maybe to generate it okay sorry okay so let's see so is it this the query on the

left that you need are the query on the right right yeah so when you go to this screen this is going to be empty right you hit this copy introspection query button and it actually copies something here that you're going to paste this right here the introspection query is something that that UI is giving you you're going to paste it into this tool here and when you run it it gives you this data here and the easiest way that copy and paste this entire thing is to do it from your network tab so if you

know how to open up your developer tool on a macbook it's command shift c move over to the network tab right and you'll see that it posted this query to the graph QL server and here in the response you can just highlight this entire response and take that and then once you put that in here this is what generates this view okay so all right so once you're here this is a

great way to be able to V these relationships and it gives you a good idea of how you can start building queries one of the great things that you can do is pull specific storage slots from an account and really use this to drill into the accounts storage and a single request so if you if you've built some applications already with solidity I think it's it's pretty painful to do this with the json-rpc without having to do a bunch of multiple queries so this is one of the great things about being able to now do it with graph QL so this started out as a project called eath QL sorry

so this project was started because we wanted to have a graph QL API for aetherium and this was something that was started by a friend of ours named Raoul who's now working with protocol labs he he did this while he was working on the Pantheon client and so our goal was always that we would work together to create a new standard besides just the JSON RPC for being able to query aetherium data and now we have this e IP 1767 that was trying to discuss the schema for this graph QL API now that that's been accepted there's a graph QL API that's been implemented into

etherium clients and soon another one so if you won't run your own etherium client you can run guest version 1.9 and above and it's going to include the graph QL API you just run get with dash dash graph QL and it's going to start this new API that you can query on the local port the panthéon client if you've come across the panthéon client it's it's an enterprise focused aetherium client I developed by the Pegasus team at consensus they've also implemented this standard and soon parity I understand is also looking at implementing it so this is something

that is really great for our ecosystem because we we often look at the tools that were created four years ago when when main that launched and we say these are the tools that we have but we don't always take a step back and say like how could we have improved this and are we really being limited by the capacity of the existing tools so take a look at this EQL project it has some extended features outside of what's currently in the EIP the EIP was kept pretty narrowly focused so that we could get it adopted and and merged in but there's some

additional things here like some plugins support for being a to support a RC 20 tokens and we have some ideas of how to move this thing forward over the next few months but we for the last quarter have been trying to focus on getting the implementations and the clients all right so I sorry I know this is pretty fast for a 30 minute workshop any other questions on graphic well I wanted to be able to show you a little bit more yeah so graph QL should also be able to support subscriptions

it's not part of the spec right now but we did a talk at each Paris where we said that's one of the next things that we want to do is try to push a specification for subscriptions over graph QL cool all right cool so the next thing that was on our list was some of these oh let me talk a little bit about the the archive data so indicate in case you haven't come across it yet there are multiple other AP is besides just the standard efj API that's available and the main one that I wanted to talk to you about was the transaction

pool API this is something that in Fira is actively working on adding to our offerings and it's something like we never wanted to add a custom API that's why we worked on making graph dwell a standard or eql a standard this transaction pool API that we're going to be providing will provide access to the content that's currently available on your death node if you run the transaction pool API so if you run your own node you can enable different API s for it whether that's the miner API the management API this one here is called the TX pool API and what you're seeing

here are the current content of transactions that have not yet been mined so if I go to meta mask here right now and I send out the transaction then it's going to go off into the network and it might take anywhere from a few seconds to an hour maybe to get mined and while it's in that pending state you most people on the network don't have access to that information of what's that transaction this TX pool content is what you would need to inspect and so if you enable this API and your client or if you use the one that in fear is going to be providing soon you'll be able to see transactions that are in flight but

not yet mined and the implications of this are you can have a better approximation of things like gas price so if you're familiar with the eath gas station project and the eath gas station API I may show you really quick maybe you'll easily recognize this page you can go to this page to understand what the average price of a transaction is setting for it's it's gas and you can use that to be able to set the gas price that you're going to use for your user this gas station API is powered by a trip the transaction pool under the hood

right it's the built-in eat gas price method is going to do a decent approximation of what you should be setting for your gas price but it doesn't have access to a large enough data set and the with the algorithms that the client uses aren't going to be as finely tuned as what like the gas station API can provide because it's just it's run that's more of like a traditional analytic service so if you have access to this API if you have access to this API you can now get this TX pool content and then you can better

calculate or approximate gas price you should be setting for your users or maybe you see that there's tens of thousands of pending transactions on the network you're able to better understand how long it's going to take for the transaction that your user just sent to get mine any questions on on that so far all right so the the other thing that was on the list is ENS so if you're if you're familiar with ENS there is a great

there's so we recommend using ethers je s as the library for interacting with ENS and that's really again because of the user experience as you're using ethers to connect to the network and you start getting all of these transaction or you're dealing with all of these addresses for your users can really consider using ENS in the applications that you're building the fact that you can resolve something like registrar dot firefight dot into its address and use that instead of having it having your user in dealing with these hex numbers

all the time the other thing that we're trying to add like I said to graph QL or EQ L and the graph QL spec is this native ENS support so that from this playground you're able to use ENS entries in here instead of just hex alright so that was a really fast like 30 minutes what questions can I answer for you guys I'm gonna be around in the hall afterwards and I can kind of walk you through the setup of this graph QL

if you still need to help with that I can walk you through some more complex query examples but any general questions I can answer for you right now all right well thanks everybody [Applause]