Best Use of HyperIndex - ETHOnline2024
ETHGlobal·Wed, Oct 9, 2024, 12:00 AM
Join us for a workshop with Jonjon Clark titled, "Best Use of HyperIndex" This workshop is part of ETHOnline 2024, an async hackathon that takes place from Aug 23 – Sept 13, 2024. ----------------- Follow us: https://x.com/ethglobal Check us out: https://ethglobal.com/ Email us at: hello@ethglobal.com
Transcript
what is up Legends uh super excited to tell you a little bit about the EnV prizes in the eth online 2024 hackathon uh I'll go through the prizes a bit I'll go through actually using the products and how you can get the prizes so hopefully it's super informative and just a couple epic details to start off with obviously there's this nice prize pool um there's so many details on the website you can go visit but we're also super responsive and excited to help you build so if you come join the Discord um which is great over there if you check our site our docs we more than happy to help right quick high level what is nvo as you can see it's the fastest most flexible way to get onchain data and there will be two main pieces we talk about hyper index hypersync and how you can win prizes for both but if we have a quick look at Envia over here you can see more about hyper index you can see more about hypersync there's a lot more stuff we'll go through um so yeah very quickly to start off with Hyper Index this is a blazingly fast blockchain indexer but it's also a multi-chain index and we'll get on to how you might want to use it but generally if you're building some kind of uh dap some kind of smart contract that you're deploying people are going to be interacting with them and when they interact with them you're going to want to have a way to take this interaction data make it meaningful and show it on your your website right you might want a leaderboard of the people who've interacted with your smart contract the most or how much they've deposited how much they've with drawed um all of those kinds of things so you can see here what is the best use of hyper index we have this uh prize over here which is really nice and just to show you a little bit more about hyper index that's what we're going to jump into uh right now so let's start off with that right so I'm going to actually start off by showing you what it looks like in the hosted service and expand upon what I meant so if I hit this Explorer button over here real Nifty you can see there's a lots of protocols that have deployed nvo explorers uh some nosis ones some scope ones some sabler I'm going to go into this sabler one you can see in this production sabler deployment from about a month ago they have processed 335,000 events across all of these different chains and just in case you don't know what an event is um I think it should be uh pretty obvious and you probably do know that but let's find some I don't know let's find some random uh thing over here um let me find a what's a good one igen layer let's take a random contract right I strategy manager you see events and when people do stuff like they call this deposit into strategy method then events like deposit which show you who is the Staker what's the token what's the strategy what's the number of shares this information is very useful and it gets emitted and what's happening in the index are here is it's it's processing all of these events across multiple chains and the index takes this event and you define some logic that when this event happens I want to save it I want to transform it and then the result is you get this really nice graphql API where you can make some kind of query and say I want uh the tranches and I want uh the amount end amount time ID position I want all of these things and your uh front end can essentially make these really nice structur queries and get data about your users or about anything like that so that's kind of the the 101 on indexing and and why it's important and why it's nice and what's nice here is you can see you can index across multiple chains and you can do it really fast normally to go through uh 12 different chains and syn uh hundreds of millions of blocks would take uh months and this took 27 minutes so that's a really nice part about NV it's really really fast so without further Ado uh let me actually show you more about how to get started and do this yourself and how Works um and I'll just show you here's the repo go give it a star smash a star would appreciate that uh you can uh dig in a bit more if you want and and see what's actually going on on the code here but for now what I'm going to do is I'm going to pull up a a terminal um give me a second to bring that across uh I'm going to just uh uh make directory demo uh make directory demo to I know you can't see my screen right now uh but that's fine um cool I'm going to uh do this I'm guessing you can all see this this which is great and you can see right now I'm in a completely empty directory and what I want to do is I want to index something so we've talked about it we have some protocol that we've deployed um and I want to index all the events and query information from it so the the quickest way to get started is first you want to quickly check the docs it's it's very simple how to uh what you need to install node pnpm Docker I have all of that installed um also have EnV installed so go install those bad boys super easy there's also this no code quick start guide over here but all I'm going to do is I'm going to grab this contract address um of the events I want to index over here like the deposit events all you'll need to do is run this NV init command I'm going to call this igen layer indexer um I'm going to start here um I'm going to say typescript uh we're going to do evm I'm going to say contract import From the Block EXP Explorer ethereum main net and this is the address uh and it wants a valid API key this is uh very sad because it normally tries without the API key um so what I'm actually going to do which is a little bit cheeky is I'm going to use a network like optimism so what happens is you need to provide a little API key to to fetch it from the ABI but this is so far only on um main net it's actually much easier to get it on optimism and that's something we're improving as well so on optimism let's say we want to go for indexing what about the op token this is the optimism token right here right and there's all these events you transferring the token this or that this is a super busy contract I'm going to copy this address so now if I say EnV in it um optimism token indexer yes typescript evm contract import and from the optimism block Explorer where we don't yet need as strict of a a key I'm going to put this contract address in and there we go you can see that's super nice it goes and grabs all the events for us so yeah on Main net we'll have that improved soon but for now you have to put in your own API key uh the public API Keys work a bit easier for some of the smaller or let us say other networks not that optimism small um and let's just say I only care about um maybe the the transfer event that's the only one that interests me I can then add new contracts do a whole bunch of awesome things or just say I'm finished and I'll skip for now I won't add a a token what's happening is it's autogenerating an indexer for us that's extremely nice and what I'm actually going to do is just uh just in case I actually already had an indexer running somewhere else on my local computer because I do a lot of indexing I'm just going to say pnpm NV stop you won't need to do this you likely won't already have one running that's just because I have one running but if I now run pnpm NV Dev actually before that what I'm just going to do is I'm going to open up this code of what we've generated just so I can show you in a second so I'll I'll show you the code I've generated now uh but what I'm going to actually do is I'm going to now say pnpm nvod Dev and it's going to actually create and start indexing so I'll show you what we can do with that now in a second but you'll see just like that it's already scanned through the first 9 million blocks and it's already processed 10,000 15,000 uh events it's going to keep smashing up if my internet was better that would go even sooner but yeah we've already indexed more than 9 million blocks and we are extremely quickly going through and indexing uh thousands and thousands of events and if you know much about indexing uh you'll know that that's extremely extremely quick right so just to show you a little bit about um actually what the code has done and what it's generated there's three main parts this was all just generated Brand New by the by the NV init command by the way it's super easy to get started your config defined uh kind of what data you want to suck we want to suck it from optimism from this specific address and this is the transfer vent I was talking about that we wanted very very nice uh your schema tells you uh the how you want to store the data what it looks like you can think of this as kind of your table um and it's very simple and then this event handler tells you what Transformations must I do when I receive this event so every time there's a transfer event on this op token all we basically doing is uh grabbing the information like the from parameter from the event the two parameter and we basically just saving it right again you can see we've indexed more than uh uh 240,000 events the password is just testing over here and now what we can do is we can see all of this data Maybe Just plus over here all of these transfers we can see there are tons of transfers over here we can see from to the value just like that and this API this is what you might be interested in in your front end you might want to make a query and say uh give me the biggest uh transfers so you might say I want the 10 biggest transfers uh let me first get rid of this part over here give me 10 transfers where value um um sorry and let's not use aware we're going to say order by value descending so we want the the biggest ones and we want the value we want who is it from who is it to and what's the ID and bang just like that we're going to see wow okay the biggest transfer we've seen so far is from this zero address and it's uh 429 quantian for tripan Mish mobilan uh over there which is quite a big number and you have all of these cool things so you could have a little application that does a leaderboard of the biggest uh op transfers and who's transferring from who to who and this is just indexing and it's it's smashing along uh which is really really nice so what you can also do I just want to show you quick I'm going to stop this you can say something like nvo in it uh you might be developing locally so what you might do is you might say I want to use a local ABI and here once you've compiled your smart contracts you just put my local ABI la la la la la and it will generate an indexer for you very very nice so that's going to get you started and again you got this uh golden trifactor of the schema the event handlers and the config and that's going to get you going and lightning fost you're going to index and remember your best friend is the the docs over here the V2 docs uh there's more videos over here there's a lot more information there's some tutorials there's some guides uh there's all the good stuff so go ahead and smash this and that takes us back to best use of hyper index and there's more things like uh best runup of hyper index most creative application of nv's features so you can think of lots of ways to use hyper index which is really really nice um as we saw all of this uh information is indexed to this very nice database that you can then uh do a bunch of different things on which is interesting you can hit it like an API you can deploy it to the hosted service over here so it's hosted on Envia and make your queries uh from the endpoint which is amazing you can see all of the logs uh you can go check out some of the other ones for inspiration and check the repos so check that out there's tons to do there again uh this this price fits really nicely you can do this prize while also trying to hit all the other prizes in the competition which is Monster uh this can just be part of your Tech stack which is really really nice super fast scales well so that's a nice nice one uh also if you wanted to do some kind of analytics visualization Pro uh project look at uh information across multiple types of chains maybe you're doing like a bridge Explorer there's just so much you can do with access to super fast onchain information remember all of these events um on any of the contracts you're absolutely sucking them up and you can do some very interesting analysis uh again we support more than 45 evm chains so there's a lot of options for you so that's best use of hyper index it's a lot of fun go play around with it um and yeah last thing I said as I mentioned um in these event handlers this is very simple but you could just write some uh cool code over here um if you wanted that did specific things like every time a user deposited you know you uh did something you can change this like it's it's made to be very flexible this boiler plate just helps you get started which is super nice okay let's cruise along to best use of hypersync and hypersync is actually used very heavily by hyper index if you wondered how we were absolutely steaming along and and getting so many um events so quickly from all these different Chains It's because we are using hypers sync which is a a really really powerful rust data node and uh it allows you to access historical data transactions uh logs uh blocks uh traces really really quick and we have a few different clients we have clients um here's the hypers sync docs by the way where you can learn more about it but we have clients in node.js in Python and in Rust and there's even actually a community one and go and there's examples in all of these so you can go check out the examples and and see what you can actually do but I'm going to start off by showing you actually just something I've built with hypersync and this for example would be uh you know who knows maybe a contender for this if you built something like this I mean I've already built it now but I'm sure You'll Think of many other cool ideas and this was also in a in a hackathon I built this it's called chain density and I think it's pretty cool it lets you choose from um all the network hypersync supports and it lets you figure out something called The Chain density so you might want to know uh of all of these events uh when which blocks were they emitted and it's interesting to sometimes know uh what the distribution of on chain activity looks like for an address so I think maybe it's just going to be easier for me to to show you what I mean let's pick a random address this one's got seven transactions I might want to see okay what are the transactions over the entire optimism chain what does it look like for this address like where is it interacting and I just put in this address I say I want the transaction density and I want to say it's for optimism optimism's there um I hit submit and in 0.13 seconds it scanned all 124 million blocks and it's showed the where the transactions have happened at what block number that's quite interesting uh so yeah we've scanned uh that's nearly a rate actually of a billion blocks per second so that's really nice let's choose um something that's a bit more interesting maybe this igen layer manager one over here or what's another IG layer one IG layer um what about rest strategies is this emitting any events is it interesting it's not actually emitting that many events uh Ian [Music] layer uh what about Community multisig what about slasher let's see when things are being slashed on igen layer oh not not super often okay I want I want to find an interesting one for you I layer igen pod manager this must be interesting okay there's some more things happening in the IG pod shares pod deployed quite a lot of stuff's happening here let's maybe click this and let's see uh what the events look like in the igen Pod manager I hit submit it's going to scan the entire ethereum chain and it's going to get all the EV that are omitted from this address and very quickly you can see oh this is what's happened okay there's starting to be a bit more activity uh another cool one let's do like a blur Marketplace uh blur Marketplace to you can see there's a ton of events happening here and blur blur Marketplace to I'm going to hit this let's go back here um this would take you quite frankly forever if you were going to use the RPC and that's why using hypers sync's really cool oh check we can see it's obviously stuff stopped happening at block 16 million but you saw uh an increase in activity more than 40,000 defense process that's very nice okay so this is hypers sync let me show you what it actually looks like again remember we have these clients for you to interact with it I'm going to uh find uh this piece of code um over here and basically uh I'll I'll show you this repo this repo you can come check out as I said there's tons more examples um over here if you if you come to the docs this is quite a cool example evm address summary it basically you give it an address and it's going to fetch all the token transfers uh all the esc20 transactions all the EC 721 transactions it's going to just fetch anything everything uh this one is in the node.js client you can Define this query structure it's super flexible from block what logs transactions traces you want um it's not so daunting don't worry about this and then uh you can say what stuff you want back we want uh these logs these transactions these traces so it's quite simple to Define your query uh you can come look more M the docs over here how to define your query it's very powerful you define your network which is nice um and then we just do some math here you can do that in Python you can do whatever you want and I'm just going to run it to go ahead and show you uh how it actually works so if I do pnpm all transfers that's how the script works and you just give it an address it's going to scan the entire chain and there you go you can see it scanned 20 million blocks in 2.4 seconds and it found that this address has three transactions in nine transactions out and it's got erc20 transactions for this and just to show you that this makes sense let's go pick another random address okay this one's only got like 10 transactions let's pick this address that's great uh I'm going to grab this address and again let's say pnpm all transfers I'm going to paste this address it's going to scan the entire etherum chain and in two seconds it found okay there's four transactions in there's six transactions out uh this is its balance and you can see there was no erc20 transactions in this one um so yeah that's that's a little bit of the magic of of hypers sync um definitely go ahead and uh check it out again there's a video over here it shows how we do stuff like extract the whole lot of Unis swap events how we scan 200 million blocks and arbitrum and and decode all the pool log created events there's there's really a lot you can do here it's very very uh flexible and if you want to do any kind of data science related project uh this is going to be yeah really really special for you so go check that out uh there's also just special mention you can make Co requests which are super easy as well like I want to get all the transactions to and from an address you can stick this in your terminal and make the request and you'll you'll see you'll get a lot of things which is nice so yeah hypersync what is the best use build something crazy this was an example of like a cool tool I built using hypers sync where for addresses you want to see its activity over time you know maybe you want to see something like uh I don't know a border AP Yacht Club what does the activity look like of a Bape Yacht Club right this could be interesting you know this was a cool nft uh let's check that maybe we say transaction density uh or let's say event density and we hit submit and bang there you go you can see oh it went up and it's been trending pretty downwards on chain so yeah this is an example of a cool tool bolt with hypersync um and there's many more Cool Tools you can build so the sky is the limit uh there's there's epic epic things I want to show you something else that's been built uh using partly using hypersync um this is scope it's it's a really really cool uh Explorer focused on account abstraction and yeah a lot of the data is all coming uh from uh hypersync as well and the the client and the indexes so um just shows you can build really really cool stuff uh using hypers sync that's super performant got lots of Rich data um yeah so that's another cool example I wanted to show you and if you want ideas come hang out in the Discord and we can tell you stuff so yeah there's lots of options for you to use hyper index indexer or hyper sync um there's the best overall project there's the most creative use of the features there's the best runner up after these two best use cases so there's really a good variety of prizes um it's good fun technology that's really really performance and cutting edge with good documentation and really good developer help so yeah it would be super pumped for you to build on it and really excited to to chat with you so come also hit the website check the Explorer uh see more about hypers sync docs uh look at the blog if you want to see see some cool use cases of of how people use it and most important remember to drink some water touch grass stay healthy have a good hack remember to you know have some orange juice on the side and some good snacks to to keep the brain uh functioning it's a it's a long hack so have fun take it easy and come hang out in the Discord we'll see you guys soon massively excited for you to build using EnV and that's it we'll leave you there
Automatic transcript — names and jargon may be misspelled.