motor cycle goes through chainlink overpass 6 17 2018 teeka chainlink 77 smart contract use cases enabled by chainlink Sponsor workshop: Chainlink Polygon Primer Workshop 05
im just going to share my screen can you see that okay yeah it looks great awesome cool hi everyone um my names harry and im from chaining labs and today im going to talk to you about oracles decentralized data and external computation now what were going to do is were going to just quickly go over the polygon grants hackathon first then well talk about smart contracts and cryptographic truth and then well talk about what is the oracle problem and then well dive into some topics around d5 and price feeds using chaining vrf um reaching out to any api from your smart contract and then well speak about where you can go to to learn more and well finish things off with a couple of demos so polygon grants were super excited to be here as uh to be part of this hackathon were big fans of polygon as you guys have probably already seen we love the easy onboarding experience it has for developers um you know for solidity smart contract developers we love that it offers them a fast low-cost scalable evm sidechain that they can use for building smart contracts and decentralized applications right so this is why we have price feeds while we have vrf and while we have api calls live on polygon um on the mainner and on the mumbai test net as well so based on all of this were contributing five prizes of one thousand dollars in link to the five best projects that use chain link in some way or form in their project so what well do now is well go to the um github issue thats been created for this so i am in the chain link github repo here at smart contract kit and in the chain link repository if you go to issues you can see polygon grants hackathon bounty so five prizes of one thousand dollars in link to be given out to the best five projects that use chain link so what you need to do is you just need to build something that uses chain link as part of this hackathon and it just needs to use either price feeds uh chaining vrf or any api and there needs to be a state change on the blockchain as a result of using one of those solutions right so thats the submission requirements pretty pretty simple stuff some of the things well be looking for you can see down here and theres some you know submission deadlines and things like that so if you create a projects a project sorry in as part of the hackathon and you want to apply for this bounty what you should do is you should come to this issue you should let it be known um that youre going to be working towards receiving one of the bounties post a link to your project etc so that we have visibility on it and then at the end well kind of see what the best five projects are okay so that is the uh github issue lets move on now so lets start off by talking about digital agreements so today our lives are underpinned by all these agreements that we have in place right we have agreements with our bank you have one with uh netflix if you have netflix you have one with your social media um accounts as well right and and these agreements we we call them just trust us paper promises and the reason we call them these things is because theres no real guarantee um theres no real firm commitment or guarantee that the companies and institutions that we have these agreements with um that theyre actually gonna you know live up to their end of the agreement right that theres no guarantee um its basically a promise made on paper no firm commitment other than um a choice or desire to fulfill the agreement and everyones used to the world working in this way for so long you know we dont really question that and we dont really think that theres an alternative but the fascinating thing is that in 2009 we finally had an alternative to these just trust us paper promises in the form of bitcoin and since then its evolved into more complex blockchains that make use of what we call smart contracts right now a smart contract is not smart and its not really a contract either we prefer to call them highly secure tamper-proof digital agreements a bit more of a long-winded name there but its a better description so the difference between the traditional just trust us agreements that we um we have today and smart contracts is smart contracts run on decentralized infrastructure like a blockchain and they enable us to rethink and change the way in which we execute and enforce our agreements so the big shift is that the contract execution and enforcement is done by this completely separate decentralized infrastructure thats got nothing to do with the you know participants in the agreement so um these smart contracts are more advanced versions of what we call cryptographic truth right and cryptographic truth is the ability to guarantee an outcome based on maths cryptography and physics right so what you see in this diagram here is a spectrum of all the agreements that exist today and on one side you have the just trust dust paper promises of today that i was talking about um where theres some document whether its electronic or paper and theres some people and you know they might do something or they might not and on the other end you have cryptographic truth which relies purely on maths physics and cryptography and and this is kind of involved into more advanced versions um in the form of things such as d fire and hybrid smart contracts which ill go through later on so so heres an example of a recent just trust dust paper promise guarantee um that kind of went went wrong right so robin hood is a tradify product you know a lot of people know about it users can sign up and trade stocks and all those things right so you think great cool ill sign up ill trade but then um robinhood says whoops sorry guys uh we cant let you trade anymore because the people making money um the people that are meant to be making money arent actually making money anymore so sorry were just gonna prevent you from trading um and thats kind of what happened in this scenario right its a its an example of a just trust us paper promise uh where the company didnt live up to their end of the agreement and and they could stop it if they wanted to and they did and you know kind of users werent happy about it so there was nothing forcing them to deliver on their promise other than their desire you know and they didnt want to and they didnt so as you can see you know smart contracts or which are which is you know cryptographic truth as i mentioned earlier theyre strictly superior digital agreements to these just trust us um the mod the just trust us model that we have today right its strictly superior and ill give you five reasons why so number one security um because its right these contracts are on this decentralized infrastructure they cant be hacked modified gained coerced blackmail bribed anything like that right theyre highly tamper proof two reliable guaranteed execution so once again because the smart contracts are running on decentralized infrastructure and you have guaranteed execution right its going to take a um worldwide power outage or internet outage to kind of stop a highly decentralized blockchain from executing a smart contract three transparency so in a normal digital agreement um transparency is usually opaque and hidden away which led to things such as the financial crisis last decade but in a smart contract scenario transparency is unavoidably built into the smart contract right with blockchain technology four trust minimization because the smart contract is running on this decentralized infrastructure the participants in the digital agreements dont necessarily need to trust each other right because um they have the decentralized blockchain running the smart contracts the the users of robinhood for example you know they dont need to worry that um robinhood wont allow them access to the platform right unless its codified into the agreement uh and five efficiencies so all of these things that i discussed security guaranteed execution transparency trust minimization um we can kind of use these things to create more efficient automated processes that can save businesses money um so in the end basically trust is an expensive thing to to have right so i just want to summarize this section to by saying that cryptographic truth and smart contracts are strictly better solution than this just trust us model that we have today right theres no person somewhere that decides what happens theres maths theres cryptography and theres physics and as long as these three things continue to work in the way they do today which is one of the biggest guarantees youll get in the world i think and youre going to get the expected behavior and outcome from your agreement so instead of having the possibility of something will happen you have a hundred percent assurance that it will happen so now that we know why smart contracts are so awesome compared to the traditional agreements that we have in place today lets talk about their biggest limitation smart contracts are not able to connect to external data or any off chain resources on their own so as a developer you might ask well why cant a smart contract just make an api call right its just a program after all and the answer to that is everything on the blockchain is deterministic right and if we have an api call as part of a smart contract for example what happens if some nodes get one answer and other nodes get another answer what happens if the api call times out and some get no response um that then the the blockchain isnt going to be able to reach consensus on what the state of the smart contract is and and basically will become broken right so we need to maintain that determinism so if making that api call is part of the validation and then each node can kind of get these different results so this is defined as a smart contract connectivity problem not being able to connect to external data systems and events and it actually limits smart contracts to purely things that can be done on chain right such as moving tokens around and things like that so to interact with the outside world we need whats called an oracle right and an oracle is any device that interacts with the off chain world to provide data or connectivity to a smart contract so the benefit of this is the oracle can basically tell the smart contract what the api call is or whatever off chain computation being done the the result of it is and this way that can be used as an input to the smart contract that every node in the blockchain has and that way they all have the same input and they can all continue um executing a smart contract in exactly the same way and we keep that determinism going that i discussed earlier so heres where things get really interesting though using a centralized oracle like i described earlier um can actually create a single point of failure for smart contracts and and can compromise the overall security of the entire digital agreement the reason for this is if youve got a highly secured decentralized blockchain you know but then youre using a single oracle to get data from a single data source the end-to-end security of your system is no better than your weakest link right and in this case its that single oracle feeding date into the contract if youre a hacker trying to influence that contract youre not going to try to hack the the smart contract on the blockchain because you cant as i described earlier however if you can somehow influence that single oracle feeding the data in then you can actually gain the outcome of the smart contract so so how do we get around this problem the answer to this is with a decentralized oracle network so this is what um chain link is designed to be a modular flexible decentralized oracle network for getting uh secure and reliable data on chain or for triggering external computation so what we do is we we bring in or trigger the external computation in a decentralized way and by doing this we kind of extend the decentralization and trust minimization properties of the blockchain and we apply it out to the data source and data delivery layer so we get an overall superior um and more secure solution so if thats a little bit confusing to you theres a good diagram here to try out wrap your head around it visually so here we have a number of chaining nodes all oracles all fetching data from different data sources as you can see there are slightly different prices there and what they do is they come to a consensus on an average value or they aggregate the results and then they feed that single result on chain to the smart contract so the thing to note here is no single oracle here can directly influence this final result in any meaningful way and it would take a sufficient number of malicious actors or oracles in this case to to kind of gain that result by a significant amount so um by combining on-chain smart contract code with these kind of off-chain resources like oracles you actually create what we call hybrid smart contracts right so smart contract a lot of people think of them as just on chain smart contract code but weve actually redefined kind of what a smart contract is in that were saying a hybrid smart contract is a combination of on-chain smart contract code and off chain resources such as oracles all working together um in in a single solution here right so you can kind of think of them as like a supercharged version of a normal smart contract and were already seeing these um today in the form of define insurance and other things and and theyll go on to redefine what our industry is um you know uh known for so heres an example of a hybrid smart contract in in the form of parametric crop insurance um live today actually so we have on-chain smart contract code here um evaluating rainfall and temperature and things like that then we have multiple chaining nodes getting data from multiple sources so we have rainfall temperature and you know other metrics as well so all of those things working together is what we call hybrid smart contract cool so now that weve gone through what chain link is and its value proposition lets talk about chaining data feeds and decentralized finance so going back to the traditional digital agreements that i was discussing earlier um and and for example that robin hood example that i went through the the trad fire example um you know people are sick of things like this happening right and and people are going to slowly want to seek alternatives and and blockchain and smart contracts are the perfect alternative so d5 or decentralized finance is taking any existing financial product or instrument available today and putting it on a blockchain running on smart contracts um and doing it in this kind of peer-to-peer fashion right thats what d5 is so you can do lending and borrowing deal with derivatives insurance and all those types of things um right and thats kind of a very different way for the financial world to work compared to how it works today so for example in the robin hood example how does d5 work right so in d5 you have a private key you have smart contract code running on a blockchain as long as you hold your private key no other institution whether its robin hood or anyone else is going to prevent you from accessing your assets right its guaranteed you have that cryptographic guarantee as long as a smart contract code um executes in the way it was designed which we know it will because it runs on a blockchain then and youre going to get the expected outcome and behavior um from your d5 protocol right its guaranteed we have that cryptographic truth so never before in the history of financial digital agreements have we had this level of guarantee right one that purely depends on maths cryptography and physics so as i explained earlier though you cant um just get data from a single data source if you have a a decentralized protocol so in this case a d5 protocol you dont want to be getting price data from a single data source or a single api so this is where you need to use multiple data sources you need to use multiple oracles you need to come to a consensus on the data you need to aggregate it you need to make sure that the result cant be flash loan attack you need to make sure that its consistently posted on chain in a secure way even when gas prices spike to you know 2500 or whatever it is um on other networks um i know on polygon we dont have that issue as much but um this is kind of what our price feeds solve is they give developers on chain highly secure high quality data in this kind of decentralized manner so um these price fees have gone on and theyve really helped to accelerate d5 into what its known today for and this is where we serve some of the largest lending derivatives and insurance protocols um our price fees actually power the majority of d5 today and this is why a lot of defy uses us and also why a lot of new d5 protocols coming online um automatically integrate to us right because they want secure and they want high quality reliable price data so if you head over to data.chain.link you can see some of the feeds that we have available so ill just have a look now so im on the polygon mainnet here so we can see some of the data feeds that are available here ill just go into the ethersd one you can kind of see theres a trusted answer we have multiple oracles giving results and we have a deviation threshold which says what the how how much the price can deviate for a result needs to be kind of triggered um i think that needs to be updated so everythings um visible um publicly you can see all the responses that each oracle sends its all kind of transparent so as i said before we support quite a number of large d5 protocols on various chains including polygon as you can see we we we support ave set protocol sushi swap you know decentralized exchanges and and also protocols like synthetics as well um but d5 is still a very small part of crypto its less than five percent in terms of total value locked up we actually see this as kind of increasing quite a lot over the coming years we think it could approach half of what the crypto market cap is and thats why we we need to focus on building hyper reliable systems we need hyper reliable oracles hyper reliable price data needs to be of the highest quality and we need to really make sure that we build the systems in the most secure way possible so thats enough about define and price feeds now lets talk about vrf so chain link is more than just price feeds you know changing provides the ability to do off-chain computation as well right because you know doing computation on chain sometimes isnt ideal because you can get expensive or it can take a long time so one of the more pressing needs for off chain computation was to implement a a random number generator right so random numbers have actually been used for thousands of years whether its you know flipping a coin or rolling a dice you know the basically you just want a random result right so implementing random numbers on a computer is kind of a similar thing its a similar scenario and um what weve seen is having a true source of randomness on chain is is something that were seeing um more and more sought after as time goes on but until now getting random numbers on chain has been kind of problematic because you need to either a use an external api and and this is a especially an issue with random numbers because how do you know the result that you get back isnt um a malicious result um that someone wants to export your smart contract with right um or b some people have used on-chain data and values as a source of randomness as well and then this also has its risks because like i said before the blockchain is deterministic miners and malicious actors can have a look at your smart contract and can almost pre-meditate what a random number might be in a given instant and then they can possibly submit a transaction and try and front run you and things like that so not ideal solutions um uh up until now so what chaining vrf does is it provides a solution to generate a provably random number right so what does this mean it basically means two things it means a um you know that the random number was generated by that chain link oracle and and no one else because they sign the transaction with their private key and b we actually have cryptographic truth that the random number was generated with the seed that was given when the vrf request was made so when you make a vrf request a seed is generated which is basically a source of uh entropy for a random number i think its a combination of um the chaining nodes public key address and the block cache submitting a request or something but that gets stored on the smart contract and when the vrf response comes back and you get a random number we can actually verify it using cryptography that it was created based on that initial seed right so that you know its not just some random number thats come in and that someone else has kind of specifically put in to try and gain your contract its one that actually came as a result of that seed so thats kind of the how the magic in vrf works so um vrf provides probably fair outcome in things such as games gaming is a huge use case for for random numbers here uh and as we can see in in the blockchain and crypto space gaming is becoming bigger and bigger as well right and theres plenty of interesting use cases for using vrf in gaming uh one of the more popular one is minting nfts with provably random traits so ava gotchi is a personal favorite of mine here as you can see um theyre live on polygon actually i think and and they use channeling to mean avogad cheese with provably random traits so another great example of using vrf with nfts is with them pokemon booster packs here and theyre also using vrf to generate provably random species and traits for the minted nfts if youre interested in doing some kind of nft slash um vrf uh project check out um patrick collins from the devrel team has just released an awesome video here titled how to make nftr on chain with on-chain metadata so if you search for patrick collins youll see it he uses um a hard hat to do it he uses chain link and he does it on polygon and he actually submits them to openc as well so definitely recommend checking this one out and maybe i will add the link in the youtube video after so one final example of using vrf in blockchain based games is to actually use it to determine provably random and fair game logic as well in your blockchain based games so in a fighting example here where youve got an attacker and theyre either going to hit or miss you can use vrf to determine whether they should hit or miss in this case so another popular use case so lets close things off now in the presentation part of this workshop by discussing how you can access any api using chain link so a chain link can actually be used to integrate to any api whether its like a public http get api could be some kind of private web api enterprise database iot sensor you name it if theres an api you can connect your smart contract running on polygon to the api using chain link so the way it works is its a bit of a request and response kind of model where a smart contract will make a request to a specific chaining node or nodes and say hey i want to reach out to this api the chaining node will take that request it will fulfill the request and then it will send the response back and then the smart contract kind of gets a response back in in another transaction so theres two kind of paths you can take with making api calls if your api call is just a normal http get or post request then you can just use what we call the core adapters to do that and then you can basically just find a node or a number of nodes if you want to use multiple sources and aggregate them and things like that and you can say you can find a node thats running a job thats suitable for you and then you can just insert that into your smart contract which well go through a demo in a minute if youre trying to do something a little bit more technical and custom for example you want to connect to like a postgres database or something you might need to create whats called an external adapter right so an external adapter is what gives chaining the ability to connect to any api thats kind of not standard and an external adapter is basically its basically an api in itself with a specific input and output json structure and and the way it works is chaining nodes then use that external adapter to reach out to other apis and then um the results kind of get posted back to the chaining node which then gets sent back to the smart contract i know its a little bit um technical however just know that if you want to just do a normal api call like a http get or post you can go to market.link here and then we have matic mainnet and testnet here you can see a whole number of uh chaining jobs for fulfilling um just general uh requests so if you just want to do a http get and you want a uh an integer return also an integer heres an example of a job you can use and well go through a demo of this in a minute if you want to create an api and do something really custom definitely recommend at the end of the presentation well go through some resources where you can learn how to do stuff like that so weve been through market.link um its a great source for for looking for jobs to basically um if you want to reach out to an api or if you want to search for other external adapters as well you can kind of look on here and i think thats it for apis yes so lets finish up by going where can you go to learn more information now so the best place to go first is the docs at docs.chain.link this is no thats not the docs heres the docs here so docs.chain.link weve got some really cool tutorials basics random numbers api calls theyre their oevm base so you can run them in polygon as well theres code examples here that you can literally um deploy in straight into remix and execute in addition to this we have really good docs for using vrf api calls and and price feeds here well get well go through these in a minute and we have a really good hackathon resources page too if youre looking for certain resources definitely check this out as well another good place to check out is our blog at blog.chain.link weve got some really cool technical articles there in a special developers section theres some polygon specific ones as well such as you know deploying a how to get a random number on polygon for example with step-by-step um code instructions and examples and things like that if youre looking for some inspiration on a use case for smart contracts for your hackathon submission we have a great article at blog.chain.link called 77 smart contract use cases enabled by chain link and it goes through various categories that you can kind of look through for inspiration for your submissions such as d5 gaming insurance nfts supply chain and more so recommend checking that out if you want some inspiration and we have a really good youtube channel as well if you go to youtube and you search for chain link engineering tutorials we have a playlist where weve bundled all of our technical content together theres plenty of stuff a lot of it is evm based so its it applies for polygon as well and i think weve actually got some polygon specific things there too if you have a look and finally we have um what we call our starter kits so these are boilerplate projects for using chain link um in your project and and we have one for truffle hard hat um and for brownie as well and i think im actually going to go through one example if i have time but for now that is all for the presentation so if you want to learn more if you want to reach out we have a specific channel in the polygon discord and the channel is called sponsor chain link so the devrel team will be watching that well be supporting you with anything you need in regards to using chain link in your project so you can reach out to us there or you can reach out to us on the chaining discord as well theres some technical channels there that were always monitoring um if you have a specific error or issue you can and post a question on stack overflow and tag chain link we we monitor that as well well respond and yeah once again definitely check out our docs so that is it for the regular presentation part what im going to do now is go through some demos and show you how easy it really is so the first thing you need to do is make sure for the first demos were just going to use remix because its online its easy its got a nice gui and then hopefully ill do a hard hat example first thing you want to do is make sure you are connected to the polygon mumbai testnet here and you can get details from docs.magic.network in the network section here if you need to add this network to your metamask you can you can do so with these instructions here once youve done that you want to make sure that youve got a little bit of matic um youre going to need that obviously for the form of gas and youre also going to need some link as well right so if you head to fawcett.matic.network you can grab some free testnet matic and link as well you just put your metamask address here hit submit and then youll kind of get some sent to you for free so once you have that in your wallet youre youre good to go so the first thing were going to do is were going to do a price fees example so in the docs at docs.chain.link im going to go get the latest price evm as you can see theres a code snippet here im going to literally just hit the deploy this contract using remix button here and were going to open it up hopefully thats big enough for you guys to see so i just quickly go through the consumer contract here so were using a training library here and what were doing is were creating a new instance of the aggregator v3 um here and were specifying a contract address and ill get to that in a minute and then all we have is we have a single function that just calls the latest round data function from this price feed thing here so and then were returning the the latest price so what this is is its the contract of the price fee that we want to consume so uh in this example here we can see all the various price pairs available if you head to the chaining docks in the using price feed section and go to contract addresses polygon you can see all of the price feed addresses here so if we go down to the mumbai test net we have a few on the test net as well were going to say we want to use the eth usd price feed so we want to get the latest price from from that price feed running on mumbai test so were going to plug that value in there then we would compile the smart contract and then we are going to deploy it using metamask make sure youve got the correct contract selected there you hit deploy you confirm the transaction there we go once thats deployed uh hopefully you guys can see that once we hit get latest price we can see that we get the the price of ethereum here so it grabbed the latest price from the um from the contract here for the ethiosd price feed running on mumbai test net so we now have um highly high quality and secure price data in our smart contract and you can use it for whatever you need right so thats how easy it is to get price data using chaining price feeds on polygon its literally just a few lines of code so yeah very easy so thats the first example lets go back to the docs now and lets do a vrf request lets say you want a source of randomness on your smart contract so we go to get a random number once again we have a code snippet that were going to deploy using remix here make that a little bit smaller so this contract works a little bit differently first of all we need to were going to use link in in this request because um in this case were getting an oracle to basically do something off chain for us and then send the response so theyre going to need to pay some some gas in the form of matic etc so were going to need some link here but weve got some in our metamask wallet already once again if you havent got any head to the faucet choose link put your metamask address and hit submit but for now what were going to do is well go through the contract so the constructor will go through in a minute so basically the way this works is there are two functions theres a request function and a fulfill function so the request or get random number function is the one that reaches out and says to the oracle hey i need a random number and the oracle will receive the request and it will send a response back and it will make its way into this field randomness function which takes a random number as an input and were just kind of storing it on chain so thats kind of all were doing here really but theres a couple network specific configs that we need to set here so we have a vrf coordinator address here so this is a contract that lives on chain that coordinates all vrf requests for the vrf chain link node um in this case its deployed to the uh not the address actually well get the real address in a minute so theres a vrf coordinator address we have the address of the link token on the network as well which we need to set its obviously different depending on what network youre on we have the key hash this is the public key of the chaining node thats fulfilling the vrf requests because they sign the request with their private key and we actually um use this publicly known an um address to then you know verify everything and theres the fee in link thats payable as well so we need to set all of these four before we do our request the way to do that is in the docs in chain link you go to the contract addresses section in using randomness and if you scroll down to polygon mumbai test net youll see this is the address of the link token on polygon on mumbai sorry on polygon this is the address of the vrf coordinator contract running on the mumbai test net this is the public key hash of the chain link node and the fee in link payable is quite low obviously on polygon here um so were going to set that as well so once we have all of these values set we can compile our smart contract again and we can deploy it once again make sure you have the right smart contract selected and then we hit deploy and we wait for it to get deployed so once thats deployed we actually need to fund the contract with some link before we can submit a request if you try a request now youre going to get a failed transaction so what we do is we copy the random number consumer contract address and we go to our link token here and oh sorry ill explain adding the link token as well if you uh if you dont have the link token added in your metamask account you can go add token and you can grab the token contract address from here from the chaining docs contract addresses and you could just paste it in right so in my case its already been added so i cant do it but um do that and then you can kind of see it here so im going to copy the deployed contract address here im going to send a small amount of link 0.0001 and well wait for that to send and once thats sent we will then um call this get random number function again and this time hopefully its going to be successful for us cool thats successful so we hit get random number so while that executes it would take a few minutes you can go to the polygon mumbai blockchain explorer you can paste in your contract address here and you can kind of see all the transactions against your contract so we can see um this transaction was me funding the contract with a little bit of link and this is the request for randomness transaction that actually sent that link out to the vrf coordinator contract which then sends it to the chaining oracle so if i go back to the smart contract now and hit the random result you can kind of see um we have a really big random number there so we got a response successfully so if you have a response there it means that the verification was successful you have a verifiably random number that you can start doing things with um you can do all kinds of things once its on chain you can apply modulus to it if you want it to be you know between a certain number so between 100 etc the more you can chop it up or do whatever you need to so once again very easy to get randomness on chain using chaining vrf with just a few lines of code so the next demo that ill show you is using any api so if we go back to the docs again and we go to using any api here make a get request so once again we have a really good easy um boilerplate kind of code snippet that were going to play around with were going to open it in remix now this example is actually very similar to the vrf example in that we have a consumer contract that kind of uses some chaining libraries um and what this does is it as well it like the vrf example we have a request function that that requests something in this case its to reach out to an api and we have a fulfill function so this is the one that gets called when we get a response back so once again were setting a bunch of stuff in the constructor so in this case were setting four things the first thing we need to set is the address of the chaining token now in this case actually we need to update the docs here if you go to the matic docs here at docs dot matic.network and go to chain link you can see the any api example here theyre setting the address of the chaining token specifically here so were going to do the same so if i go back to remix im going to do that now we need to do uh find a job that can fulfill our request so you can go to chaining market here you can go to matic test net so if we wanted to we could grab this job id and the oracle contract and use it maybe well just use the example from the docs here but in our case were obtaining a unsigned integer so you could theoretically use any job that you find here in the matic test next section that does a get and then returns a an integer so well copy the oracle contract address as well and well paste that here and fee in this case um 0.01 link so well put that over here so well compile this one and theres a typo here uh the checksum failed the docks just need to be updated um there we go so we have the the proper oracle contract address there so thats all compiled now so were going to once again deploy it to the mumbai test net were going to make sure we have the correct contract set here and were going to hit deploy and while thats deploying ill just explain the the contract so what were doing is were connecting to this api here so its a public api that just gets a bunch of crypto market data as you can see its just a bunch of bunch of raw json here but what were doing is were building up a new chaining request were saying hey we want to do an api request using this job id that we obtained which is running on a specific node and when we get a response we want to call this we want you to call this fulfill function down here right so thats what this line says and then were appending some stuff to the request so were saying we want to do a http get to this api here and once thats done we want you to traverse this json path to find the value that were looking for so in this case its raw if usd volume 24 hour so raw efusd volume 24 hour this one here um thats what were looking for in the api call and once thats done we want to multiply the amount by 10 to the 18. so in the api its a decimal its a floating point number solidity cant handle floating point numbers this is why we multiply it out to kind of pad it out like that and once thats done then we submit the request to the oracle contract that we specified up here when we found the job to do to do a request and and we want to pay the specified fee as well so thats what that function does we have a deployed contract here i will fund it with enough link and then well try run that function so im going to send it 0.01 and then when we do execute the request um and the fulfill function gets called its just going to store the value that it gets from the api request so im now executing the request volume data function right now we dont have a result yet as you can see the volume is zero however if we just wait a few seconds for the chain link oracle to fulfill the request uh we should have a response so currently the volume is that number there six one eight six one uh if we go back to here we can see we get a result there so once again with just a few lines of code and using chain ink were able to successfully reach out to an api and grab data and then have that data available in our smart contract and we were able to use a specific job and oracle um running that that we can kind of reach out to and use to fulfill our request we didnt have to spin up our own training node to do it you can spin up your own chaining node if you want and check it out docs for how to do that however for these simple requests you can simply go to the chaining marker here at market.link search on matic test net and theres a bunch of jobs depending on what youre trying to do so once again very easy to do just a few lines of code so so there are three remix examples for using chain link in your smart contracts but weve got a few minutes left so im going to now show you our hard hat starter kit so if you go to github.com smart contract kit this is our repo youll see pinned at the top here are our three starter kits so the hard hat starter kit here is a pre-packaged hard hat boilerplate repository that contains all the smart contracts and code and scripts to use chain link in your project and its all in this easily um usable pre-packaged repository that you can then take things from copy modify do whatever you want so ive got a version that ive just pulled before here um as you can see there are the three smart contracts that we just went through the api consumer the price view consumer the vrf consumer theyre all here as well in in the same form that we just saw on the remix examples we have a bunch of deploy scripts for deploying them we have a bunch of tasks hard hat tasks for interacting with the smart contracts once theyre deployed and we have some config as well so in the hardhat config file we specify a mumbais default network here we have a specific entry for mumbai here that uses a specific rpc url and a private key here so in this example you need to create a dot env file and that dot env file needs to have your mumbai rpc url here so you can you can get one from the matic docs here in the network section i believe and then your private key so the the account that you have on metamask that you have many can link in you can export the private key from metamask and throw it in here just be careful you dont check this file into any public repository though um you dont want people um looking to see if you have mainnet funds or anything like that and in addition to that theres one more conflict thats been made to this hard hat project we have a specific entry in the helper hardhat config file and we have an entry from mumbai where we say this is the link token for mumbai this is the ethersd price feed for mumbai for using the price feed consumer and these are all the vrf kind of um values that we need and heres an example oracle and job id for doing an api call so um thats kind of it really all you need to do once you have this boilerplate repository downloaded and youve installed all the dependencies with yarn you just run mpx hard hat compile there we go thats all compiled and we run mpx hardhat deploy and what that will do is it will go through the deploy folder and deploy the three smart contracts that we just went through before and youll get some handy cli output here as well so um ill make that a bit smaller so once its deployed it literally gives you the output that you need to interact with the smart contracts using the tasks that i talked about earlier so for the price feeds contract there is a read price feed task and you just call it passing in the deployed contract address that we get from here and it will connect to the price feed consumer contract and and return the price of the ethersd price feed there so as you can see very easy and well do one more example lets do the random number consumer so were going to call the request random number task on our random number consumer contract here deployed running on mumbo i dont need to fund it with link here because the the starter key actually does whats called auto funding so you will check to see if you have enough link in your wallet and if you do when it deploys these vrf and api consumer contracts itll send them a little bit of link as well so that you dont have to do it yourself so im just going to call the request random number task which well call that request random number function in the smart contract then we can get as you can see we get some output here and it says run the following to read the returned random number so well give it a few seconds to fulfill the vrf request and ill call the read random number task on that contract now um and it will just call that um the the get a function for the random number and as you can see we get the random number returned here so as you can see its just another way to kind of use chain link in your projects you can grab this repo if youre going to use hard hat you can grab it you can copy stuff into your own project you can use this as a starting point and just cut things out as you need you can use the task and deployment scripts as kind of like templates for your own smart contracts its very flexible and and we highly recommend having a play around with it so that is all i have for the presentation uh i think im a couple minutes early um if anyone has any questions you can ask them now in the chat otherwise like i said before reach out to us in the polygon discord chat we will be monitoring that one the sponsor chain link channel specifically or reach out to us in the changing discord as well wed love to interact with you there too but for now thank you to the polygon and dora hacks team for having us were very excited to be here we cant wait to see what everyone builds thank you thank you very much for all the introductions i guess we have a few questions here and uh uh the first one i actually did this uh this guys asked two questions and i would just ask all in one uh so he want to know when uh as a student is the time to start writing the the like the device launch contract and when it is a good time to jump into defy industries yeah um in terms of the indeed fire industry itself um the sooner the better i say because um d5 is still very uh early on its kind of like a precursor to this huge change thats coming in the way that these digital agreements are done and um what weve seen so far has been amazing weve got all these amazing default protocols going however everythings still very early and we think theres going to be a lot of growth so if youre interested in that kind of thing highly recommend to to kind of jump in and start learning things um in your own time so if youre a student you know sometimes you just need to kind of work um when you kind of have some off time and kind of do your own study um i was entering hackathons myself um even as little as a year ago working full-time elsewhere and you know i was just kind of working in the evenings or in my own spare time or on the weekends kind of doing my own self-learning but yeah if d5 interests you theres no better time to jump in than today and the second question i remember you mentioned about the bounty program of chairing at the at the very beginning of that competition and could you like briefly introduce a little bit more about it sure so ill just share my screen again so um the best place to go like i said if you go to our smart contract hit repository and go to chain link issues and bounty the details are here so were going to be giving away five prizes of one thousand dollars in link to the five best projects that use chain link in some way or form and if you want to try and win one of those bounties um have a look at these criteria here so well look at things that are more things that are original well look at how technically challenging it is i will look to you know is it a practical is it something thats practical that people want to use um well look at how usable is it is it visually appealing um etc and and yeah any kind of wow factor um comes into play as well so um theres just a few more points on that and um you can use uh chaining api calls vrf um or price feeds in your project um you can use a combination of them if you want as well and just make sure that you um specifically comment here or get involved in this issue so that we are aware of your project and we can kind of consider it when it comes time for judging great um yeah and i i guess it will be the last questions and also it is from from myself uh because you mentioned about how chain link could interact with the mft and because im im a bit interested in the nft area and you know that the market of the nfc is going a bit crazy recently uh so i just want to know uh is there any like uh maybe further further imagination or further area that you think channeling could like uh get interacted with the nft yeah um i think definitely chain link can be used in a couple of ways with nfts um and and once again weve got some really good uh blogs on on this um the first way is uh using a source of randomness for for nfts so like i said um having random traits or um you know um ensuring you have provably random minting of nfts as well is is something quite big um and another one that you can a way in which you can use chain link with nfts is um you can have whats called dynamic nfts dynamic nft so these are nfts that are obviously dynamic and i think thats becoming something more and more interesting that people are looking into and weve got a really great blog post here if you just search for dynamic nft chain link youll find it and i think we even have a video on youtube as well so probably those two are the two ones that interest me the most but im sure that the more the nft space matures um the more well see innovations occur um within fts okay great uh and thank you very much for your time and uh effort today and also thank you for all the amazing questions from from uh from our listeners uh we i believe the whole sessions has been i guess super helpful for all of the audience today and guys definitely remember to check out the the bounty from channeling and we have uh in the future we have a series of workshops for our developed developers in the following days and tomorrow we will be welcoming professionals from equivalence block and figmas with us talking about how to scratch into the app and some other interesting topics and uh if you havent followed us on youtube and billy billy please make sure you do that so you wont miss any of the upcoming workshops and project demo sessions in the future and i hope all of you guys could do a very good job in the polygon grants hackathon and good luck and help happy building in the future and thank you for joining us today and thank you very much harry for sharing yeah thanks for having me and yeah look forward to seeing what everyone builds guys thank you you Theme: Oracles, Decentralized Data, and External ComputationSpeaker: Harry Papacharissiou, Developer Advocate @Chainlink Labs
movimientoantipiquetero.com.ar