movimientoantipiquetero.com.ar

chainlink vrf solanaChainlink Hackathon: Everything Chainlink


smartcontracts chainlink ico review chainlink x tron chainlink vrf solana Chainlink Hackathon: Everything Chainlink
chainlink vrf solana how to purchase chainlink Chainlink Hackathon: Everything Chainlink
hey everyone welcome back long time no see all right um well thanks for participating in the last one if you did and if youre new here welcome welcome to the demos um in the last demo we kind of built up to the basics of blockchain and smart contracts coded our first one we didnt actually use the technology just hackathon is all based around chain link so lets dive right into that introduction to chain link if you uh missed it in the last one uh im zach iash im developer advocate for the chain link protocol um all right so today were going to go through a couple of topics um were going to talk about the oracle problem and how chainlink solves it um and then were going to go over a couple of chain link products our services service offerings we have the chain link data feeds were going to be automating smart contracts with keepers accessing any api we want with uh wood chain link and then obtaining a verifiably random number using the chainlink vrf so lets jump right into it the oracle problem and chain link okay so after the last demo um you know we talked about smart contract math based agreements are awesome compared to our traditional brand-based digital agreements but it turns out that these smart contracts arent quite that smart at least on their own and their biggest limitation is smart contracts are not able to connect to external data or the outside world outside the blockchain so why cant a blockchain just connect to an api you know outside data source um well remember in the timber before we were talking about how blockchains you know they all have this copy of all the blocks in the blockchain and have to come to agreement on what the real uh blockchain is this is called consensus and because of this consensus and the programmability of it all they have to be deterministic so this this ensures that everyones able to come to agreement on what the true blockchain is um and if we made an api call uh then each node could get different results so lets look at this image real quick um on the left side we have the good uh nice deterministic blockchain as we know today maybe its just gonna calculate a value one plus one all the computers know how to calculate one plus one they all calculate them the same it can easily reach agreement on the right side we have uh this non-deterministic blockchain that is uh connecting to the outside world and uh by blockchain you know these are the nodes these are the peers these are the people running the blockchain software and um so this peer over here theyre trying to um call an api and maybe its an api thats like you know the weather in charlotte thats where i live um and so it gets 76 degrees fahrenheit this node calls the same api and gets 75 degrees fahrenheit you know just a second later maybe maybe the reading on the server change well now they cant reach consensus this is why we cant just connect a blockchain to apis or outside data sources it would break the consensus of the chain you can we can call this the smart contract connectivity problem uh small contracts so if blockchains can connect to outside data resources more contracts cant connect to outside data resources and now were limited so this limits smart contract functionality really to only things that being done within the blockchain which kind of boils down to the moving of tokens performing payments are just kind of representing ownership of things like nfts but another way we can call this problem is the oracle problem um so what is an oracle well you know in you know ancient times or greeks an oracle was someone who could kind of tell the future and give you an answer based on any question that you wanted they kind of knew the truth of the world and um in the blockchain sense an oracle is uh a entity or software that knows the truth about the outside world and knows you know what the temperature is outside of the blockchain in charlotte north carolina um so any device that interacts with option world to provide data or connectivity to smart contracts thats what it is in blockchain learning they can report the results of any outside data or computation on chains or blockchains can keep their deterministic nature theyre um a separate service that lives on top of the blockchain a a middleware so to say um so now instead of having the blockchain connect to uh those apis as we saw in the last slide we can connect to an oracle which will handle connecting to all those outside data sources so great we have a problem to the solution to the uh smart contract connectivity problem also known as the oracle problem well create a blockchain oracle but the naive way to do this is just have a single um oracle that reports all of our truths um and this creates a sin if we just make a centralized single oracle node this creates a centralized point of failure and remember when talking about these blockchains what gave them all their in smart contracts and gave them all their awesome properties was the fact that this was like a decentralized system so we have this highly secure blockchain decentralized and uh but were triggering events were getting data of events uh to trigger events on the blockchain from a single node a single point of failure and that reduces the whole security properties of the blockchain down to that single node thats what were relying on you know then the insecurity of a system is no better than its weakest link pun intended in this case the oracle so um we have this super secure blockchain no one can hack and this very hackable central node what do we do now we create a decentralized oracle network or a bunch of decentralized oracle networks this is chain link chain link is designed to be a modular decentralized oracle network uh for getting secure and reliable data on chain and uh for trigging uh triggering off-chain events um based on on-chain conditions so it can communicate both ways between the on-chain and off-chain one and because its decentralized it preserves all those awesome properties that we love about blockchains and smart contracts so we bring in data uh to trigger external computation uh in a decentralized way by doing this we solve this problem by extending the decentralization and trust minimization that we found on blockchains so we can build a chain link network with as many or few nodes as we need to make sure we have good guarantees on our outside data this is what really gives us the full end-to-end reliability that was the promise of smart contracts that we really wanted to build to begin with um and does it all in a decentralized way so lets look at this example real quick we can make a decentralized oracle network and this would be comprised of changing nodes just like blockchains are comprised of blockchain nodes and theyre all retrieving the price of a a certain asset well say like tesla stock for instance and um they all have to get that price and then they have their own kind of consensus algorithm just like blockchains do where they come to agreement on what that actual price is then post all their observations and their final uh agreement that they came to onto the blockchain um so we can write some awesome smart contracts around that so now by combining on-chain contract code with off chain resources and oracles we have what we can call a hybrid smart contract an even more powerful version of those awesome math-based agreements that weve been talking about this will lack of time um these are smart contracts that rely on existing on-chain code combine it with any critical off-chain computations you know weve kind of just thought of smart contracts as just code up until now now were kind of redefining what they are the smart contracts arent just code that lives on blockchain smart contracts is code that lives on the blockchain and anything else we can get access to in the outside world these hybrid smart contracts truly are uh supercharged versions of smart contracts and theyre already starting to redefine the smart contract industry as a whole and theyll continue to go on and continue to redefine how we are doing our traditional agreements so important thing about um chain link is this blockchain agnostic because its this middleware because this is we have this oracle network that sits uh you know on top of the blockchain um it can actually connect to any blockchain that needs data and today theres a lot more blockchains than uh that run smart contracts than just a aetherium you know we have of course ethereum theres polygon solana uh xd xdi you have rootstock built on top of bitcoin um all kinds of blockchains and chainlink can interrupt interoperate with all of them uh to make sure that they get the most reliable offchain data that they can have so im gonna start talking about uh the chain link data feeds a little bit uh this is a particular service that we can make out of um chain link oracle networks um so we talked about um in the last demo you know we talked about you know the flaws of traditional agreements went through a very specific example robin hood and showed how math-based agreements can solve all of this well in that you know i talked about c5 or centralized finance which were these financial digital agreements kind of traditional that you would get when you log on to your bank or go to your favorite crypto exchange and do anything financial today is a lot of the most popular applications today well defy is totally redefining that market defy unlike c5 centralized finances decentralized finance and its taking all of these traditional financial digital agreements and making them decentralized financially putting them on a blockchain this provides those also properties like transparency um so now we can look into the exact how these d5 smart contracts are written and see the exact code thats written in that contract um gives you control of your assets no bank our exchange has to custody your funds and uh you can even like these d5 apps are even giving some awesome yield compared to you know traditional savings account you know and uh my savings account i think i get something like point one point zero one percent interest and uh certain d5 apps you know theyre giving five percent six percent seven percent interest in part because of the all these awesome efficiencies that were creating um so were getting all these awesome advantages of d5 and uh redefining how were looking at financing decentralized um financial digital agreements and kind of replacing but the thing is a lot of these defy contracts you know financial contracts they need to know price data they need to know what the price of certain assets are so if you wanted to build um an exchange you know on chain this exchange would have to know what the price of all the assets are that exists outside of the chain you know ether exists on chain but even even the ethereum blockchain doesnt know what the price of ether is in dollars dollars is this concept thats kind of outside the blockchain um and so to do this we can create a chain link network a decentralized oracle network or don that will grab the price data of all of these assets that we want to represent on chain and and itll pull them in now in that trust uh trustful decentralized way and so you can kind of look at this diagram and you know we have all these uh centralized uh traditional c5 exchanges here um you know maybe these are all um crypto exchanges and you know you have data providers that aggregate these data this data and then you have our chain link decentralized oracle network which connects to these data providers and maybe even some of the exchanges themselves and they themselves each node you know theyll aggregate that data to achieve what they think is the true price of that asset what they calculate is the true price of that asset then theyll share among each other and come to consensus and aggregate their own answers to come to a final uh guaranteed truth about what the price of that asset is and theyll post it on chain here that uh into a rent what we call a reference contract that any um any kind of other application that spelled blockchain can use now uh we can build these awesome dfi um smart contracts and primitives that take advantage of this price data and it really lets us take it to the next level so why are we harping on why like why we need to use decentralized oracle networks or dons for these this oracle functions well theres already been plenty of attacks on smart contracts in the blockchain space that um targeted specifically centralized oracles like we said earlier a centralized oracle makes a pretty easy attack target and these attacks have lost users and creators tons of money and reputation thats not cool you know if we have in crypto since everything is open if you have something that can be exploited and money will go into it and in crypto money flows fast um someone will find an exploit and uh try to take that money so we can actually go to data.chain.link and we can view these decentralized oracle networks live posting data for a whole bunch of different data sets so here you know we have cryptocurrency data sets we have a bunch of different chains we can go look at right now were on the ethereum main net so you know lets look at each usd all right the trusted answer this is the answer that all the nodes most recently came to agreement on you know its saying four thousand dollars and thirty four thousand thirty six dollars right now and these are all the nodes that are working to get this data theres a lot of them and um you know theyre all doing their own aggregation like i mentioned earlier to make sure that they post the best possible answer because we can see each answer you can look at each note and see the individual answer that they posted so if a note starts acting a little funky and they want to post a 400 instead of 4 000 thats all going to be visible all these nodes have their reputation at stake you know as node operators now we can scroll down we can see the price history and we can look at the individual nodes and what theyve been posting their etherscan addresses all this awesome information and you can even see the users look at how many d5 apps are using this data to do cool stuff and you know they actually sponsor some of this data you know theyre getting a lot of value out of this so they they help pay and secure all of this data being posted on chain so yeah that was data feeds um you know we just went over that you know they act each node aggregates their own data and then that data is aggregated within the nodes themselves uh to get the final answer so lets just go ahead and jump into a demo and see what programming with these data feeds is like live um so again uh youre gonna see this a lot what do i have installed what do i have were just gonna need a metamask wallet were gonna need some test net eth and were gonna were gonna go ahead and start at the chaining docks this time um so from the last demo i already have some testnet eth in my in my in my wallet so were good to go if you need a refresher please feel free to watch the last demo i did to see how we got all that set up okay so lets go ahead and go to the chainlink docs okay so this is the official training documentation um its all open source a really great resource if you ever want to do anything chain we can really smart contracts in general um but were just going to go right now were going to look we have an introduction section on the the left nav bar and we have a section called using data feeds so we click on introduction to data feeds its going to give us a quick explanation of how data feeds work were going to go ahead for this demo and were going to go ahead and go to get the latest price evm so were going to do this all on ethereum for now if you want non-evm chains like solana theyre being added so right now we have another one for solana were going to focus on evm ethereum for now um so it tells us where you know these data feeds are available and look at this it gives us some completed demo code that we can use um to get the latest price were going to use were going to use the data feed to get the latest price of each usd and put it on uh put use it in our smart contract and if we keep scrolling youll see a button deploy this contract with remix lets go ahead and press that okay and um all right were back in remix and it automatically loaded up that code for us lets go ahead and zoom in a bit full screen okay cool okay so here we have that smart contract and just like in the previous demo youll see a lot of the same terms the pragma something new here is the import statement this means its pulling code from in from somewhere else that we can use in our smart contract in this case its pulling in a file called aggregator v3 interface thats sold this allows us to allows us to interact with price or data feeds in our smart contract so again you know we define the contract name we have our state variable calling it price feed its a custom type called aggregator v3 interface its taking that from this import statement we have our constructor which initializes our state and this time its pointing to um its taking the aggregate v3 interface and pointing it to the the reference price data for eth usd on the covan network the test net so everything is kind of set there and we have one function get latest price and its going to call that and its going to recall this function from our price feed that we set here its going to call another function on that called get latest round data and get latest round data is going to return all the information about the latest round that that decentralized oracle network posted data for its going to tell you the round id its going to say hey this is the actual price tell you when that round started the time stamp of when the data was posted and uh giving you the data of uh what round that data was put into the blockchain at and then well what really all were going to care about is the price right now so returns price great so now were going to we have our we have our smart contract its using the chain link data feed were going to go ahead and compile and deploy this so lets go ahead and compile it lets uh turn on auto compile again all right so everything is working fine we get a couple of these informational warnings again again if its yellow no need to worry about it its saying hey unused local variable were not using any of these other things that were returning were only using price but thats okay thats all we need for now so nothing big no red warnings that say hey the compiler is not able to read this code so lets go ahead and deploy this now remember this is set up for the covant test net um to get us going so were not going to use javascript vm were going to switch to injected web3 thatll connect us to our metamask again say connect make sure you know everything is good there and it is remix and our metamask is set to covant testing and so thats what our remix is reading covant test net its looking at the right account it shows my youth balance there that is indeed my account our gas limit were good there and we want to make sure that were pointing to the right contract you see now theres two contracts here because its loading in this contract from our import statement right here on line four thats not the contract we want to compile we want to compile our price consumer v3 contract this is the one we wrote and it includes that other contract that were importing in our constructor doesnt take any arguments were good there we can just deploy it we are deploying so minimax is going to come up say hey youre changing state on the watch im going to call some gas were all good there confirm and boom that was quick we have our contract so now we can click get latest price and it should show us the latest price of ethereum and bam it shows us the latest price of ethereum um theres no floating point decimals in uh solidity so it gives it to us as uh integer 256. um there is a function that tells you where the decimal point is but this is how we can access price feeds uh our data feeds from in within our smart contract and start building all kinds of cool stuff so now we can use this method and start making some cool contract uh logic around it in our contract to do cool stuff and so basically just a basic introduction of chain link price feeds again if you ever want to know more details the docs are a great place as you see i basically just went straight to the docs and follow the demos here our demos we put a lot of work into theyre really great i still use the demos all the time and were going to continue doing that throughout this demo so if you have any questions about price feeds any details you can read the docs you know we can figure out how to get historical price data theres a registry of where all our data feeds are all kinds of great information and some contract uh some change specific addresses where our address is on ethereum and you know on the hackathon theyll probably be posting a lot to test nets so you know you have covant test nets uh rink b test nets also here well i think green yeah ring piece also here you know covan is awesome though i i love testing on covant if you can uh but yeah you can also have binance smart chain feeds polygon x die huabi eco chain avalanche phantom arbitrage harmony solana and optimism um so we go you know if theres a data feed you know you can find it here and you can find all the addresses to use in your smart contracts awesome um all right so lets go ahead and well before we move on do we have any questions can we use any api with a data feed so thats a great question uh so the data feeds are these like curated decentralized oracle networks um that do all the heavy lifting for you and connect to all the apis into the aggregation that we talked about so theres some data that youd need um to get and isnt uh available in the data feed we can actually use the chain link any api solution a lot of people opt to use this for their hackathon its a great way to mvp your application um were going to go over that later so if you want to connect any api we will handle that lets see a little confused by the syntax of get latest price function all right lets go back and lets uh lets look at that again and kind of go over the the syntax so you know first im just going to go through it so you know all bases are covered here we say function that defines that we are writing a function get latest price thats just what were going to call it the name right and its not going to take any arguments were just going to use this to read data were going to make this function public so any account or any other smart contract can actually call this function were going to say view say hey were not actually accessing uh state or were not uh writing anything to state were just going to read data from state uh so were not actually going to do really any hardcore computation we can label it view that makes this um function gases it doesnt cause any gas and finally were going to say it returns an int you know and well define what that is going to be but this function in general returns an integer and so we put our curly braces this is where we put the body of our um the body of our function and you know to make this a little easier to read for right now im just going to cut this out so now were saying hey im going to call this a variable price feed which we defined and initialized in the constructor and were going to call git were going to call latest round data that comes from that uh that variable and thats going to return a bunch of values when we call that not just price its going to return a bunch so we need to take those values and we need to put them in some kind of variable and store them so we can use them thats what were doing here inside the parentheses so were saying hey get latest round data is going to return a bunch of data take the first unit of data it returns and store it within round id take the next data unit of data returns and put it in price take the next you know so on and so forth and stores it in there and finally we say hey all we really care about in our smart contract is the price so we stored all that data but really were just going to return the price and these data feeds do put in like the price feeds are put in as in uh integers and again remember int is synonymous with int 256. um so there you go thats uh kind of the structure of that that function whats the name of that data structure an array no this is just a bunch of different um a bunch of different variables all together were just kind of creating these variables in memory in the function and storing them there okay i think um these feeds are sponsored but will they at some point become non-public unless you pay for it uh great question uh theres no plans that im aware of uh at the moment to make these feeds non-public um you know we know how important these feeds are to building these important d5 primitives and we want the space to continue growing so for now they are public okay last question um okay two questions actually ill take these two what restricts the oracle nodes to uh from providing wrong data again that whole aggregation uh property and their reputation um theres all these like this whole subject of uh designing these systems called crypto economics how do we incentivize actors and this distributed system this decision decentralized system to act in the best interest of the users and uh the important parties that are using it and so you know you can go into a lot of detail theres a lot of good resources online you can google on how you know chain link is uh secured through crypto economics but in a nutshell you know they all have to go through this consensus algorithm they all have to figure out what the truth is theyre all aggregating data remember when i showed you data.feeds.link you know all their reputations are on the line everything they post goes on chain and is available forever and um you know the link token comes into account and um you know kind of keeps them in in check so in a nutshell thats how these kind of nodes are restricted from just providing any data and finally can we have current time as a data feed we can make a data feed for anything that exists any kind of data that these nodes can access so basically everything um you know i dont think the current time is a current data feed its certainly one you can make so all of this software is open source chain link is open source um so anyone could uh make a feed the chain labs team can help make a feed you know if theres a lot of demand but yeah we can make a feed for anything all right lets go ahead and move on in the presentation all right so were done with data feeds for now lets go ahead and move on to the next thing which will be automating our smart contracts using chain-link keepers um i kind of want to put this early on because this is one of our the newer services that chain link enables and really shows how powerful this oracle paradigm can be it doesnt have to just be about getting data and putting it on chain we can do all kinds of crazy off-chain computations and well go into what keepers does so another thing thats kind of limiting about smart contracts and we talked about that oracle problem and how they cant connect to outside data and resources but blockchains cant actually really execute their own code arbitrarily they need an outside actor to initiate it right so you know as weve been deploying our contracts if i want to run get latest price i have to click that button get latest price i have to run that code you know we have to run our functions and so chainlink keepers allows us to create a decentralized oracle network that will arbitrarily run our code whenever we want we can define the conditions we can even define some computation that the keepers will do and then theyll execute our functions when the time is right when we define they should run the functions of course is the decentralized oracle network so it does so in a decentralized way preserving those awesome properties of the blockchain so one example of where this is useful is in d5 loans so back to d5 almost all loan applications in d5 what are called over collateralized loans meaning that when we put assets into d5 and want to take out a loan against those assets we have to actually put up more collat more um collateral um in terms of like uh us dollars for example then uh our eth um in there then um the loan that we take out is worth um and if those that collaterals price and that price is being determined by chain link data feeds of course uh falls below a certain price point um those loans need to be liquidated you know someone has to take out that collateral and say hey look this this loan isnt working out um ill pay back that loan and ill take out that collateral um but you know traditionally you know you kind of just hope that people will liquidate the loans and that this will happen and in times of high gas fees and and chaos um you know when the markets are going insane this can be tough you know gas prices skyrocket gas prices can go above the gas costs um you know people are just like kind of panicking so we can you know employ the chain keepers network to come in monitor those loans and liquidate them as they need be making sure that these financial systems dont break down its not in here uh missing one slide but another cool use case um for keepers is time-based smart contracts which youre about to do in the demo so like you know maybe you have a smart contract that wants to run every hour or every day um these uh we we could use the chain keepers to run that function on a timely cadence so now again lets learn by doing lets uh hop right into the demo so uh what do i have installed for this i have a meta mask wall i have test net eve were gonna start with the chain link docs we are missing one thing though were actually gonna need to get test net linking so just like um just like ethereum requires eth for gas the chain link chaining surfaces require link tokens to pay for the computational resources that link nodes are going through the data feeds are sponsored which means that the users and the big dfi apps that are sponsoring them they pay those fees for the users to keep an open ecosystem so we can continue by building awesome defy apps um but for something like the chain and keepers were gonna need to get link to pay for this service so i actually dont have any link in my meta mask right now only eth so were going to go ahead and do that so what i have tested if were going to click on that because its going to take us to the chain link faucet files.chain.link and instead of just eth were going to get some link this time um so well put in well get our public key our address and well put in our address pass the caption not a bot and ask for link alright so we have tin test link on the covant test net grade that gives us the transaction has to show go to metamask what no link whats going on yeah so metamask you know remember all these erc20 and lynx case erc 677 tokens are smart contracts manamask cant feasibly keep up with all the smart contracts that exist on ethereum so we need to add uh the link token contract address here and itll know where to look so to do that um were going to go back to the docs so were just going to go to type in docs chain link i know im already here just want to type it in and were going to scroll down and we have developer references here here we can see link token contracts this is uh where all the link token contract addresses are stored for all our chains the link token exists on and we see here we have ethereum mainnet covan rink v gorelli other evm compatible chains you name it were were deploying everything on covan so were going to take this address and were going to copy it ctrl c or command c for my fellow mac users so and also it gives us a handy link because it knows probably if youre here youre going to want to get some funds from the faucet so were going to go in our meta mask were going to click import tokens and were going to paste this address into the token contract address so its reading that smart contract says hey this is i know this is link summary decimal places are there well add custom tokens and look its showing that tin link so click import tokens and now my wallet will display my wing tokens as well as my each great so good there and well head back into um well leave remix for now and were gonna go back and so now were going to start the demo were going to use chain keepers and were going to automate our smart contract so functions will run in our smart contract even without us having to run them so first again start up the chain link docs boom back at the chainlin talk stockschain.link come here a lot and were going to go to using chain link keepers again theres a little introduction here that explains to us the value of changing keepers and how it works and gives us a little detail on how we need to onboard were going to go ahead and go to making a keeper compatible contract so theres two major parts to making keepers work we need to make our contract be able to work with keepers and then we need to actually go to the chain link keepers contract itself that determines all the jobs that keepers work well get there um so making keeper compatible contracts again if we scroll down it gives us some code some code and then finally an example contract again we can deploy using remix so lets go ahead and click deploy using remix alright so again we already have our setup smart contract ill skip you know going through the beginning we already know pragma import contract state variables constructor but now we have two particular functions that are too big that are unique to uh smart contracts in general we have check upkeep and perform upkeep so chap these are two functions were going to need to put into every smart contract that is going to interact with change keepers check check upkeep is going to tell our smart contract and its going to tell the keepers when they should actually perform the work they need to perform when they need to call perform upkeep so check upkeep actually doesnt ever need to be called by any users or the developers themselves check upkeep is just for the changing keepers theyre actually going to take this function and theyre going to virtualize it on their own on their own nodes and theyre going um theyre going to run it there until the conditions are met um so its not actually going to cost any gas but we need to include it in this case the upkeep is we say is upkeep needed so we need to return our bool true or false is the upkeep needed um and were going to say hey were going to access this inherent variable on uh sorry block.timestamp this is going to say hey what time was the latest block created and if we subtract the current block timestamp from the last box timestamp that was created and its greater than a certain certain interval we define and were going to define in the constructor then um perform upkeep then so lets say all right our block timestamp and last uh our block timestamp uh minus the last timestamp ends up being greater than interval a chain the keeper will see that say great and its going to run perform upkeep on this uh contract um and we can pass in call data so like if we want our to customize each run or um of our upkeeps we can actually tell hey like actually we want you to pass in this data and to perform upkeep well call our call data doesnt have to be used um and thatll pass in data to the smart contract and you know we can do some cool stuff with that and we can actually have within check upkeep we can have the keepers nodes do computation on that data before they post so okay great lets go ahead and deploy this contract again everything is compiling okay just a couple of uh informational warnings nothing red were going to switch to injected web 3 again because were going to deploy this to a test net connected to my meta mask already covan great right account and again make sure its pointing to the right contract we dont want the interface the interface is what were importing we want to say counter in counter our contract has a constructor that update interval so when we deploy this contract we have to tell it like hey whats update interval and then were going to use that again for the keepers to say when they need to perform upkeep were going to store it in this state variable interval and this is an immutable state variable so lets put it there its not going to change and you know we have last time stamp and we have counter um so you know were gonna initialize our counter at zero every time we perform perform upkeep uh the keepers perform upkeep its gonna increment that counter by one and um yeah so we need to define our constructor how often do we want the keepers to run perform upkeep uh im going to say every 10 seconds well put 10. you know this constructor is a unit all right we should be good deploy were pointing to the right contract not the one were importing pay our gas fee all right our contract is deployed to the covant test net and if we click on counter its at zero so where we started it out at if we click on interval its at 10 thats what i put in so 10 10 seconds is what this is defaulting to here and so every 10 seconds itll check in the last time stamp well just get the block timestamp that we deployed this at the constructor cool all right now weve deployed our our keeper compatible contract were all good there we need to now go to the second part of this and register it with the um keeper registry guess what were going to go back to the docs and figure out how to do that register upkeep for a contract this is part two and again if you forget all these steps you can go to the introduction explains everything these will walk you through all of this and so this is still all done on chain you know were gonna say we need to tell the keepers now that we deployed our contract its good to go like we need to tell the keepers hey this contract exists and you need to start looking at it and uh performing uh your keeper duties and so were actually going to and all this is done still on chain in a smart contract where we can say hey this is the address of our contract but you know theres are this convenient training keepers app we can go to which will help us go through this whole process and you know see some information about um chain link on mainnet and we see some buttons and we can see some contracts that are on uh chaining keepers right now right now we have appointed to covant testnet because thats what our meta mask is on so you see a bunch of like nonsense you know test upkeeps as people are just kind of testing out their code um and making sure everything works fine you know you can switch to ethereum mainnet and see some you know really cool legitimate projects that are using um chainlink keepers uh live now back to covant testnet thats what were working on and were gonna click register new upkeep ah you must connect your wallet before adding a new upkeep so my wallet is not connected and youll see up here in the top right theres a button for connect wallet so click that youll see its communicating more mana mask we see this is indeed uh keepers.chain.link thats what we want to talk with hit next they just want to see our addresses cool all right were in um see my this is my wallet address here lets go and start registering that new upkeep um so were gonna have to put in uh you know email address upkeep name upkeep address so you know ill just put in one of my old deprecated emails for now a yahoo and well call this um hackathon demo thats what well call this upkeep now we need the upkeep address this is the address of that contract we just deployed so where can we get that we had it in remix right so if we just go to remix again we have the address here we click on this double page icon that copies the address of this deployed contract and uh come back here we can paste that in there uh the admin address that has control of this upkeep it defaults to my wallet that im doing this with um thats what we want to do a gas limit so the keepers um you know theyre going to be running all of these functions and thats going to cost them gas and um you know were paying for these keepers now those gas costs since we need it were paying for them were sending this in terms of link tokens to the keeper nodes and so you know if the gas gets expensive our keeper our keepers upkeep gets very expensive and so we may want to put a gas limit on a uh what uh a gas limit so that the keepers dont get too expensive if something happens with our computation and it gets too expensive if we go for the if we go to the docs it uh kind of explains more on how like all these fees are calculated um you can read it here um but for i also said the gas limit is two well just put in two hundred thousand yep okay um and if we wanted to put any check data in there uh when we run check upkeep we could were not going to today and we need to start funding our contract with link so were going to pre-fund it so every time these keepers run our functions again theyre going to look at how much gas costs it costs them and theres this formula again you can read in the docs and then theyre going to take out some of that link and get paid right so we need to pre-fund it so they can continuously run their functions and lets go ahead and lets put all 10 of our link in here we can always go back and get some more so register upkeep and its going to ask me to confirm again pay pay the gas were gonna have to pay some gas to register it in the first place and um its going to wait and confirm awesome so our upkeep registration has been submitted successfully its all in chain and you know heres the transaction and we can actually view that upkeep okay so it uh its active it gives us the address heres our current balance of link weve refunded it with and some details on the upkeep you know what our id is when it was added my wallet is the admin address and the gas on what we set itll also show you the address of the last keeper that ran your upkeep but youll notice something were getting a warning this upkeep is underfunded if you are the owner consider adding funds so to make sure that the keeper is always getting paid when they do their upkeep we dont want the balance to fall to zero so we require uh it is required to put in a minimum balance of link to make sure it runs i only had to link so were actually gonna go back and uh were gonna were gonna go back and were gonna get some more link so we can hit that minimum balance we can always go to link token contracts and you know itll link us to the right faucet for the network we want so im going to go to foster.chain.link slash coven and you know send me 10 more link oh gotta put in my address so this will get us some more link great we have 10 link again so now lets go back to the keeper the upkeep and we can click on the button right here add funds to make sure we get above that minimum balance lets actually add in eight more links so well have 18 link it can run maybe a couple of times and well click confirm now we actually have to you know send that link over and its going to go through a bunch of confirmations allowing it to run all right so my link token got sent over now we have to confirm everything again or with the keepers contract this time say okay good all right our funds were added and look it looks like its already running we already had a keeper that fast now that weve hit the minimum balance run so lets go back to our contract lets see ill see whats been doing here all right remember what are they doing when they perform upkeep all theyre doing is you know every time the amount of seconds passes they check it they run perform upkeep and um they increment our counter by one so we have counter equals counter plus one now our counter was initialized at zero thats what were still showing down over here uh if i click on it now hopefully it should have incremented so lets see ah four its already run four times awesome and now every um ten seconds this contract these keepers will keep running and you know theyre going to you know run through my link balance and theyll keep running maybe we can come back at the end of the demo and see how much how many times the keepers have run awesome so that was trailing keepers that was automating our smart contracts um using them lets go lets lets go into the comments and see if theres any questions question why is a chub check upkeep function not having a return keyword uh lets go back there and lets look at check upkeep the reason it doesnt is because um were not actually returning anything in this function were not um it can return a bool but remember the check upkeep is something really for the keeper nodes to run were never going to have to interact with this so its not too important how often should i how often should i deploy to a test net here looking for our best practice in this question is remix robust enough to write complex smart contracts and fully test them without deploying them to a test then awesome question um so um remix is great especially when youre starting out its great um to quickly get a quick win go in there deploy your contract onto a test net see how it works but um a lot of the power in developing smart contracts is done locally in these like deployment frameworks um so you have hard hat brownie and truffle those are three of the biggest ones and thats where if you know you get a little bit more experience in programming you can mess around with them thats where you can really write uh robust tests you can uh all locally you dont do it in your browser you can um fork the blockchain and make a local instance and test it there and write all these awesome scripts to automate everything thats where most developers actually do a lot of their work when theyre developing like production grade smart contracts and we conveniently have these starter kits that um already come pre-loaded with a bunch of like some some initial tests and like uh chaining smart contracts if you want to see them just have to type in github wrong browser lets do it over here lets type in chain link github were going to click you can click on this this will take you to the main um chain link you know node stuff but were actually going to go smart contract kit or organizational account here and were going to were going to click on one of these well click on hard at starter kit up here you see theres also truffle starter kit and chain link mix which is a brownie starter kit and so um you know you can work with one of these and if you already have some experience well talk about a little bit about them later but these are great places to go feel free to clone fork whatever you need to do and work with your smart contracts there constant crypto yeah so you like using truffle and ganache those are awesome choices to do things locally can you explain again the input parameters of the keepers function yeah so um yeah we have this bytes call data right so our check data we can tell the keepers like when we were registering our okay we can tell the keepers hey like heres some check data go in there and uh you know cut like we can every time we make a new upkeep we can um customize it for different inputs so maybe i have this one contract that i want to upkeep that starts with a check up key a check a check data parameter of zero and then another upkeep registry that starts with a check data of one then these uh the keepers will start to check upkeep with different initial conditions and can even work and use that data to do some cool stuff and then pass that data on to perform upkeep as call data so then we know we can make one contract and deploy to the blockchain and then have multiple upkeeps that start with different initial conditions and do maybe even do different off-chain computations awesome um great questions guys lets move on so weve already gotten some questions about this so lets go ahead and move on to accessing any api using chaining again this is a powerful tool if you just want to get mvp for some data that isnt already on a chain link dawn decentralized oracle network or um you know you dont want to go through the effort of because its quite difficult to spin up a it can be quite a lot of effort i should say to spin up a chain link network so yeah we can connect to any arbitrary api using chain link we call this solution any api cleverly enough and it could be anything could be a web api enterprise system database internet of things censored um or an api enabled physical device such as a car theres a cool hackathon winner who now works on my team harry who actually connected a smart contract to a tesla so thats awesome so you can find a bunch of nodes that um to do this work so we do this by going through a node we go back here or do this by going through a chain link node that uh can relay this information back and forth between the blockchain and the real world and if we want to find these nodes we can go to a great website market.link where we can find a bunch of different chain link what we call jobs adapters data sources feeds basically a lot of different things for the chain link network but in this case we can find nodes that um will do our work for us and were going to talk about nodes and jobs in a second but just to give you an overview of market.link lets click here and so yeah you see here we have market.link you know we can say hey like i want to im a data provider i want to list my data here i really need this particular data we can request some new data im going to go here and click on nodes and we have a bunch of networks here and these are a bunch of chain link nodes some of these are in our some of the these are in the feeds like in the eth usd feed we were talking about and you know we can click on them lets look at link pool now you can see some some metrics on these nodes the kind of jobs that these nodes will run for us a bunch of good stuff and if you want anyone can come here and they can list their node and their jobs well talk about adapters in a second all right so uh any api were gonna go ahead and go through the demo um you already know how it is were gonna go through and uh i have my metamask wallet i have tested and tested link um stored in my because we will need link from here on out every service other than data feeds is going to require us having link uh um i need to stock up though um and uh were gonna start on the chaining docks again back to docs.chain.link this time were gonna scroll down until we see using any api again we get an introduction explaining how this works were going to make a git request though so one of the most simple things we want to do is we just want to make an http get request to an outside api and we want to see what data it returns and post that on chain all right lets go ahead and deploy this contract using remix close out some of this keep our faucets open in case we need it we keep our keepers no close to this ring makes it sense okay so we have our api um consumer contract yeah thats what were going to call this the api consumer and uh you know it imports chainlink client.sol so just like we had an import for keepers to interact with keepers to interact with any api we need to import chain link client and were going to say hey this api consumer inherits from chain link client so if youre used to object oriented programming that just says hey this is uh taking in some of those methods of this parent class and um you know we have a couple of state variables volume so were actually going to use this any api solution get the volume of eth usd from an exchange or a website and a couple of state variables oracle job id and fee so this is what im going to explain to you what these are um so remember in market.link we were looking and i was showing you about all these different oracle nodes that are listed these nodes have an address associated with them that that they they that actually represents that or that note on chain and so if we want to make a request through that oracle we need to know the address uh the ethereum address that represents the oracle on chain thats what the oracle uh here is and then job id so that oracle that specific node may do multiple things it may make a it may have a job to get a get request from any website you want it may have a job for a very specific website like hey this is a weather data aggregation job and it just does that and um yeah so it can have multiple jobs that do many things and so we need to define a job id and so when nodes go on market.link and they list themselves on like hey this is my note this is my address theyll also list the job ids they have and what those job ids do um and finally a fee so again were requesting something from an inv from these nodes we need to pay them in link token for the work that theyre doing so this is the changing network um okay so real quick i actually just want to show you a job well go back to market.link go to jobs its like i was saying see you see all these different jobs and what networks theyre on and what node is running on them and so this is for on ethereum ring b test net some instagram impressions job thats pretty cool um you know copy some data multiplies it gets some gets the number and post it on chain thats cool its instagram impressions so you really cant do anything with these is any api requests all right so were going to go back like looking at the code so we initialize uh this demo code we have in the docs automatically initialize us to a specific oracle address and a job id these are already set for the job were going to do which is just make a git request and the fee is set uh we only need to pay 0.1 link to uh to get there so then we have our function request volume data this is where were going to send a request to that chain link node and say hey i want you to grab us some data its public anyone can run it it returns a patch 32 called a request well get there so first we need to build the request we need to tell that changing node uh where we want to go to get the data and how to get it so well do request.add and well say hey we want to make a git request and we want to make it to this url so this is actually an open url if i make this get request if i just push this on my browser my browser should make a git request to it and we return all of this this data in json format and so yeah we say hey make a git request send it to this url then were going to say remember that big list of data thats a lot of data in there we need to tell what data we want to extract from all that json object so were going to say hey were going to say the path for the json is this its going to go through that json because its going to find raw then go into the the value for there and its going to find e go to the value for there usd so on and so forth until it gets the volume 24 hour so its going to extract that particular data value thats within volume 24 hour and then were going to take that and well say hey we want the node to multiply it by a certain number to get rid of the decimal places and then you know well well actually add that to our request and well return uh the actual function that sends uh this request out to the oracle that we and this function comes from that import chain link client so say send chain link request to well put in the oracle address this request that weve been built weve been building with requests.add request.ad right this continues to build a request so this will send out our full request and what we said to be the fee point one link when this function runs it actually returns the id of that request the request id and thats in vice 32 form so thats why we have a return here for bytes32 request id now were calling request id when this runs so the the compiler will run this this code here and say okay replace this with the request id that gets it now and it will return it awesome so thats what will happen and then we have fulfill so just like keepers you know they have to have a function to run after we send the request out this node will then run well send data to this fulfill function and so thatll run this fulfill function here and pass in that request id this should be the same request id that was generated when we made the request and the actual answer and this case the answer will be uint256 and well call it underscore volume um this is public but we have this whats called a function modifier that comes comes with it that will help make sure that our um chain link node is the one that fulfills this function okay so thats basically whats gonna happen were gonna send out the request by calling this function the chain node will then do its work and fulfill that request by calling this function and it will take that data put it in volume it will take volume and well store it in our state variable called volume so we will now go to the compiler compiler is giving us a green check mark not even any warnings and again well make sure we are pointing to the right contract our list is can kind of big now api consumer thats the name of our contract your vacuums are without soul api consumer and uh well go ahead and deploy we dont have any arguments our parameters for our constructor so we can just straight up deploy it ah but i deployed it to javascript vm thats not going to work we want injected web 3. okay api consumer deploy confirm awesome so our contract is now deployed down here and we have our volume which initialized at zero we dont set anything to initialize it with so it defaults to zero and we have a request volume uh method and fulfill uh method were not going to actually call the fulfill method uh well never need to call it just like perform upkeep this is for the chain node to call so lets request volume gas estimation yeah so remember we need to pay the chain nodes and link tokens so we need to actually fill the contract itself with link tokens to get this to work because in the contract well say hey i can package the sling token and send it over to the oracle um so yeah were going to not send that transaction out and the first thing were going to do is were going to copy the address of our deployed contract were going to come here to our account and were going to click send then were going to paste in that address up there where theyre going to switch from eth to link and uh you know it only costs point one link to send a request well give it a little bit more well say point three my meta mask is just estimating 0.299 and well hit next and you know pay the gas feed its in link confirm now we have to wait a second for the link transaction to go through um this is you know the disadvantage for using covan takes a little time you know compared to local environments or our javascript um so our link is sent we should be good now if we hit request volume what happens ah that area went away were good its giving us the details how much gas estimated gas fee were gonna need to pay were going to go ahead and confirm that wait our request is sent its been included lets check the volume theres nothing there its still zero why because remember were sending this request to a chain link node that chain node has to do work and then post that data to the blockchain and then that so its going to have to make a transaction itself pay gaskets all that good stuff and then you have to wait for that transaction to be included in the blockchain so it could take some time for this data to be posted and boom now its posted may not be instantaneous but it can be relatively quick and uh yeah we have this volume this big number this is uh the volume of each usd from uh cryptocompare.com api so yeah thats uh thats in the api uh again theres some jobs that are very specific like maybe you want to get this wet weather data from open weather consumer this already helps you get set up and how to basically a lot of the same steps put into the oracle job id and requesting the weather temperature how to do that also a new feature thats really awesome and really well requested really requested is multi-variable responses and large responses in the past you could only send one request and get one response back from a chain-link node and that response had to fit within uh 32 bytes or 256 bits if it was anything bigger than that or required more than that you would have to make multiple requests but now theres a way we can get multiple variables with one request this will be a great resource if this is something you want to do in the hackathon and also large responses if you have a very big chunk of data that youre returning back on chain you know again this will let you go beyond that to 32 byte 256 bit limit um you know find existing jobs its going to point you to like market that link um so yeah that is any api this is where you can really power your smart contracts with any kind of data that may not be available as a decentralized oracle network again um you know you can make a decentralized oracle network if you want and and for production thats what we want right we dont want to run all of our data through a single chaining node um were introducing a centralized point of failure but this can be really great for academic projects and for testing and generating a generating a an application um that may not have an existing decentralized oracle network without you having to go through all the effort of building one and just focusing on your application logic at first um so its a very handy and uh useful tool all right lets go back to the comments now we have yes i see theres some discussion going on patricks answering some awesome questions um about um mocking yeah so if were gonna do this all locally you know if we were to use one of those starter kits a hard hat truffle brownie and we were to you know do this locally or even switch the javascript vm within remix those chains theres no nodes looking at those chains because those chains only exist on our computer no one else knows about them so there are no chain-link nodes there are no keepers theres no vrf there so what if you want to test your smart contracts locally and you uh but you know those things dont exist uh you can mock these services and in fact these mocks have been put into our starter kits um especially the hard hat and the brownie starter kits where um you know you can test it that way so you know you kind of just make this contract that represents the keepers or make a contract that represents any api or vrf and then you can act as the the keeper of the or the any api node and that way you get all the power of testing locally and quickly ah yeah weve got some really good questions there is a way to make an any api call where a tls or certification is required and is there an automated way to keep that up that an up-to-date certificate so this is going to be covered a little bit more in future demos but nodes have this ability this um if we go here and uh well just uh give a little sneak peek here and well go to node operators for people who want to run nodes and theres this thing called external adapters and external adapters allow nodes to add basically any kind of logic customize any kind of logic the node wants and uh connect it to the main node software and within this external adapter we can you know you can put a tls certification if you need that in any api keys all that good stuff we can make an external adapter and place it there and you know we can make that external adapter public but you know of course were not going to want to share if theres api keys if theres uh sensitive information a tls certification with private keys in it we may not want to share that with everyone so we can kind of put the structure of the external adapter but the nodes when they run that external adapter theyll put in their own api keys and all that good stuff so thats how you kind of connect to these data sources that you know how the nodes connect to data sources that require a little extra authentication uh harrys gonna be running uh a great demo on uh external adapters later in the hackathon and ill actually be running a demo as well on running a node so well well cover more of these topics later how would you make an oracle yeah same thing were going to go over that and ill be actually going over that in a in a future demo on how you can run the chain link node software is there versioning of contracts what if there are bugs and a new version is required a great question um so yeah so i mean of course you have the solidity not to confuse people you have the solidity version which is up top this just again tells the compiler what language of solidity to look at but you know lets say we want to update our contract and go to a a new contract or uh change something theres a bug and we want to update our contract and fix the bug remember the blockchain is kind of immutable thats one of the properties of blockchain once we deploy something its really hard to change that and so theres some work around this you know we can make functions that like allow a special address to change certain things um you know its kind of a naive way to be very dangerous because it can give someone a specific account way too much power over that smart contract you know this could be a topic all its own but i really suggest looking into uh proxy contracts thats how most people uh how most developers today uh do upgradeable contracts theres a lot of nuance a lot of detail you know could really be its own workshop um but uh yeah so you know looking to proxy contracts for that if the data is pushed to the chain what stops you from reading oracle api data from the chain without paying the fee well the oracle isnt just going to put the data on there we had to send that request earlier and its in that request we first had to load the contract with link tokens and then that contract is going to send the request to the note along with the link token this is actually uh why the link token has its own standard erc677 that inherits from erc20 uh theres a function called transfer and call so like since all this all at once it sends the token it sends all the data for the request and then the oracle will push the data on um and if you know you know what stops other people running it if you make that data public uh on the blockchain you know there itll be easy for other contracts to access it but if you know like hey i need this data for my contract my contract paid for it you can store it in a a private variable um just a little a little detail there private variables those determine who can access it but everything in a blockchain is public so even if we store that data in a private variable if someones running the blockchain node software they can still dig dig in and find that data its just not going to be easier and other contracts and other accounts wont be able to access it by default you know theyll have to run a node and dive in and be a ton of work okay awesome uh yeah you guys are just coming up with great questions love it all right were going down to the last service available for now the chainlink vrf our verifiable random function randomness function um so as weve seen you know with chain link is a little bit more than just getting data off chain on chip with keepers we had this really cool way to automate our smart contracts and even do some off-chain computation with that check data input but one of the more pressing needs for off-chain computation was to implement a verifiably random number generator and so you know random numbers are used all the time a lot of times in games you know if youve ever played in the lottery you know where theyre all the walls and stuff you know trying to get a random number there uh theres a good example um you know flipping a coin rolling a dice a lot of times redness is used somewhere where we want fairness where we want everyone to have an equal chance of being selected and so computers have you know random number generators built into them but randomness by its nature is supposed to be something thats unpredictable you know uh in in this case you know something that thats unpredictable hard to see where its gone what its going to be and uh generating random numbers because of the nature that it should be unpredictable non-deterministic um getting random numbers on changing is really really hard because remember the on-chain world is deterministic and so like some old school naive like when blac like ethereum and smart contracts were still coming out ways to get randomness was like to read the latest block uh timestamp and hash it or you know just on any on-chain hash um are connecting to making your own centralized oracle and connecting to some off-chain resource that can be hacked or manipulated and we have those that were hacked and were manipulated the reason using on-chain randomness is so dangerous is because while you might be using the block uh time stamp or anything from the block header to generate that some on-chain hash uh the miners remember they build the blocks and theyre going to see what that answer is before everyone else before they transmit their block and so they can begin youre giving the ability to the miners to begin manipulating that randomness so if its like a lottery you know they can say hey like im not gonna submit any block until it gets a random number that selects me the winner of that lottery thats not what we want so enter the chain link vrf uh the chainlink vrf brings a solution to bring provably random numbers to the blockchain uh so were gonna remember this is about math-based agreements we want to prove that what were doing is good using math math is cryptography so um when a contract requests data from the chaining vrf that contract can verify using descriptographic methods that the number was indeed generated randomly so you know it generates uh um takes some data it makes a it takes some sea data within itself and generates a random number and post it on chain along with the proof so yeah a lot of interesting use cases come from this true fair randomness on chain now one common place were seeing this is uh nfts so using randomness to create uh randomly generated uh nfts with randomly generated stats on them so you can prove like hey you built this uh this is a randomly generated uh nft and actually another demo ill be doing later in the event it involves this um so yeah and like nfts gaming you know you can see a lot in games where this would be uh useful random number generators are used in games all the time to create you know sources of chaos to create fairness um all kinds of things you know you know maybe youre opening a digital nft pack um and this is gonna tpack give you skins and items for a game um you know you want to give your users like you know if theyre going to be paying for these packs you want to give your users the assurance that hey if theres a one in a hund a one in 100 chance that you get this like pretty rare sword you want to give them that guarantee that its actually going to be one in a hundred that youre not manipulating it on the back end that uh something shady isnt going on so players arent actually getting these rare items and thats where the training vrf enables very powerful and fair applications so lets jump right into the demo then um same old same old metamask test and eth and testnet link which we are good for all right and were going to start out the docs of course docs.chain.link say it a million times um yeah so were going to go to using randomness uh well get our introduction explains basically how it does it and if youre interested on like the details of the cryptography and stuff um theres some good blog posts you can read the introduction here and kind of see how that works okay so were just going to go ahead and jump right into it lets go and deploy the example contract in remix all right um we have the import statement for this contract which brings in the vrf consumer base so just like trailing client just like um the keepers consumer we have this contract we need to pull in and our state we have a couple of things here we have the key hash and fee which were going to initialize in the constructor and we have our random result where were going to store our randomness so vrf and any api work very similarly they were work asynchron asynchronously so we have to make a request and wait for a response to come back um so in our constructor were going to say hey were taking in this uh vrf consumer base were inheriting from it and we want to initialize that contract were inheriting from and were going to point to the vrf coordinator this is like the node address in any api this is the address of the vrf coordinator on uh on covant in this case all this detail is here and then we have um you know our link token address we need to tell hey this is the link token that exists on covan this is the address of that contract and we need something called the key hash again specific to the vrf on every location and the fee um on test net the fee is set to 0.1 link you can always go to the docs to check what the fees are for whatever network youre on okay and just like any api we have two functions get a random number and fulfill randomness get random number just like any api well send that request out to the chainlink vrf uh we have a little require statement here that make sure that this contract has some link tokens in it because again making a request we need to pay a link to the the vrf for the work its doing and just like any api request after we send it its going to return a bytes32 uh the request id of the request that we sent out once that request is sent out with a link token it will the vrf will compute a random number along along with a proof and the proof will be verified on chain thatll happen in the back end and it will the vrf will call fulfill randomness put in the request id which should match the request id of our request and also give it um that randomness that we requested and it calculated well then take that randomness and well store it in our state variable random result so im sure youre getting used to this workflow now lets go ahead and do this compiler isnt throwing any errors i have it on autocompile lets go ahead and switch our environment to injected web 3 since were pointing to kovam it is picking up kovan gas limit and make sure were pointing to the right contract we dont want any of the ones were inheriting here we want random number consumer structure doesnt take in any arguments were good lets deploy confirm okay so we have a random number consumer deployed on covan now and we have our functions again uh we wont need to touch fulfill randomness and its actually showing up as raw fulfill at randomness on this button thats because were inheriting from this vr of consumer base and uh overriding the raw fulfill randomness function so if youre familiar with object oriented program thatll make sense basically were just kind of customizing it from that contract but were never going to need to call that thats what the vrf is going to call so lets look at a random result now we didnt set it up to anything so its set to zero lets call get random number lets go yep of course always always always got to send the link token to the contract i forget this sometimes everyone forgives it sometimes um unfortunately the gas estimation error doesnt give you too much detail about whats going wrong but if you see that uh the first thing you should think is have i loaded my contract link tokens um its pretty it can be easy to forget sometimes when youre just in the midst of everything so well copy our token address from here and lets go ahead and send this contract some link tokens again well paste in our address switch it to link well send point three again its just going to do its metamatic thing and put it at 0.299 well say send confirm and well have to wait for our link token to actually get included in the testnet blockchain its waiting in the i mempool for some test net miner to pick it up all right were good were in so our contract has uh link tokens in it now enough to pay the fee everythings set up lets get random number pay our gas fee all right and again if we click random result right away its not going to show because we have to wait for our transaction to get included we didnt have to wait for the vrf to see the request generate the random number which it does all of those relatively like quite quickly but the real time consuming part is waiting for the vrfs transaction itself with all the data to be posted on chain so the vr off can take some time um theres ways to get you know check this out this might take it a minute here but yeah while this is updating um actually you know what ill just move into comments and look at questions and when we go through well come back and well well see what the random result is um uh mike so uh mike says i dont think its fair to charge for vr calls i know like itd be cool if uh this could be you know free and open and anyone could just make a vrf call for free but remember this the node is doing actually a lot of cryptographic work on the back end and computation if we want to make a sustainable ecosystem theres got to be a way to incentivize node operators um to get uh to do all that work and run all that infrastructure and have that computation run um but yeah i feel you it is like super needed uh function uh on the blockchain can i use chain link vr from uh polygon smart contracts you sure can its actually very very popular on polygon a lot of a lot of nft projects and gaming projects go to polygon because the cheap the fees are very cheap there blockchain is pretty fast so if we go back to the docs um we can actually uh under using randomness we can go to contract addresses and we can see the uh the addresses and look polygons like one of the first ones that comes up so yeah polygon mainnet polygon test net binary smart chain ethereum main net covan ring b thats where the vrf is going if you dont see a chain here that you want to use uh right now you know its constantly being integrated with new chains always check back in the docs and if not you can always deploy it like its an evm compatible chain you can always deploy it to another chain or a test net somewhere else until the vrf is available on the chain yes and human rights humanization correct yes good point um these fees prevent these nodes from getting spammed this is a big reason why fees are uh i think in general in blockchain um that uh you know if things are just open and free you know people will and cant just spam the service until it goes down uh unfortunately so by adding just a fee it prevents them from doing that without going broke if you dont secure millions you can make your own random numbers on chain its not secure but for a little stick application is doable um yeah i see your point but im gonna counter there and say that if its something on chain and theres user value uh stored in it that it is important um under no circumstances should we sacrifice user security to save some money so if um you know its getting a little too too expensive you know maybe look into ways to sustainably fund your your d5 app theres a lot of cool ideas uh out there um are you know go to a chain where its very cheap on polygon i believe the fee is like yeah you see the fee is like 0.0001 link so thats really nothing you can even have the fee you know it might sacrifice on ux but you can have your users load the contract with link tokens and or put that cost off to your users is there any danger of attacking the time between requesting and receiving random value thats a great a great question im definitely not a blockchain security expert you know you can go really in-depth with blockchain security but i can say that you know the fulfill randomness function because its inheriting from uh this vr for consumer base it has some safeguards to uh assure that only the vrf calls fill randomness you know it checks the request ids make sure make sure they matches so you know it is very very secure to use amber uh whats the incentive to make api calls on chain paying for them versus making the api calls in the js layer of the app for free uh thats a good question um so like i said earlier like any api since its using a centralized node um for the most part you can you can make it where it uses multiple nodes but thats going to take a lot of effort not highly recommended but since it is going through a a single node this is not something you really want to use in production because we dont want to have a centralized node controlling all the oracle functions you really want to make a decentralized oracle network um so when youre making it on chain when youre making the api its really useful for hackathon projects uh for making mvps for where youre saying hey this is going to be a chaining note eventually im going to put a um eventually im going to put a updated uh im gonna put a decentralized oracle network there and theyre gonna be pushing data or you know whatever but um you know and itll be more transparent too than doing it from the javascript layer remember the blockchain is all transparent its all open everything will be there all the logic will be there youre not obviously skating um how the oracle functions are working behind your javascript app and uh last what is the chain-link token used for please subscribe as you take yeah so i as weve gone through the similar chain link token is like ethereum it is the kind of gas-like token of the network that powers all these chaining nodes it gives them the incentives to act properly it pays them for their work for their computation and it prevents ddos attacks on the nodes lots and lots of uses for the token uh within the network you know you can you can you can google all these uh things online you know again the chain link token is not just a regular erc20 it is an erc 677 token so it adds in its own functionality called transfer and call that helps make all this oracle magic happen as well all right thanks for all the questions guys this has been fun um lets move on so again uh summary of what weve gone over today uh weve talked about the oracle problem aka the smart contract connectivity problem and how chain link solves that using decentralized oracle networks we talked about d5 and how ching data feeds really enable the future of uh really power the engine of define you know we need financial data for all these d5 apps and you know data feeds arent just price data it can be all any kind of data we talked about how smart contracts cant just run their own functions and how we can use keepers to automate running these functions in a decentralized way we accessed we showed how you can access any api using uh chaining nodes and market that link and finally we talked about the problems of generating on-chain uh randomness and using the chain-link vrf to generate secure provable randomness and putting it on chain in our smart contracts that was a lot um but um you know now you know you understand all this stuff and now you actually have the tools i know i said this before and i joked around about it but now you actually have the tools to make really powerful math-based agreements you know the future of the internet and agreements as a whole hybrid smart contracts um and i think once if you havent already once you start doing it its addicting like you realize how how much potential there is in these smart contracts and all that you can make now that you have these uh the chain link network bringing connecting your smart contracts to the outside world so again if anything in here didnt make sense to you or you need to review this this will be back up on youtube please do take your time go at your pace bring in the coding demos go back to the docs you see i went to the docs a bunch um you know go to stack overflow where you know ask specific technical questions we often monitor stack overflow and try to answer them in a pretty timely manner go to discord have discussions talk with engineers ask questions there and yeah happy building i hope this gave you the foundation that you needed i hope you enjoyed this demo i had a blast i love teaching this stuff so yeah um stay curious out there and uh you know i believe a link is being posted for a type form um if you could fill that out that would be great and give us some feedback on how these demos were you know be critical let us know uh let me know where i could have done better and uh what could have been more clear for you so thanks for listening and uh congrats for completing the first day of demos see you around in the hackathon you Chainlink is the industry standard for building, accessing, and selling oracle services needed to power hybrid smart contracts on any blockchain. Chainlink oracle networks provide smart contracts with a way to reliably connect to any external API and leverage secure off-chain computations for enabling feature-rich applications. Chainlink currently secures tens of billions of dollars across DeFi, insurance, gaming, and other major industries, and offers global enterprises and leading data providers a universal gateway to all blockchains.Learn more about Chainlink: Website: Docs: Twitter: ChainlinkEngineeringTutorials,