Chainlink Developer Workshop - Dan Forbes
ETHGlobal·Fri, Oct 9, 2020, 12:00 AM
Chainlink Developer Workshop with Dan Forbes from Chainlink
Transcript
hi guys my name is Dan Forbes I'm a developer advocate for chain link and today we have a relatively short period of time to talk about chain link so I'm gonna try to do that in an efficient way um the workshop that we're gonna be working off of today can be found on this github repo that I set up it's github comm Dan Forbes / Stanford so you can find all the information about me that you want there um so the workshop that we are gonna be working off of today is this chain link plus remix workshop so this is gonna be a fairly you know an exposition of the the basic capabilities that chain link provides I'm assuming that since you all are here you're pretty comfortable with blockchain solidity development um so I'm guessing that everyone kind of knows what remix is and and all that stuff okay cool so we don't need to talk about that um so I'm just gonna use some technologies that you guys are probably already very familiar with to showcase the capabilities that chain link exposes um so I already have remix D installed if you're not familiar with remix deed that is like a little program that you run locally that allows you to pipe your local files over to the remix online IDE so that you can work locally um so let's let me uh preparing before you guys came okay so what I'm what I'm doing now is I'm in my my home folder there before I'm gonna do things in a slightly different order here so before I use remix D to connect to my local computer I'm gonna save the code that we're using which I think I've already done this but that's okay just for the sake of completeness we'll do it again so the code is right here on the the workshop that I'm working off of here it goes takes you to this code that's up there on gist you can find it very easily it's um you know you'll see it in lots of chain-linked workshops and such and so because we're doing things simple I'm just gonna create a directory in my home folder called workshop that's what we're going to be working out of we're just gonna use this one solidity file so I'm going to go ahead and save that and now I'm any newsroom d to connect and i i've alias alias rmx to be this helpful remix command so i can just run that sir sorry any questions yeah sure sure 100% so we we won't use that alias let's do it from scratch so let's this is what the the command that I'm using is so we're invoking the remix D application I believe that s stands for source um so we're going to well actually let's let's move into that doesn't it bother me okay so now we're in that workshop folder that we created it has that solidity file that we downloaded so now I want to connect that to remix so we're gonna invoke the remix D command S means source I think so I'm gonna use the current directory you know specified by the dot as the source and the remix IDE that I'm using is just the the standard remix that the etherium foundation puts out there or I could pass a relative or absolute path to the directory that I wanted to use and I could be working out of some other directory just for convenience sake I'm just in the directory that I'm gonna be working in but you could just specify whatever path was pointing to the the source directory and I think actually in the in the official documentation they tell you to use an absolute path and not a relative path um but I think it obviously works fine so okay remix IDE this is why you alias things so you don't make errors like that in in workshops but that's cool we're also here to learn about things so now I can go to remix etherium org and you can see it's very helpfully saying like do you want to connect your local um your local file system and I accidentally closed that no big deal because it's a nice little tool and I'll just click here and say connect and boom there we go we see it on the other side there this a test net consumer dot Sol file that I downloaded so because this is an IDE it's helping me to figure out some things that I'm doing wrong specifically I need to use a different solidity compiler and now as much as I do like remix and I think it's a tool that we should all be using it's not without its little quirks here and there and that's why we do these workshops so people are aware of them and understand them so I always have to compile files twice in remix so here we go I'm gonna compile it for the second time and God willing it's gonna work um so let's go to our our workshop we'll see what we're doing here we've used remix to compile the test nut consumer solidity file that we downloaded and now we're gonna go ahead and deploy it to the Rob stone test Network so now when I come over here to the deploy tab of remix the first thing I want to do is I want to make sure that I'm using the the web three api's that are being injected by my extension in this case I'm using the the brave wallets so we're gonna use that you can see it's already connected and now I want to make sure that I'm deploying the correct contract so I'm going to select the a test net consumer contract that we compiled these are all the dependencies that were also compiled when we compiled a test net consumer but we want to deploy the meat of this project so we're going to deploy a test net consumer so now my wallet is you know asking me to pay for all this because I like you guys and we're working with free money we're gonna do this really quickly and also because no one likes awkward silences in a workshop especially me as I'm sure you can tell so now we're waiting for this to deploy and so once this deploys we're gonna fund the contract with link and link is the chain link utility token it is a mechanism for value transfer as well as a mechanism for data transference so it implements an e rc that was written by our CTO that exposes this transfer and call capability so what it allows you to do is you you pay for the service that the Oracle is providing and just in case we didn't really talk about that I I guess I kind of took for granted that you all know what chain link is and what we do what we do is we bring off chain data on chain and so what I'm working through right now is this process of getting the etherium to USD exchange rate and bringing that on chain into a solidity smart contract of course the blockchain doesn't know about USD it doesn't know about what the exchange rate is so that's off chain information that we want to bring into our smart contract and so that's what we're doing right now and so that is a service that we need to pay for there's someone out there running the chain link node and they're managing the infrastructure all that kind of stuff and so they're they're exposing the service and we're gonna pay them for the service that they're exposing and so we pay for that using our link token and then because it implements this ERC that was written by our CTO that's also how we communicate the details of the request namely reach out to this API to get the the eath to USD exchange rate you know there's some other stuff in there that we're gonna talk about um but the long and short of it is or in this case in the long and long of it is we need to fund this contract with Lync so that it can make this chain link request so that's the step that we're on now we're gonna fund fund this contract with Lync um so while I'm doing that are there any other questions because obviously I didn't necessarily do the best job of like explaining everything what's up the workshop yes and that was something I explained at the beginning of the workshop if you go to github comm Dan Forbes slash Dan Forbes you can see different workshops that I've done and we're doing the chain link plus remix workshop okay so um one of the reasons that I like remix is it it exposes a lot of friendly capabilities for us and one of them is that we can really easily copy the the address of our deployed contract so I just copied that to my clip bored and now I'm gonna fund this contract that I've deployed with link paste that there I like we only need one link to do this but I don't like seeing weird odd numbers so I always use multiples of five again spending free money is so much fun what's up do we have a question so that is a price that's set by the node operator so chain link is open-source software it's run by people who want to run it and who want to provide this capability and receive link as payment for this capability and so like I said they may have different infrastructure someone may be running their chain link node on their laptop and you probably wouldn't want to use that node operator for a production use case but there may be people out there who are very well-known in the blockchain technology industry that are running these nodes you know it's kind of part of what they do is their business they have very high assurances regarding uptime they're using the best infrastructure so they have to you know they're they're running they're providing these services and they're expecting to get paid for them and so they set the price that makes sense for the services that they're offering um any other questions that's a really really great question about how chain link works okay cool good seeing you again yes yes so right now we that is kind of the way things work and I'm hoping that I'll be able to show you something really specific to that that can help you in that case um we are working on a feature called service level agreements which is going to create a more long-standing relationship between a smart contract creator and a node operator providing this service that's in the works you can follow our progress towards that on our pivotal tracker which is a public feature tracker you know all of our code is open source so you can follow all of this on github but that's in the works and what I'm what I'm presenting des is kind of what we currently offer because it's it's enough and it's really cool and I think it's really helpful any other questions yep no this is great I don't believe that you have to expose the data that that would be your choice and in fact to answer the the previous question about like aetherium to USD exchange rate I will show you a contract that we are maintaining that can be used for that it's a reference contract that we're providing so you can expose those kinds of capabilities um but I think that you could also maintain that information is private or certainly um you wouldn't have to expose the information that you received you could just perform some calculation any other questions these are really really great questions okay so we funded our contract with Lync let's kind of see where we are so now we're gonna use remix to execute one of these functions on this contract that we deployed and we're gonna provide it with some parameters that are in the chain link Docs and again one of the reasons why I like remix is because we can do this we can deploy a contract and exercise it all in one kind of go so I'm just going to the chain link Docs here and we'll talk about the data that I'm gonna get from here if I can find it here it is okay so we are gonna be calling this request aetherium price method and as we talked about there's some node operator out there that's exposing this capability um and so this is the address of the contract that is associated with that chain link node there's an on chain and an off chain component to the oracle and so this is the address of the on chain component and then this is the job that we're gonna call on that oracle so you can imagine that someone sets up one of these nodes they're not just exposing one capability they're exposing a whole host of capable because there's many many data providers out there and they want to expose a certain set of that and so we're telling them that we want to use this job ID what's up yeah I use capability a lot it's a very general term and so in this case what I'm referring to is some API that's exposed by some data provider so chain link we can really hook into any kind of API data provider anything like that so most of the API is that we hook into a restful api is that I'm sure you're all very familiar with but that there's no requirement for that I wrote something that allows chain link to query data from a G RPC API if you have some proprietary API you can hook it in to that there's middleware that allows you to do that so from my point of view it's just that this abstraction this data out there some data provider that exposes capabilities and so we're gonna get those into our smart contract and so we are gonna tell let's let's look at this request etherium price method actually so you can see that we're gonna specify the job ID which we talked about and then when our our request is fulfilled it's gonna come back and there's gonna be a callback that's gonna get executed with the data that the node is returning in this case where we're calling a function that's on the contract we're currently writing that's not a requirement you could have you could specify a callback on a different contract if you wanted to and in this case we talked about kind of custom middleware that you can write for accessing any data provider there's also just built-in adaptors is what they're called that are kind of baked into the chain link software that you can use to access data providers and so one of these built-in adaptors is HTTP GET as i said it's very common to get data from a restful api so we kind of expose built-in functionality that makes that super easy for you now of course that API is going to return some JSON table JSON object so we want to tell the node what value in that response we want to get so we provide a path that we want to walk to extract the the value that we want so in this case well here let's actually look at it let's see what what data the node is going to have access to this is just an HTTP GET request right so let's go ahead and execute that request I don't know sorry this is not gonna be easy but that's okay I do want you to see that we're not doing anything like magical here we're just reaching out to this HTTP API it returns a very simple JSON response I'm sure you're all familiar with that but obviously we just want to get this exchange rate out of here so in this case we want to walk this path to USD so that's what we're providing is a parameter to our request of course if there was a more complex path we needed to walk we can do that too we can dig into objects we can specify array indices all that kind of stuff and then in order to you know play nice with the theory of datatypes we're gonna take this value and we're gonna multiply it by 100 before we write it back to the blockchain so that's basically what we're going to execute we funded our contract with link so that we can send this request it now has what it needs to pay for this request as well as how it's gonna transfer all of these arguments that we just talked about so we're about to do this and make this happen are there any any questions about that or anything that we've talked about at all cool so I'm going to go ahead and copy these values here and I'm going to paste them into this way that we're gonna execute this method all right so now it's happening so while it happens we can of course if we want we can go see the transaction out there on ether scan but I also wanted to show you that we can look on our Explorer the chain link Explorer so what we do is we take that transaction and we paste it in here to the chain link Explorer there's the job that we're running so what we can see here is this is what's actually happening out there on the chain link node this is the I believe the invocation of the job that you know the ID of the invocation we have the job ID we are running this node so there's all kinds of information in here for you and you can see that that obviously we had to configure this job on the chain link node side and so we talked about the HTTP GET task that is performing we talked about the json.parse task it's performing we talked about multiply we didn't talk about these last two things the node is going to convert that multiplied value into the e few in 256 data type and then it's gonna write that back to the blockchain as a transaction it's gonna go through the oracle contract and get called into that callback function that we talked about did you have a question correct there specifically they're part of the the job that we set up and we invoked that job with the job ID when we when we made that and so this has been created by some administrator on the chain link node where in this case we are composing built-in adapters to achieve the the functionality that we want but you can also one of these could be replaced with what's called an external adapter and that's what allows you to query a G RPC API a proprietary API you can have business logic in the external adapter so maybe you want to query multiple data sources and perform some kind of off chain aggregation they're very flexible so there's the Oracle and then there's the data provider you can just use HTTP GET if you want to talk to the data provider or you can create this external adapter which sits between the Oracle and the data provider and does work that you as the external adapter developer get to decide what that work is you would need to use an external adapter yes umm yes excellent question I've thought about the same thing myself you would need to use an external adapter there's anything too so let's let's see how this job is doing okay it says that it hasn't yet written it back to the blockchain I don't necessarily believe that you know these things are asynchronous and sometimes they don't always work so let's see if we get a current price we do get a current price so let's let's go see what happened we made this request and this called our fulfil aetherium price selector so let's go down here we are for fill at the Aryan price you can see there's some kind of helper functions that we have in here to make sure that things are secure and everything but basically what we do is we update this state variable on our contract this current price state variable and now we can query it just like we would any other variable before we we made this request that that value would have been 0 so unfortunately I am at time now so I don't have much time to go over kind of next steps I hope that that was helpful and you understand what chain link does yes so there are third-party marketplaces out there that already exist where and they're run by really reputable people that are trusted members of our ecosystem but they're independent because you know chain link what we want to do is bring this promise of decentralization out to the Oracle layer so that you can build end-to-end blockchain applications that include real world data but that don't sacrifice the guarantees of blockchain decentralization determinism you know data integrity all of these kinds of things and so this is a much more sophisticated example of composing chain link capabilities namely this is that reference contract that we're maintaining with the etherium to USD exchange rate there are 18 node operators involved in this process there's an on chain aggregation process where we take the median of the different values that we acquire and so I'm gonna have this demoed at our booth which is you know right out there so I can go over all of this with you but today's workshop was pretty short we covered the basics you saw how to make a chain link request and how to use our capabilities to access off chain data from a smart contract um I hope that you guys use it in your hacks if you're wanting to do so please come find me it's my job to help you understand how to do that and I hope that you have more questions now and your I'll come by our booth and ask them any sure you do so in this case what we're doing is we're there's 18 node operators and across them they're querying eight different data providers so we get lots of different data oh wow it's actually been bumped up to 20 so we're we're adding new node operators to this contract that we maintain all the time but we want to make sure that the value that we write back to our reference contract is rock-solid because we're providing it to you in the community and you might use it in your smart contract so we don't want to provide you with bad data so what we do is we take these 20 different values that come in and then we take the median of those values so let's say that at the data provider level there was a breach of trust maybe God forbid at the Oracle level there was some breach of trust but somehow one of these 20 data points was bad in this median aggregation process it would get discarded but that's an implementation detail that we as the smart contract developers made because in this case we are smart contract developers providing a reference implementation of the capabilities that we expose maybe it would have made more sense in this case for us to take the median so we discard maybe we discard the the two most outlying values on either end and then we take the mean that would be another way of aggregating the values the idea here is that chain link is exposed capabilities where you can even aggregate values where you can have a decentralized source of off chain information and and you as the smart contract developer can then make smart decisions about how to use that off chain data but first you need to be able to get that off chain data into your smart contract in a way that makes sense this is the reference contract that we're maintaining for this very specific use case but it's very important to me that you understand that we are open-source software and we are we support an independent community of node operators and data providers so as the creators of this technology we are showcasing it we are assuming the role of the smart contract developer and composing our capabilities in a way that we want you all to see but that is not to say that you you need to rely on chain link for any of this that's antithetical to what we do we want to make sure that this is fully decentralized there are these third-party marketplaces you are able to run a node if you would like I would not encourage you as a smart contract developer to run your own node and then only query that node for data because now you're creating a highly centralized system so we are a tool of the smart contract developer we expose a set of capabilities that enable them to get off chain data into their smart contracts in a way that makes sense sometimes we compose those capabilities in a way that we want to showcase but that doesn't mean that's how you have to use it any other questions great questions please come by the chain link booth and ask some more thanks guys
Automatic transcript — names and jargon may be misspelled.