New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

ETHParis: Chainlink - How to connect your smart contract to external data

ETHGlobalWed, Oct 9, 2019, 12:00 AM

ETHParis workshop: "Chainlink: How to connect your smart contract to external data." Chainlink explains how to connect smart contracts to off-chain data, APIs and traditional payments to developers and hackers at ETHParis. ETHParis was an ethereum focused hackathon that took place in Paris, France as part of the 2019 ETHGlobal series of ethereum focused hackathons. March 9, 2019 at 42, the coding school in Paris, France.

Transcript

good evening everyone so I'm Johnny and I am an engineer for chain-linked my focus really is on operations so really around the scalability how easy it is to operate the monitoring and really the ease of use of operation of chain link decentralized oracle network and so it's specifically for connecting your contracts for external data feeds so to get started I'll be going over a intro to chain link for anyone who's not that familiar sample problem so why channeling would be useful in a specific situation an implementation wall through which I would recommend everyone to join into if you've got your laptop's at the ready won't be that hard a live demo and question and answers after that so in order to understand chain link must first really understand that contracts are not able to connect to external their for anyone who is who has worked insulator and has been building contracts you'll know you cannot just call an external API if you want to get external data in if you want to call a JSON API so op APR you want to connect to a database really anything off chain radius or start you'd want to pull you in on Unchained to use as a condition in your smart contract you can't do it so really is the main problem watch and link is trying to solve it's a big limiting factor a smart contract adoption I we truly believe that small contracts with without a reliable data feed and without being able to connect to off chain data sources are not feasible well not really you know the limited to just talkin transactions like if anyone's seen you know if you've on a theorem or used aetherium most of the time that you use a theorem is mostly for gambling apps for decentralized exchanges there's not really any real use case what you can do we know we believe that is because you cannot connect your external contracts your contracts or external data feeds so we're focused on being able to connect contracts to external data feeds for anyone who's built anything with web I API developer you'll understand there are thousands and thousands of API is out there what will do a million different things for you they'll give you different day or whether that will be for the weather price they're stopped there are like anything really there's any API for it so generally is all about being able to connect your contracts to those external data feeds gets ahead one and as well as that a big issue with adopting smart contracts in general is not being able to connect typical payment providers like if you want to send someone you know actual fiat money whether that is USD the pound euro whatever you cannot do that currently in a smart contract you have to use some form of talk and whether that's died or any other sort of like stable kind but then you've still got to be able to get that off and it's not really usable well not really user-friendly anyway for anyone who's not really words with crypto so chin link is also allowing people to connect their contracts to payment gateways I a pal for example so you can actually trigger real payments from the events of a small contract pretty key and well as that Jen link will also support being able to connect two different networks so for example if you've got an aetherium small contract and you've got some conditions in there and out of the back of the conditions you want to trigger a transaction on Bitcoin to send someone you know some money stun say if you've got an insurance contract then channeling will allow you to do the main way it does that is something called external adapters a chain link is very extendable as the notation of external adapters which are like little micro-services I like to think of them as like API proxies so for example any API one needs credentials it's not really JSON it needs some some form of converting to to be JSON like a saw API you can build them on top of chain link it's really simple they can be done in any language like a lot of the time if anyone's familiar with AWS like we run a lot of adapters in lambda so it's just like any API proxy you give it a key and it'll call the API and then chain link will return that they're back on chains who yeah the beauty about external adapters is that you don't really need any watching knowledge at all like if you've developed to an API before and you you know if you're familiar in Java go Nord whatever just build your external adapter in the language you prefer and as long as it returns a specific JSON payload back like you find so to get a bit like a bigger picture of chain link it is a decentralized oracle network and what we mean by that is that you you aren't relying on one party to get the data for you like you know a lot of the alternate solutions are specifically relying on central part is they might provide proof but in terms of like availability and reliability potential for downtime for you not to be able to get the data in your contract to break goes against the for example with chain-link rather than saying like the example i'll be going over is to get the etherium price so for example in this sense you could say right I won six chain link nodes to get me the price of aetherium from all dayit sources could be four different exchanges wherever you want to get the prize from all the Chairman knows go I will get that data though you've got six nodes there my you know the six nodes might be calling different api's or then when all the six nodes come back then they all aggregate that data and then reply back on chain with idea I mean in terms of reliability you've all you've always got the failover if one of one two three of them nodes are down you're always gonna have inaud you always gone enough an old fashioned that data if one of the api's is down by over nodes are using different api's so it's it's a way of really trust minimizing the the retrieval exit of external data onto the block based on this example like for example you get the theorem price it's someone like a salary contract for example you say I want to pay person I want to pay Bob $50 I want to pay in a theorem so you just get the price of aetherium right it's on that rate then you convert how much your theorem you're gonna send to Bob and then just send that or without the reliable data feed then you wouldn't be able to get the price of the theorem and send Bobby's mother exam so to go into more detail with a sample problem like got a small contract knows it knows its market price it can make crypto payments based on the price in fear and requires escrow or deposits based on that price so good example right you've got Alice and Bob Alice has a website Bob is contracted to do SEO for that website because Alice wants her website at the top of Google standard sort of I see our agreement and if Bob does his job right then Bob's going to get ed 50 dollars worth of a theory oh we want to do all of this on Shane so for example if you think about that practically you'd need to get rise of aetherium you need to get the ranking of that website right where it is uncool are using an API so and the criteria and the terms of the contract is basically check the ranking of Alice's site if the value is less than 10 yet the current price of etherium and pay bob $50 worth of etherium if you're thinking in in terms of like smart contracts and like if he was building night in slitter like it's pretty simple but the key you know the key piece of the puzzle are you missing in this sense is being able to connect to external debt feeds and get the the ranking of Alice's site under price so Alice in this situation a leash would first send some aetherium to the small contract think of this is escrow so based if Bob does his job right then is some aetherium in the contracts bob says he's done his job right Alice goes to trigger the contracts and then you would once Alice triggers that contract then the etherium contract would make a request to chain link chain link would use multiple data sources it would check the rank in it get the price and then start feeding that back into the contract well the view of this is is that you're not relying on a single source of truth you are getting your data from multiple endpoints you're using multiple exchanges more pellagra gears so in the happy path if you think about this contract as obviously the situations where Bob don't really do his job right and the ranking hasn't really gone up that much well in the happy path once Alice triggers a transaction everything comes back okay you know chair links called the SEO ranking the the ranking is gone higher up it's less than 10 he's got the price of etherium and then we'll figure the transaction send Bobby's money and number and send the right amount based on the prices for you enough of the sample problem so ways to implement the laptops open they're interesting it reads to get yourself ready now so I'm going to go through the steps yes to do this yourself so I've been talking a lot about the price of etherium this basic example will get the price I'm not sure and at the end I'll show a demo of that doing it on chair as well where you can go along so there's two ways if you want to use chain link easiest way is like for anyone who's done contracts is just using a web IDE however that being remix or super box know like if using remakes you don't have to sink anything don't really have to set up a local environment yeah it's good for beginners for anyone who likes working in Zeppelin OS or truffle you can use it yeah I yep it's good for that like I were recently doing some buy some stress testing which healing can I've got like a truffle script and it just like it synchronously fires like a ton of requests like to chair link and where some bill and it's all done in truffles yeah if you just we will be focusing on just on remix today really simple so I would load the workshop edger and we've not got when you load the page you'll see like he's different events if you scroll to the bottom you'll see Eve Denver really that's the section we're going to go over but yeah this is the only link really you need to type in everything's at the bottom under Eve Denver this I'll just go through the steps as well so for this example we're going to be using Robster the example also utilizes ENS so for example our journaling contracts and our channel ignored savvy NS addresses and our contracts when they talk the chilli knows use the ENS address to resolve the etherium addresses and requests so first if you've not gotten that mask installed I get madam asked any browser get some Robson etherium you've not got any already and get some Rob stand link as well because you'll need some link to be able to film the Oracle to serve your request just I'll skip over but if once the previous slides are anything just let me know oh to make this easier for yourself you want to add a link talkin onto your muscular op stone you can use the NS address for that if you had a custom talking in mask it's slightly less address should resolve and then you get the talk and just up done and once you won the force it and put in your Robson address and once it's confirmed you'll see the link new Butlins and then once you've got that and you've got some etherium you're pretty much ready to go people alright we remix and stuff do let's get going if you're if you're not doing this workshop don't worry because I'm gonna do it at the end but good for you to follow through well when you get to remix make sure you change your compiler version to non point four point two for the source the flat file sauce we're going to be linking to is no point to it won't build unless you select that compiler version at the bottom of the workshop page there should be a link to a solidify you should see a contract link at the bottom if not you can I mean it's a lots of Type R if you're just doing this from the side but it's on the bottom of that workshop page everyone if anyone's following along you alright you good good yep what's it what's that sorry yep so once you've got that contrived luck contract up paste it into remix simple contract is so big if it looks a bit overwhelming it's just cuz it's a flat contract so we've got all the dependencies in there for you so you don't have to mess around with copy and paste and all the dependence isn't what you doing so just again make sure you're on the right compiler version and quick starts compile if or compile isn't enabled and if always good you should see the right inside all green yeah yeah okay yeah sue yeah switch the run tab so you want to actually deploy the contract to Rob's turn now and make sure you select the erupts in consumer contracts I think it pretty much selects it by default but you might you may go one of the different dependency contracts make sure it's that contract and deploy it it's Rob's turn it might take a little while especially if loads of people are sending contract deployment transactions at the minute yep yes if um if I go back to discuss it's a long link if he goes to the workshop age or just Google like channeling Doc's and this page you'll be on there like the drop-down yeah good good to leave Denver one yeah yeah not the top one cuz the contracts a little bit different if I through you find it alright very bottom ember one of a link to the air to the right contract file be a slightly different one at the very bottom of the workshop page and grief Denver no worries yep so once you wish you've got the contract deployed good you know you've got the air bold symbol to copy the address you want to send some link to it if you're going meta mask and if you've got some rocks then link and just send my a couple of link to that it it uses one link per transaction so sound like three or four not really that much and no reef if I'm going a bit too fast I'm just thinking I need to do a live demo at the end I don't mind going through this way anyone well yeah the the contract you've deployed needs link because when you create an Oracle request when you call share link it creates that request by sending a link token and the link token is of ERC six six seven which is basic I two to three if anyone knows okay I'll see numbers but a tiny bit different and so basically is a transfer and call where it encapsulates data within the request and that darian capture Allah is the parameters of the of the Oracle requests it tells the channeling node what it's going to do if if you've got through okay and you should see the function what's after it's been deployed for requester for you in price and and the sets for this are on the workshop linkers well if you got Ansel I near the bottom it's all give you that job ID it's a copper USD so we are getting the etherium price in USD to give a little information around the job ID it's if you create a job on a channeling node like it tells it what to do okay it'll be a hedge TT you beget then convert the value to like you int 256 and then write your buck on chin the job ID is the primary key for that job journaling not if you do go to send the transaction and you see that arrow pop-up it's because you've not got any links into the contract so if you did do that then your contract is just made a request to a chain link not when the channeling node is notified when the transaction is confirmed it will trigger the event log which will then kick the chain link node into gear and it's a covert the Empire conveyed the right value in them right back on it so this and if you have done that and you following through and if you click that price on there you'll see price and through your contract and that's that's good so I will show you this now he want to just show off sure the actual the contracts off a little bit more people are not Saluda though this contract imports what we called the chain-linked contract oh you'll see the erupts in consumer is it inherits the chain-linked contract and then it inherits the Honorable just or withdrawing so consult with it as the NS addresses you can see in the constructor is setting up channeling with ENS and then there's request price methods so just to run through that a little bit it's creating a new channel request of the job ID this just passing that in and creating a new channel request that request it's just add in a you are standard URL and then it's creating a array just for JSON parsing so for example array just tells it what value to actually ask in the Jason when he gets the response bytes arrived back on and just like a multiplayer value and then the actual channeling request called well even so I run this earlier and it reported that the etherion price was $137 0.5 so if I run this again what you mean by unique sorry oh it's always the same so copy and paste it from that workshop document so that job ID points to what we call a job on the node and all that job is is literally just a bit of Jess and where it says like I want to do HTTP GET json.parse f you in 256 conversion multiply it and then write it back on share like if you see the Jason spec it's pretty simple it's just like what we call core adapters and then they're just written out as like types it's just like tasks in the job hey let's not move much may change like 15 cent but yeah just an example there and in this contract as well there is it's like request etherion price which gets the latest price of etherium pretty simple request the daily change it's it's all using the same API just like a simple example just different end points and the last market where he got that value from you like this is the one I called earlier for for like the change in a day so the reason like you see it being a larger value like that is because obviously it's not floating point precision precision in its Lydian aetherium so what it does is just multiply the value and then if you wanted to use overall you then you can divide it by you know whatever it's multiplied by just so we q5 the decimal points and you get actual accuracy when you you're getting the volume questions it's on the workshop pages well on the documentation oh yeah so it's just like Rob stand up cheering don't link and you go on that page it'll ask you for your address and you just still send you some link right I mean yeah you know it gets saved in in the same contract so you'll see like there I'm just calling some instance variables on the contract and like you'll see the breach request method there's also what we call a full fulfillment method yeah yeah yeah so for example if you want to you know call a different API or get different there then deploy your own contracts all you have to do to the work with chain link is just implement our chain linked contracts and then you'll get all the methods to be able to create Cheerilee requests we we have contracts what we will maintain just in the future for like the decentralization they're not owned by anyone it's just contracts what like create different objects for managing different things or all you do is I we have an NPM repository just install it I import the contract which like the channelings contract yeah yes yep what that is yeah yeah yeah you can design your contracts in a way where people can just get the last price so for example on fulfillment it stores the price to stick but like for example you could rather than just store in one price you could store the timestamp on the price and then people using your contract can get the price check the timestamp see if it was you know in their parameters whether it was like 10 30 minutes ago or two minutes ago for example like speaking yes yes worth mention in the bouncer so we are holding a bouncer the the best person who uses share link in the best way you'll get $1,000 worth of link token [Applause]

Automatic transcript — names and jargon may be misspelled.