[Music] This workshop is titled bring any web to data on chain and basically what I'll be doing is I'll be demonstrating how we can use one of flair's uh enshrined oracles to bring arbitrary web to data onto the flare chain. So Flare is the blockchain for data. We have enshrined oracles that allow you to bring uh trustworthy data on chain. And so first of all, I'll motivate uh this demo by showing what data I'll be bringing on chain. I'll show you how we can modify this data.
Um and then I'll just run the process in the background. Um, so you can uh see how the script works. Um, yeah, and I'll also explain how the pro protocol itself works and what's the workflow of that protocol. Um, before we get started, let me uh direct you to the Flare developer hub. So on the flare developer hub you can see uh written guides for uh the protocol that we will be uh looking at today and other flare protocols.
Uh and so if you go to FDC FDC guides hard hat and uh web to JSON this is a a more in-depth guide on uh what I'll be demonstrating today and you can find find additional resources uh here on the flare developer hub. Um the second thing is the uh flare hearthead starter. Um this is a GitHub repository with example code um which you can use as a um uh baseline building block for your flare applications. Um it has uh examples on how you can use different FDC attestation types and different flare uh oracles and protocols uh in your applications. So yeah, what we'll be doing today is we'll be taking data from Star Wars uh API.
Um and we won't be taking it from the first one because it has been broken for more than a month, but the second one works. So basically what this API allows us is um it has an endpoint for um let me zoom this a bit. Um you cannot see it and neither can I but it has an endpoint uh which allows us to query data about Star Wars characters. So for example, if we query um Star Wars API API people uh dash one, we would get Luke Skywalker and certain information about him. Um so yeah, let me just copy this because this is the per first of the three components of the uh request that we need.
The second is uh if we go to JQ Playground, um this is a a website that will allow us to play with uh JQ filters. And let me copy this in also. Let's me zoom in so we can see better. So um basically um jq in a nutshell allows us to uh query and save fields. So for example uh we could do name equals dot name.
Um, okay. I think Yeah. Interesting. Cool, cool, cool, cool, cool. Um, let me just get the example so we don't waste too much time on this.
I mean, you know how it goes. Whenever you're alive, things go unexpectedly and what what anyways um this is supposed to be working. Um so jq allows us to filter uh JSON inputs. Um, and okay. Yeah, it's probably something with the I see.
Oh, no. I see what the problem is. So, um, the problem seems to be that the JQ that I pasted in, the JSON that I pasted in is of a weird shape. Oh, there we go. So, yeah, basically we what we can do is uh write name and dot name and that way we can um get the name field.
Uh but jq also allows us to manipulate the data we get. Um and not to waste time, I will now just paste in the um yeah I guess I will waste time. Um, okay. Let's do it the oldfashioned way and just cut in some of this. What?
Cool. So, this thing is not cooperating today. We'll skip this. Basically, uh, jQ allows you to filter the data and apply additional transformations to that. And the filter that I pasted in and is supposed to be working um is the second piece of the information we need to provide to the FDC protocol so that we can get the data we want.
And then the last component is the AI signature of the solidity strct that we want to store the data as. Um, and how you can get that is a bit of a mystery. Um, and I know I I'm just putting things out there right now without really telling you what is going on and why we need them, but please just bear with me. Um just the last thing that we need um and that I have prepared is the way you can get a solidity encoding for a strct is you can define it and that's too small probably. Uh so you can define a strct and then just uh make a uh a simple function uh that takes that strct as input and make sure it's public.
And what this will do is that when we compile this solidity code in hard hat, we will get the artifact for the whole contract and we can extract the AI signature from within the artifact. So if we go I go here to contract FTC example and web to JSON. Uh, and this one, if I just search for AI signature, uh, hack or just ABI signature. Um, you can, sorry, is it this one? Yeah, if I search for AI signature hack, um I can extract the only component from here and this will be the AI signature of the solidity strct that we want to um save the data as.
What I just did is I've given you a recipe of how you can use Flair's data connector without actually telling you what the Flare data connector is or what the um workflow for it is. So let me now do that. Um I will once again go to the Flare developer hub. Um nope not this one. the Flare developer hub because there is a handy diagram right here under user workflow.
Um, and let's open the image in the new tab. Um, ideally ideally I would now go there and point things out as they spell them, but they told me that I'm supposed to talk into the microphone. So unfortunately no uh acrobatics here but basically um the this is the workflow for the flare data connector. We start with some external data that we are interested in and then we need to prepare an attestation request for the FDC protocol. To do that, we can use a verifier server provided by Flare.
Um, and all it all this does is it allows us to send data that we need as a JSON to the verifier server and it will convert it into um encoded data. And we can then when we get the encoded data back pass the data to the FDC protocol which will decode it and start the whole process and then the machinery will run in the background. Um I won't go into detail into how that works right now. So you can um ask more about it uh afterwards or at the booth. Um but suffice it to say we get back data and proof that that data is valid or rather we can go to one of the flare validators which we call data providers and request data from them and then we can encode the data ourselves and generate the Merkel proof and compare the proof that we have generated with the that is written on chain and it has been written on chain uh by the consensus of all the validators.
Um so basically once we get data back from the validator we can calculate the proof and see that the data is indeed valid uh ourselves. Um and yeah once we have the data we can pass it on to our smart contracts um which will then utilize it. So one last thing from me is I will run the script. Uh so within the scripts fdc example web to JSONts um in the flare hardhead starter um the script here uh basically goes through the whole um workflow that I have described for us. And this is what I meant when I said that the uh code in this repository can serve as a baseline building block for you because this is a working example script.
All you need to do is take it, modify it, uh change it, change it so it suits whatever your project is. Um which is I think it's kind of neat. So yeah. Um I'll I'll talk you through the steps as they happen. So first of all, this is the data that we send to the verifier server.
So you can see this is the uh uh URL that the API that we are accessing. We are accessing character number three and you're free to guess who this Star Wars character is. Um it will be a get method without headers or query params or body. Um, but you can also provide those. Um, and this is the post-process jQ that didn't work on the JQ playground.
And the API signature uh that I've shown you. Um and we can see that the response we get from the verifier server is that uh our request is okay and the data is valid and AI encoded request is the thing that we want and we take this AI encoded request and uh submit it to the FDC hub contract on one of the Flare chains. Um we also need to calculate the round ID of the request so we can actually request the data the proof uh for the correct thing. Um and what is happening now is uh we are waiting for the round to finalize which takes some time but no more than 180 seconds um because um we need to get the consensus and everything. Um yeah we can also check the round progress at the link here.
So um I would say that the third request is probably ours. We we got 99% um acceptance rate in the sense that 99% of the validators uh told us that they are able to provide the data that we want and generate the proof. one said that they cannot but it doesn't matter. Um if we go under advanced and finalizations we can see if our round has finalized yet and um it would be the number 49. So we can see that the round has finalized.
Um and this is the proof that we got back or rather this is the proof response. This is the data we requested um but uh encoded and these are all the proofs that um have been provided to us um and then we can decode the data which I won't go into detail about um but basically we can decode the data and then send it to a smart contract and the data that we got back his R2-D2 um which uh who um stars in six movies. Uh it has the ID3 as we requested and a BMI of 34 whatever that means in this case. Yeah, we just took its uh R2-D2's weight uh and divided it by its height in meters squared and got 34 which is obese if I'm correct. Um but yeah, that would be all from me.
We have two minutes to spare. So more time for questions. Um thank you for joining me. Yeah, I see two hands. Oh, your presentation.
I was just curious how could you like integrate this in like maybe like a website you know like flow like for example if I want to build like a website with like metamas and our contracts how would we like integrate like flare into that um I don't know the specifics but I know it that can it can be done so yeah I mean this is a simple type script script so um yeah I do do you have like maybe like templates that show that off. Uh unfortunately no. Um I mean all the templates that we have are these scripts which are single script files. Um the specifics of how it can be implemented as a server. Uh I think I'll leave that up to you.
Okay. Okay. So we can just like do in the back end, right? Yeah. Yeah.
Yeah. Yeah. Okay. Cool. Yeah, that makes sense.
There was another hand there. Is that nice? Yeah. um for data which is not let's say open for data which is in a paid API which has like credentials yeah that uh that also works um you just need to provide the I mean with locked APIs you need API keys which you need to provide to them there is an example you how you can do it with trying to do that like with link like when they had some kind of similar was a bit like event was a bit tough or whatever. Um I mean if you look at uh weather insurance example here uh for example mean ex insurance and um resolve policy.
You can see that um there should be a um I think there there in this example we are taking data from open weather API which gives you it it is free to use but it gives you API keys uh to rate limit you and um if you look at this example on your own you will see how oh yeah this one u I was just trying to see where we pass it in yeah we pass it in this query params so if you can get an API key you can also access locked um locked APIs is there any way for when you put data on chain is there any way like let's say I put it like it was from Star Wars or Star Wars Star Wars is there any way like you also like the proof but it's like the problem has been taken from Star Wars or not Star Wars. Yeah. Yeah. Yeah. I mean you operate in the uh web tojson.
proof solidity strcts. Oh yeah sorry I forgot to repeat the questions. So yeah um um the question was how uh we can verify the proof basically. Yeah, but just make sure that like other people can check it and like the proof you put is from Star Wars, official Star Wars, not like some fake Star Wars. Yeah.
Yeah. Yeah. So, um the way we can the way they can check that is that the proof solidity strct includes the URL and all the query par params so that they can uh check it themselves. Thank you. Any further questions?
So we need to do our so we need to data on the back. So the question is how can we manipulate the data we get from the um website and basically you can do it through the jq filter. Uh jq is a I guess a programming language which allows you to perform simple manipulations on data and you can basically write your own filter and pass it uh u in as one of the attestation request parameters. Um and the validators will do that for you and just give you the solidity struct that you want. So and so they give me result of my I don't know.
Yeah. Yeah. They give you the resulting. That's right. Any other questions?
So, so usually how long will it take to like uh from requesting uh the proof and the data to like it's confirmed uncont. So um the question is how will how long will it take usually uh from the start of the process to the end? Um I think that usually it takes sometimes it happens very quick. Um but it will never take more than 180 seconds. Um I think that I would say that like 40 seconds is the average but I don't have data about that.
So so it's like we can continuously request data and maybe every one minute and the country will have the latest data all the time. Um yeah, data can be requested continuously. Um further requests will just be sent to the next round and the uh consecutive rounds but yeah data can be uh can be requested non-stop. Any other questions? I think this is time.
So thank you all for joining me for this workshop. If you have additional questions or problems with using uh the examples, visit at booth. We'll be happy to help you. And yeah, thank you for coming here. [Applause] [Music]
Automatic transcript — names and jargon may be misspelled.