movimientoantipiquetero.com.ar

chainlink hackathon winnersDeveloping with Chainlink Decentralized Oracles: Unitize2020 Hackathon Presentation


24 by 24 chainlink pen chainlinked door chainlink hackathon winners Developing with Chainlink Decentralized Oracles: Unitize2020 Hackathon Presentation
chainlink hackathon winners chainlink and tesseract Developing with Chainlink Decentralized Oracles: Unitize2020 Hackathon Presentation
whats going on unitize hackathon engineers and blockchain enthusiasts at this exact point in time we have an extraordinary opportunity in front of us the world of smart contracts is knocking at our door step and heres theory will show who will be the pioneers to push us into the fourth Industrial Revolution but thats not going to happen unless we get to interact with the outside world and connect these smart contracts off team data API and traditional payments so lets get right into it lets talk about chain link the problem that it solves how it solves it where a chain link is already now some of the untapped potential that it has and the tools you can use now to become a part of history so in order to understand chain link we must first understand that smart contracts are not able to regularly connect to external data or any off chain resource on their own this is a big limiting factor for smart contract adoption because it means the only thing that we can currently do in a smart contract is token transfers so you might be asking why cant I just make a regular API call thats what I do in every other language and this is really important and the simple answer is that the blockchain is deterministic and it needs to be validated by all blockchain nodes of the chain if making API calls as part of the validation then each node would get wildly different results in the case of an API being updated appreciated or even hacked so to interact with the outside world we need to call whats called an Oracle any device that interacts with the off chain world to provide data to smart contracts they report the result of that data on chain so that the blockchain can stay deterministic this is a crucial crucial piece of the blockchain and this is also where channeling comes in its connecting with this off chain data and storing it on chain there are thousands of API is out there that are already providing high quality data that people need for their applications we make it easy to enable connectivity between those apis and smart contracts even if they require authentication so that you can having centralized applications powered by the same reliable API is that the rest of the world in current Willet applications use today a single chain link Oracle is called a chain link node and Ill be using them a little bit interchangeably moving forward now a lot of users today still dont understand the block chain and sending payments and cryptocurrencies isnt quite universally accepted yet when a smart contract is us executed people need the ability to get paid in the currency that they want chain link makes it easy for option payments to take place based on on chain interactions this also works for cross chain communication and sending payments other chains chain link uses something called external adapters and well talk more about that later to enable connectivity to any resource be it an open API and API that requires authentication payments payments API or another blockchain it works essentially as a wrapper around an API so you can make these upgrades to provide authentication processing or anything to reduce on chain gas costs and privacy external adapters can be written in any language you want and they only need to react to specific requests sent to a chain link node because of this its very easy to introduce new functionality channle without needing to know anything about solidity or even theorem now heres where we turn up the heat a little bit a centralized Oracle service or a centralized Oracle or a centralized node becomes a single point of failure for the entire smart contract this is why we create decentralized Oracles saying the chain link no by itself is a centralized is kind of like calling a tree of forest one single entity does not make up the whole to make applications that are truly never needed to rely on one entity being a company a landlord or government or anything of the sort you need a network of chain link nodes why am i stressing this point well weve already seen attacks that have lost projects literally millions of dollars since their centralized Oracle was hijacked so chain link is designed to be a modular infrastructure and can build the decentralized oracle network used to connect smart contracts to any api you can select as many oracle nodes or chain link nodes as we call them as you like and use as many data sources as you like in order to trigger the execution of your smart contracts then again chain link also enables off chain based off of these decentralized Oracles for the execution of the smart contract so if the result of a smart contract said that someone should get paid $100 USD you can utilize chain link to send that transaction to get you started with defy or decentralize finance the chain link project has gone ahead and found many of the best blockchain node operators on the planet and combined their prowess to build whats called reference data contracts or price reference contracts or reference contracts these are decentralized on chain reference points that can be considered source of truth for various currency pairs like the price of eath in terms of USD for example each node in the network independently gets data from some of the highest quality data apis and reports their answers on chain you can see the answers that each provider reports so that everything is transparent many of the most popular cryptocurrency or fiat currency pairs are currently supported and the best part is if you dont like it you can always create your own network anyways currently these reference contracts are already being used by a slew of some of the top t5 projects in the world the proven safety reliability and powerfulness of these applications is a testament to the power and security that chain-link has and to reference contracts here are some of the products that are currently using chain link in the d5 space we have synthetics loop ring set protocol Ave and these all have acquired large amounts of secured dollars for their projects some other places that are starting to get some traction but arent quite there yet is the gaming realm until now and heres a big reason why getting random numbers on chain has been an issue since the current conventional way to get a random number you have to rely on the Eve miners for a random hash or a centralized API like random org that can be hacked hijacked or or even changed chain link has a decentralized provably random system and the surface is barely even scratched we saw one project implemented the chain levy RF aeroelastic on and one product pushed the gaming potential until I with their no last betting application so this is one of the areas of blocking that I want to emphasize because there is a huge opportunity here defy project pool together has also implemented the channeling the earth allowing their no loss audited savings game to be truly unpredictable which is crucial for the project they currently have about three-quarters of a million dollars worth of die and theyre constantly growing this brings me to our next point we have a blog that gives a list of ideas to power your smart contracts so if youre coming into this act on and you have no idea what to do I definitely recommend you check that out the blockchain space is literally thirsting for chain-linked secured decentralized applications let me wrap it fire some awful let me wrap it fire some of my favorite ideas off so first off d5 we mentioned before its constantly one of the major areas of pushing for project and as a ton of momentum and knowledge of people work in the field channeling supports already some of the top projects in defy at the moment theres over 1 billion dollars in assets and decentralized finance which is a huge accomplishment and major milestone and you may think wow a billion dollars thats a lot but then you have to compare it a little bit its not even point one percent of the traditional finance space the math is too hard for me to calculate how small it is the average hedge fund has over a billion dollars and there are over 700 hedge funds that have singular hedge funds that hover over a billion dollars and about three point two trillion dollars an asset managers in general and were not even talking about how much money banks high-net-worth individuals or other financial instruments are securing Chandler makes integrating with financial instruments really easy with reference data contracts now this may seem like an insurmountable feat to reach these Heights to reach what the traditional finance world currently has but I promise you its here its here and its right now and its knocking at the door the window of opportunity though wont last forever or here to make sure we can build some amazing tools and have fun doing it well next one fantasy sports fantasy sports players can average hotter dollars per league on a decentralized application on blockchain you can cut that down by a fraction of a fraction without having to trust that the scores are being updated unfairly or the odds being skewed Texas Holdem or any card board game channeling brfs make this possible with giving access to truly random numbers while still being way cheaper than a buy-in at a major Texas Holdem tournament tokenize assets you can split up your car plot to land share the stock making it easy to keep track of who owns what without having to deal with paperwork and since your data is coming from decentralized Oracles nobody can mess it up insurance this one really hits home for me lets say youre a farmer and your crops are all ruined from two seasons where the weather was terrible and your insurance being a centralized entity has decided that theyre not gonna pay out because some pre-existing condition now you can go to court and you can fight it and you could win which would be great you would still have to go through all this time and effort fighting the insurance company through court or worst case scenario you go through all that pain and you still lose with a decentralized smart contract you dont have to trust that insurance company is gonna do the right thing since the right thing is infrastructural with chain-link by this time you should understand what the power that chain-link has when it involved a smart contract so lets dive right in to what exactly this looks like at an engineering level were gonna be going over the reference data contract first because it it is the easiest implementation of chain-link while also being one of the most powerful if youre using a defy technology like yunusov compound or or any defied technology a quick check on their Oracles with a chain link price reference feed called a chain link anchor can save you heartache bug fixing panics and possibly millions of dollars down the road lets see what that looks like now so if youre looking to use reference dated contracts reference data first thing you want to do just come right to the docs doctor have all the information that youre looking for talking about how it works the aggregator interface and everything now something important to note is that the syntax for all these is for truffle and for nodejs well get to that in a little bit for now were gonna be using remix which is in theory m ide which and its really really powerful for just spinning things up quickly on a test net and singing exactly what its gonna look like when you actually deploy to mania and interacting with it really efficiently so go over the truffle in a little bit but basically what were gonna want to do is come here you could read everything that you didnt know and we have a complete example at the bottom which is great we have this little its a little copy/paste button right here and you just copy it come over to your remix ID hit this little plus tab make a new file and paste it into here so I cut it down a little bit to make it simpler and you know all these functions that we have here are to interact with the reference contract easier so we have get latest timestamp to see where we are you can see the previous answers you can go back as far as you want and get the previous timestamps as well I cut it down to be just get the latest price and if thats all you want this is literally how small your contract can be so the other important thing when dealing with remix it doesnt work with that that nice nodejs syntax what we saw so were actually importing directly from github be sure to look at our boilerplates to make sure that you have the right link and well have a link to that as well but yeah were gonna start with solidity version six were going to import from github were gonna start our contract which again if youre new to solidity this is kind of similar to starting a class we have our a great interface internal ref which is kind of like a a global variable we have our constructor which is the same as any other language its once this is gets deployed on a test net this is what gets called and we have this at latest price which literally calls saying literally calls from this reference feed and we can see a full list a full list of reference data contracts for pretty much any pair that you can think of be sure to note that they start or that the addresses are different on maintenance and the different test net so eath USD will have a different address for Robson then it will from main that be sure to test on test net before you go right into main net and and again if you want to see what these feeds look like you can come to the feed saw chain that link page and you can see okay well what are the nodes looking like whos returning what answer and you come to here and you can literally see the visualization and on all the data around here the node operators that were returning data and heres the aggregator that consensus of the answer in the middle here which is really cool so going back to remix super simple code its literally this small we have it in here great were going to choose our version is gonna be solidity it brings this file up here were going to choose our file which is which I called reference data dot soul for solidity files you need to do dot so were going to compile its gonna compile everything great looks like compiled successfully lets go ahead and deploy were gonna want to go to injected web three here its gonna ask for our permission for meta mask to connect so if youre unsure how many masks works be sure to follow our other tutorials and the docs and follow our videos as well that show you how to install meta master you can work with this really really easily you can also learn how to get test eath and test link so that you know what to pay any money when deploying these test contracts and playing around with them so great so we have rave giving me money yes great so were gonna do we injected web 3 which is literally taking a web provider sticking it in our browser here and this deploy button right here is whats going to deploy the contract and the address that were looking for is gonna be here this is the address of that reference contract that we were talking about and again we can get that list for full route list of reference contracts we can get that from here again which just has everything and you literally just copy and paste that into right here and itll be whatever feed you want so weve copied from eath USD not this one weve copied from this one right here on the Robson because were on the Robson thats not right now place it in here were going to deploy the contract Metta mass is gonna pop up say are you sure about that and were gonna say yes were definitely sure about that its gonna give us a link and its the same as the point pretty much any contract you wait a couple minutes you wait a couple seconds once it gets deployed were good to go and youll see it actually pop up in the bottom left of your remix screen and you can click that and itll show all of our functions and and how we can actually interact with this contract since we only have one function lets get latest price and its a view function which means its not actually changing any state were not actually going to be sending and receiving any link were literally just reading from the blockchain we dont have to pay anything so we can just call it and metamath will not pop up and it will give us the response of the price reference contract which is to two hundred fifty five dollars and 81 cents which is great and as you can see it looks like its a lot more thats because its its been multiplied because blockchain doesnt work with decimals very well but thats it its that simple and I can take this and do some simple stuff like you know if anchor is less than 10% of Oracle this is some pseudocode err then then dont run a smart contract literally that simple and the rest of the integrations are literally that easy too so the next step I would say would to be through this request and receive data tutorial we have a video coming out as well as the Docs are really thorough I highly recommend doing it in remix first so that it you really go in depth and figuring out how it works on a test net contract we have video on our chain link YouTube you guys should definitely check it out that goes really in-depth at it but were gonna skip that one for now were going to go to setting up a chain linked project using truffling using node j s this is a really really powerful tool because we can actually test our smart contracts and we can deploy from an IDE or a text editor that we prefer like visual studio code or vs code or whatever you want and so this is going to be the same as that requests and receive data tutorial except with no js hey engineers now were gonna learn how to build really powerful front-end applications integrated with channeling smart contracts theres a fantastic technology out there called truffle and it makes it really easy just to get everything in a node.js application and for you to start coding as you would a regular node.js application so were gonna just dive right into it right now so its pretty simple come to the documentation page here and were literally just gonna copy paste stuff so first were gonna install truffle were gonna install it globally NPM install truffle make sure that you have the most updated version of NPM otherwise your you might get issues so great and then same thing now were just going to copy this they little button what its going to do is gonna make a new directory for us were gonna CD into it and were gonna unbox this smart contract kit so this is a basically an sdk a software development kit that has a whole bunch of boilerplate stuff for us to go ahead and start developing so lets go ahead and do that and this may take a few minutes to actually download great and then once its actually done downloading the boxes is done were gonna see over here were gonna have a new project thats gonna have have a ton of stuff going on in here so just to kind of give you the rundown contracts this is where all your smart contracts are going to be this is the same thing as remix so you can kind of ignore this error for now this is basically what it would look like in remix obviously you know theres theres a lot more notes here for you guys so that you can read and kind of figuring what its doing out this contract that were doing is going to be our the request and receive data tutorial in the chain link doc so if you havent checking about check that out be sure to do that we also have a YouTube video coming out thats doing it in remix so itll be the same thing as that video just now in node.js which is really exciting so this is where all the your smart contracts live migrations you dont really need to worry about but its gonna help us put our our code on chain node modules is obviously node modules no Jess scripts these are some quick scripts basically to help us fund contracts and read and request data from contracts so that we dont have to be interacting on remix or or interacting with the contracts more directly and then test is this is you know one of the most powerful features of this is is this right here we can build these tests to make sure that all of our code does what we want it to do in relation to our smart contracts so this is this is a really important piece and if we jump in here we can kind of see what its doing its its setting up a theorem chain saying hey these are gonna be the the accounts that were gonna be playing with and before every every test which we can see down here and described before every test were going to set a link token were gonna set an Oracle and were gonna set my contract which is this contract here were gonna set my contract and were going to start running the test right so for example this first two tests were going to describe or say hey were in a credit request without link and were gonna literally requ it create a request without Lincoln were gonna hope that it arrows out when it doesnt have a link and it is successful when it does and we can run these tests actually right now we dont need to be connected to anything we can just do NPM test and its gonna run this MPX truffle test and this truffle command its kind of the magic command that is setting all this up it is interacting with the etherium chain so that we can do all this which is which is really exciting powerful but yeah while thats running the rest of this is is kind of more nodejs stuff this piece is is pretty important when were doing migrations and by migrations I mean deployments anytime we do a deployment if we say were gonna do a live deployment were going to place those contracts on a live net so either maintenance net depending on your RPC URL will determine that whats an RPC URL its its basically what connects you to an STM client so it could be a maintenance all of our test passes I main it one a test that one it really depends and you can find some of those you know either at fuses free one right so if you use this as your RPC URL obviously itll be connected to Robs then Im actually gonna use in Fira but just so that you guys can see what it would look like its going to be a environmental variable so you would do this export syntax export RPC URL and then youre gonna equals blah blah blah blah right and so this export command only makes this environment variable live for this terminal so if you delete your terminal youll itll delete it if you want to make a dot env file and put this export RPC piece in there you absolutely can do that but I would caution because you know I wouldnt want you send it to your git repo and however to see your your RPC URL and more important that is actually this bit over here processed uh Ian vida mnemonic so this is the 12 words seed phrase that you get when you set up your meta mask account if you havent watched that video yet definitely watch the video so you can get that setup in meta mask Im not gonna show you guys um but theres a you can actually go in here go to like I think its settings its one of these ones Oh settings you go to settings youre gonna reveal your seed phrase and thats gonna be the mnemonic device that youre gonna save so youre also gonna want to export that so you can do export mnemonic equals and youre gonna want to put the quotes here and its gonna be like dog cat mouse frog you know blah blah like whatever 12 words are so those are the two really really important pieces and theyre super important because like I said the RPC URL is whats going to connect you to Anna theorem client so actually be able to deploy contracts on chain whether its a Testament or maintenance obviously if you want to do testing here youre gonna want to set it to be a test net RBC URL and the pneumonic device is what its gonna actually allow to interact with that wallet with that eath wallet so thats why its really important to get metamath set up so you have this eath wallet that you can interact with and thats where itll pull gas costs from it and linked from and and everything so definitely watch that video but yeah this and this is here if you want to do some local testing you can set this up so that you can do migrated dev and and do like a dev environment but were not gonna focus on that for this for this tutorial great so were actually gonna just run run into it and we do have to edit one thing because there is a bit of a right now theres theres a bit of a glitch with the truffle box so we just have to change this truffle a Seewald provider to next meta mask updated their their software recently and it caused some stuff to break so were just going to come in here hit next and then run p.m. install depending on when you watch this this video that bug might be gone but for now this is what were gonna do and great so cool so like I said this this truffle box does a lot of different things so we want to focus on just figure out how do we deploy a contract how do we missile the contract how do we do tests and thats pretty much it so I just showed you how to run the tests if you want to write more tests you come in here and you can add more context add more stuff to do more interact with contracts depending on what your contract actually does obviously this is my contract Im just cord test so if you want to build more smart contracts or more yet more contracts you dont want to build tests for each one of those as well you can use this as the rubric so but yeah now what we wanted to do is we want to actually deploy this contract to the ROPS then test it Im using like so I was using export our PC URL equals Im using a HTTP slash like a Robson or Robson RPC URL so this is gonna deploy to a Rob stand test net which is really awesome that we can do it right from vs code thats the editor that Im using by the way if that wasnt apparent and its with a simple command NPM run migrate live now again this live is its an important keyword you can also do dev and that will connect to whatever you have in here so were gonna do live though were gonna say hey we want to connect to our Robson test net base off the RPC URL that we have so we run this were gonna take a minute or so and were actually gonna deploy nothing because there was an error oh and if you run into an error like this dont worry about it it could just be an issue with whatever RPC URL or doing or or whatever its a test net its not perfect but yeah were just gonna run it again and it looks like its working this time so thats perfect so we are were doing this migration like I said the migration you can think of it as the same as deploying and the contract that I really care about is is is the my contract outsole because this is the interesting one if you havent checked out the request and receive data video definitely check it out definitely read the docs see what were doing but basically were picking a chain so what this dot what the smart contract does is it creates a request to a certain chain link Oracle so a single node a single job ID gives us some link pay and it requests an arbitrary URL and gets the data from that URL which is obviously really exciting because any API in the world has a URL that we can connect to and and this is how we do it so this is kind of the code that it does it all with draw Lincoln in the whole nine yards so we have a lot of the basic functionality here so as its saving this migration to the chain and this is this is some interesting as well the reason that the reason that this is a important piece is this is kind of defining how were deploying the contract so were saying hey if its live heres what were gonna do to actually deploy it and and make sure it goes smoothly so so space whats going on so now were actually deploying my contract we have the transaction hash we have three blocks we have the contract address which we want to save for Im actually just gonna put it there for a reason I will tell you in a minute and then we have some other stats that are really cool so great so now we have its actually deployed and oh so important thing important thing is again you know make sure this is that your wallet has Tessa eath in it and test that link otherwise you know youre not gonna be able to deploy anything so so we can actually go to ether scan Robs then test not Robson and we can see this contract here just a double check great it was created one minute ago by us which is really cool that we can deploy contracts right from our vs code right from our you know or nodejs application so great so weve deployed it now we have some scripts that can help us interact with this fund contracts right now is is not working super well home because of that the buggy that I was telling you about so um were just gonna fund it the manual way here which is which is fine this is really quick anyway so were just going to send it were gonna send it to link when I send it fast and again just in case you didnt know you know theres the eath gas that you need to do any transaction on a theme chain theres also the chain link gas that you need to interact with Oracles so so this is the Oracle gas that were gonna be using the chain link token is that that chain link gas so once this finished send finishes sending our contract will actually be funded and we can go ahead and start trying to request data out of it which again go check out the longer video on how it works it doesnt in remix Im gonna skip over exactly whats going on and this were just going to deploy it and go so well excuse me we are to deploy that were just going to go thats so great so now were gonna do this request data script which has pretty much all the parameters that we wanted it so were choosing an oracle address you can choose any oracle address that you want that returns this type of data were actually returning a what are we returning we can see it in our contradicts its gonna be a fulfill its gonna be you in 256 so we just need to find an oracle that has a job that can you know get an arbitrary api which runs in you at 256 obviously we can go to market tell link again find an oracle like this yet we have the oracle there we have the job ID here right we have the payment here which at the moment is just one link on maintenance and we have our arbitrary api we can make this anything we want and yeah and then were just going to make this make this request so were gonna go ahead and run the script to do this and its just going to be NP x truffle excuse me truffle exec scripts request data oh and if you wanted to once the the funding one works itll just be like fun context is with the same rest of the syntax here but were gonna do request data dat JX jazz and the network is going to be live again live connected or intestine so this is going to do the same thing as we saw a remix of us clicking the button like request price or or create request to in this in this case since our contract has this function create request to which if you watch the other video like I said its request eath price in that other video so so were creating the request on this contract which is perfect because thats the contract that we just deployed and we funded it so we can actually watch on either scan the transaction just came in and its pending and once it completes were gonna see that show up back here Im perfect and thats the hash right there of the completed transaction and we can see great it looks like its completed here thats fantastic so now because weve requested this data now we have this stored data on chain and again if we look at the the scripts here for requesting data we can see that the URL is for the price of Ethan USD so we want to read right off the contract and luckily we have a another script that does this MPX truffle exec scripts read contract network network and again you know you can edit these as you as you like right in here this read contract we have so we got an error here up saying there we didnt just rerun off of that but yeah if you have different contracts or you deploy different contracts youre gonna want to come in here and adjust these rights so this is saying hey were gonna create a new variable called MC stands for my contract and were going to do data call so if we look in my contract we have a variable right at the top called data so were just calling that and thats what this read contracts doing its just its calling the contract its saying hey lets call that data right there request data obviously is a little bit more involved but cool so if we look down here boom we have the answer it there so 228 dollars and 13 cents again the blockchain doesnt do great with decimals so all the decimals are obviously removed we have in our contract we define times excuse me not in our contract in our request data times to be a hundred so we move the decimal place over twice and thats why we can see this right here and and thats it guys thats its its really that simple I hope that this was helpful for you like I said some of the most powerful awesome reasons that that truffle helps out here is you can integrate this with a with a full scale front-end back-end web application since nodejs you can run some of these tests so that you can actually run tests on your smart contracts both locally and on a live test net and you can configure it to be part of a custom test end as well and its just really powerful in that sense and super customizable well thats it see you guys next time so that is it guys theres a lot to unpack there theres a lot to uncover theres a lot to do theres a lot of really exciting opportunities chain-linked is an open source product thats always improving theres some really really cool stuff coming up soon like threshold signatures which will help reduce costs and improve the security of the system in general but to kind of get to there you still need to figure out how everything works so getting started now is is fantastic and youll be miles ahead of the of the curve here so we have tons of resources out here to help you out Im always around you can pay me in discord you can ping me on Twitter on on LinkedIn slack whatever we have a number of out-of-the-box examples as well as examples from previous winning hackathons we have this let me get out of the way here we have these these winning hackathon resources Ill just leave it in the description we have we have hackathon resources for you to check out all the docs tutorials everything you guys need definitely definitely definitely jump in the discord chat the community is some of the happiest and most helpful people and they just all want to build really cool stuff and and were all in there Im in there and definitely check out the documentation because thats gonna be the best place to start so thats pretty much it and yeah what are you waiting for go start building some chain link projects see ya The Chainlink Fall 2021 Hackathon kicks off October 22. Sign up today: Watch Patrick Collins Unitize2020 Chainlink Hackathon presentation as he goes over the blockchain oracle problem, how Chainlink solves it, deploying a Chainlinked reference contract, testing, and then deploying full-stack dApps with the Truffle developer package. Chainlink is a decentralized oracle network that enables smart contracts to securely access off-chain data feeds, web APIs, and traditional bank payments. Learn more about Chainlink Documentation: Discord: - Very active and developer-focused! Website Building DeFi Applications: Twitter: Telegram: If you’re a developer, visit the developer documentation or join the technical discussion on Discord ChainlinkDeveloperWorkshops,