DAPPCON 2018: Eth.events - a Supercharged Ethereum API simplifyin .... - Sascha Goebel (eth.events)

DappCon 2018 · July 2018 · 11:46

Sascha Goebel of eth.events presents a supercharged Ethereum API at DappCon 2018, walking through how the service simplifies querying and monitoring event data emitted by smart contracts across the network. The talk covers how developers can use the API to track on-chain activity without building custom indexing infrastructure, positioning it as a tool for building more responsive dApps.

Speakers

Topics

From DappCon 2018, hosted by Dappcon Berlin.

Transcript

yeah hello everyone as you can see we're trying to stretch this until lunch my name is Sasha I am here to present each event I have mostly history in the big data and machine learning stuff and yeah today I'm here to make your lives your developer lives a little bit easier I will be talking about each events which is basically a elasticsearch index of all blocks translation transactions logs and events that occurred on the ethereum blockchain since the Genesis block we are processing this data and enriched it

using the available ABI and provide you with a query and aggregation framework on top of elastic search and yeah let's get started I think the best way to show what we're actually doing is by using an example so imagine you are writing a decentralized application something with kiddies and at some point it will be a huge success so you are interested in getting some insight into your application you want to know how many

kitties have been born since you started your application and for that I know there's a property on the crypto kiddies contract where you can just look up that number but to make it a bit fun we will have a look at the birth event which is shown here this is emitted every time a new kitten is either born through breeding or generated automatically from the contract and below the event signature you can see the topic which is just the the hash of the event signature so the first thing you would try to do would be to just use the JSON RPC with

your preferred aetherium client you would do a curl request or you could do this with death and then parity and you just put in the the address of the contract this is the the crypto queries contract and the topic you're looking for the the birth event and once you send this transaction this a call you get back this information which is the address and topic you were looking for you will get actually a lot of these objects back and there is a big data string which we will look into now in more detail because actually this is only a concatenated version of the

single parameters of the event we have the the owner the kiddie ID the parents and the genes with this specific event every single parameter has 32 bytes so everything is the same length but of course this could look different for other events but this is the way you would extract the information out of the raw event you're getting we are the JSON RPC the next thing because this isn't that handy you try to use the web 3 API you would create a contract using the trip to kiddies ABI and the contract

address again and then just carry the birth events and as soon as you start watching the event listener you will get the single birth events with all the data extracted and if you just leave this running you will get new events as well it looks like this there you can see in the arguments array you have all the parameters already extracted and you can kind of easily use them but this comes to a price because both ways of currying event data from the block shake line is quite slow this is mostly because not all event data is stored permanently on your local

machine because it's just too much we have roughly 6 million blocks by now and over 170 million event locks that were generated and because these can be easily regenerated from the blockchain they are not stored permanently on top of that you don't have any filtering options so your only way to go would be to fetch all the events and then filter them manually which again takes a lot of time and as you may have noticed in my examples before I only fetched a few events from the last days because at least on my machine when I ran it for

the whole blockchain it just crashed because the data that need to process was was just too big so in the end if you're serious about your decentralized application and you want to have insights in your event data then you are going to build your own database of the event data you will put everything we just saw into the database make it searchable and filterable and then you can work with the data this is by the way exactly what the crypto kiddies guys did they have a medium article online where they're describing their struggle to keep the gift line that feeds in the data running because it apparently crashes quite often when doing such

things and yeah I don't have any notes so I don't know what's next yeah of course I was originally talking about Etha vents so we're going to solve a lot of these problems by providing a already existing index of all events that ever occurred on the etherium blockchain you can you can query and and aggregate the information and yeah this looks like like this so in case of the crypto kiddies I hope you can read this we have again the decrypted Kitty's address and we're looking for the birth

event and in the end the the result and you can see it took 32 milliseconds which is a bit faster than using the yet client directly and it gives us around 850,000 kiddies that are in existence this is not exactly the number that's on the crypto kiddies web page I am not sure why maybe they are hiding some special kits but yeah it adds up at some point so this is of course not the only thing you can do with these events just counting some some kitties you could also have an aggregation in this case on the birth rates per day this is from the beginning of the cryptic Kitty's

contract until now and you can see in December when protocol this was kind of popular a lot of people started breeding their cats and invested a lot of ether in it and yeah we had a peak in in December and then it kind of flattened there are also some kiddies generated automatically so this is some of the base load but yeah people are still using this and having fun with it I assume some people have invested a lot of money it's a good move to to keep on doing that and speaking of investment you can also trade the kitties on the auction contract which is what we're looking at right here I did an

aggregation on the hour of day so you can see there is a peak at 9 p.m. which is UTC time this is roughly noon in the US so you know what people are doing in their lunch break okay so you might be asking what's in it for me when using it events what you're getting is real-time blockchain we are indexing the events as soon as they appear we are listed constantly listening to the yep client and input all the information into our database there is no own server or other infrastructure needed everything is hosted on our machines so you can just

use it there is no setup required every data is already there and in case you published your smart contract on the blockchain but did not publish your ABI we can enrich the data afterwards so if you want to use it and want to give as your ABI we can later on import it and the data will be available within minutes yeah you can use it I mean in the end it's a rest interface you can use it on the server client side on the server you could push aggregated data into your metric system or on the client if you're up to that you could build a dashboard completely of any service as a

decentralized application and live the dream and yeah finally it's free so for normal etherium Deb usage you don't have to pay anything to use it of course if you're planning on doing five thousand requests a second or want to integrate some exotic side chain we have not heard of we would have to talk but for the basic usage is completely free okay the next steps would be at least one second at least that's what we have in mind

right now would be to have clients in JavaScript Python and Java we are going to simplify and optimize the existing API right now you can send raw elastic search queries to the service which is quite powerful but also not that handy so we will provide specialized endpoints for things like easy counting or simple aggregations we will provide a statistic and and status endpoints so we can check at what block the index is and what the server time is so you can make sure that you're really looking at the latest data as I said we will integrate tests and

private chains and we will probably also provide a streaming API using WebSockets which will enable you to just listen to event updates or even get continuously aggregated information for your systems and finally you name it literally so if you have a specific use case in mind and want to get on each events we are here the whole two days so stop by talk to us we're here and yeah we're hoping we can help you thank you stay awesome [Music] [Applause]