Chainlink 🛠️ DataFeeds and CCIP - Richard Gottleber
ETHGlobal·Mon, Oct 9, 2023, 12:00 AM
Join Richard Gottleber for a workshop called "DataFeeds and CCIP". Build with Chainlink on BASE and Optimism. Learn how to use DataFeeds and CCIP. Superhack is the perfect place to experiment with the OP Stack. We, like many others, are excited about the Superchain future, and Superhack is the perfect opportunity to test what’s possible alongside pioneers in the ecosystem. Let us introduce you to our amazing partners: 🔴 Optimism builds open-source software for running L2 blockchains, like OP Mainnet, and aims to address key governance and economic challenges in the cryptocurrency ecosystem 🔵 Base is a secure, low-cost, builder-friendly Ethereum L2 incubated by Coinbase built to bring the next billion users onchain 🪩 Worldcoin is building the world’s largest and most autonomous identity and financial network 🌜🌞🌛 Zora is an open protocol for creators and just recently launched on top of the OP Stack The Future is Multi-Layered Without a doubt, Layer 2 technologies have emerged as the solution for a variety of Ethereum network problems. These innovations, which offload some processing and computation from the main Ethereum network, have quickly become our great hope for scalability, performance enhancements and ultimately onboarding the masses onto Ethereum. ----------------- Follow us: https://twitter.com/ETHGlobal Check us out: https://ethglobal.com Email us at: hello@ethglobal.com
Transcript
foreign [Music] and welcome to the super hack chain link Workshop data feeds at ccip joining us today is Richard gottlieber who will be taking us through the session and with that I will pass over to Richard to get the session started uh thank you so I am Richard Gallagher I'm a developer Advocates at chain link labs and this is going to be a pretty fast and furious little workshop here so I'm going to assume that everyone is knowledgeable comfortable with web 3 at a basic level um while everybody's coming in if you want to pop in where you're from that'd be awesome I love seeing where everybody's from in the chat and these things because it's always such a global audience uh from the chat two if you have questions feel free to drop them in there as we're going through this I'll do my best to put on my live streamer hat and answer all those questions as we go through this but yeah so let's go ahead and get started I guess we got somebody from Columbia or Bogota that's awesome see we're already I'm in Texas so we already got you know multiple contents represented so let's get started talking about decentralized Oracle networks hybrid smart contracts chain link what is it I'll start off with acknowledging that web3 is amazing right it solves some really tough problems it gives us the ability to have cryptographic truth instead of relying on just trusting third parties and she's like that but it does have a problem and that problem is consensus right reaching agreement so we think about most blockchains uh they're going to be comprised at multiple nodes and those nodes will need to reach agreement on things easy way to illustrate this to everyone who's here in the audience listening if I were to ask you a question like what's one plus one right in the chat go ahead and pop your ants in there not a trick question seriously just like you know one plus one equals and yeah two like Felix said right like so Felix and I have reached consensus uh and I both agree one plus one is two doesn't matter when we ask this question doesn't matter where we are we ask this question we can reach consensus a little bit more interesting question to ask is what's the current temperature it depends right I'm in Texas and I use Fahrenheit it's like 107 degrees or something like that if you use Celsius or you're going to give me a different answer and that is a problem when it comes to reaching consensus that gives the appearance of blockchains having this phenomenal cosmic power all these benefits but they've got this itty bitty living space of needing to reach consensus right so this is like the massive downside of blockchains phenomenal cosmic power itty bitty consensus-based living space is referred to as the Oracle problem reaching consensus on real world data like that where it's it depends type of question ironically the Oracle problem has a solution called oracles uh and that is what j-link is is it's an oracle Network so oracles are a method of bringing that off-chain data on chain you can see here you can create your own Oracle right if you have a centralized Oracle node you could do I could have a little servers sitting here in my office and I could bring off chain data on chain like temperature for example but that does take decentralized benefits of blockchains and essentially centralizes them in whatever application is using that Oracle because you've introduced a single point of failure now j-link is a decentralized Oracle Network or Dawn as we call it you can see that here it looks similar to a blockchain right and it kind of replicates some of that we have multiple nodes that then reach consensus on questions that are non-deterministic like temperature as example another good example is the price of an asset right if I were to ask you what's the price of East currently it depends right it depends on where you're looking at that price it depends on exactly when you look at that price that's one of the common use cases that channel sees is data feed so bringing that off-chain information back on chain so that's what data feeds is the most common example there is using that price feed information so it's going to be an asset pair like each in terms of USD Bitcoin in terms of USD something like that we will take a look at a code example and deploy a contract using data feeds in this Workshop we also have a vrf which is a verifiable Randomness function essentially it provides you with verifiably random numbers in your smart contracts that's important because when it comes to blockchains again there is the possibility for no just in the blockchain to manipulate when you're generating a random number on chain such that I think of it like rolling dice right if I'm rolling dice I can't determine what the outcome of that role is but if I have the ability to continuously re-roll until I get the result I want I can effectively control what that random value is this is something that can happen on blockchains that's why something like channeling brf is very important to enable you to have actually verifiable random numbers another product that we have is chalic automation smart contracts while extremely powerful are also extremely lazy and that they won't do anything by themselves now what that means is you need something to actually run the functions within a smart contract that's where chain link automation comes in again using the dawn of the distributed Oracle Network to actually execute those on-chain function calls we also have chain link functions which came out just recently I like to think of this as opening up the entire uh world of the internet to your smart contracts uh is probably the most powerful piece in my opinion of chain link functions what chain link functions does is it allows you to run uh code in a compute environment within that Oracle Network so the oracles will run in a little sandbox environment JavaScript code that JavaScript code could be something like an API call giving you access to all that off-chain data it could also be complex computations if you had a mathematical computation that you wanted to run like some sort of Interest calculation for example it can be really expensive to do that on chain uh channeling functions lets you take that computation run in the sandbox environment still using that Oracle Network and then get those results back on chain and finally the newest thing that we just announced would be channeling ccip it's a cross chain interoperability protocol basically it allows you to send messages send tokens from one blockchain to another and we'll take a look at an example of this today as well if you go to docs.jain.link it's the best place to start for all things chain link uh it has examples as you'll see in just a moment that you can like click and stomately open them and remix and deploy from there I'm going to walk through a little bit different than the examples we provide I'm going to use different chains that are one of the examples just kind of show you how you feel about navigating through that for the first example I'll be using data feeds on the base testnet chain so it's the coinbase chain uh their testnet and then for the second example I'll be doing that on optimism their test net going to spolia so four data feeds if you click on this first one here this is what we'll be talking about and I've got a bunch of information here on data feeds with addresses and stuff like that which we'll take a look at in a minute we'll look down here at using data feeds from here you'll see that there's a sample contract and this sample contract is pretty straightforward I'll go through it but I'll open It remix first so please click this open remix button it will pop open a remix window just like this let's walk through this contract really quick you can see that we are importing in a aggregator V3 interface what is that an aggregate interface in this case is what's going to be taking the responses from the Oracle nodes and aggregating them together to get that response so we mentioned that it is difficult to answer a question like what temperature is it um this example is answering the question what's the current price of Bitcoin in terms of USD as difficult as that right to come to consensus so how this works is each Oracle node gets their response back to that and then those nodes then give you a set of answers from that set of answers you can turn it into a deterministic question by saying what's the median or value in this set of responses so let's say you're turning not a different risk question like what's the price into a deterministic one so that's kind of a little bit of a peek behind the curtain how things work when it comes to reaching consensus from the Oracle Network in this example you'll see here we set up a contract we set up a data feed and it's going to be an aggregator interface and then we pass in an address to the aggregate interface now each asset pair has a specific address on each Network what does that mean so here you can see that this one's set up for sepolia Bitcoin USD it's E43 right if we go back to the documentation and we were to take a look at the price feed addresses here and we were to go to the base chain like we're talking about using in this example and we're going to look at Bitcoin in terms of USD you can see the address is different right so since we're using this chain we need to use this address let's go ahead and copy that address click on that little button right there we'll come back into remix and we'll change both these values to that new address so that's letting you know hey we're going to use this address because we're on a different chain and then we've got our function here get latest data so the way that price feeds works is on a regular heartbeat and probably the easiest way to see this is if we go to data.chain.link and we'll just look at Bitcoin in terms of ESD because that's what we're using so you can see here on this page it's kind of like a visual representation of what's going on on the right hand side we have all the different Oracles and the prices they're reporting and you can see like just look at these first two right there's a difference in the price that's being reported each of these oracles reports their price and that price gets updated on chain when does it get updated on chain it depends on which feed we're looking at if you go to specific feed you can look at the trigger parameters like what we have here so if the price changes by half percent that will cause an update to happen or if the heartbeat time elapses this is basically being controlled by chain link automation so either we're checking a value on chain or using a time-based update as well this is pretty straightforward like when it gets triggered but when something happens to trigger an update then the actual value on chain is updated we're back to remix looking get latest data latest data is going to query that on chain value uh it returns a bunch of different values and that's why we have these commented out sections here if you're not familiar with solidity and like we have a function signature like this technically the right way to do this is just to have like comma and answer comma comma comma it's really confusing when you see that and you're trying to understand what's going on so we have you know kind of an explanation of what the different values are that are not being used within the smart contract so we're getting back our answer that's going to be the value of Bitcoin in terms of USD and we're going to return that back so how do we deploy this right we're in remix uh we've got the auto compile turned on that's why my green check mark didn't have that you just click file and everything would be awesome there you compile it I will change our injected provider to metamask here and again I'm using the base go early chain here and we just click deploy and this is ridiculously large now looking for in this transaction and we can see we've got our green check mark back so the transaction went through and we have our consumer contract deployed now what's really cool about this contract is because this is a view function you can get the latest price data without spending any gas you may also notice that like this price is really large right like woof that's a lot different solidity doesn't have a concept of decimal places or floats so these numbers are artificially enlarged for accuracy uh this one for instance is eight times ten to the eighth power so one two three four five six seven eight we put a decimal place in there that's going to be the actual value that's returned so pause here for a second data feeds we just like Blaze through deploying a contract and we're getting back an on-chin answer to the price of what's Bitcoin in terms of USD any questions so far can I try to build it up a custom or gold to feed my data into multiple blockchain networks using the chain link API um so if you're interested in actually adding two uh the data calls the old way of doing this I think would be to create like a job using any API it's something we had previously to functions that was a way to get information on chain and do it that way if you're just interested in having your information available via chain link oracles anywhere where chain link functions exists if it's an API you could make a call to it so that it's answering a question if you're more interested in like actually running an oracle if you look at our Docs about that in the nodes section it'll explain more about running an oracle any other questions feel free to pop them in I'm going to keep going over to ccip so ccip is brand new uh we just announced it a couple weeks ago I think it's a pretty big deal I don't know again like I worked for chain link so everything's amazing and awesome and the best but like this is pretty cool you can send tokens between chains you can also send information data between chains which is really awesome so let's take a look at how to transfer tokens between James what that looks like so back at our docs page scroll down to ccip and we'll get transferring tokens between chains here in similar fashion there is a contract that we can open up uh in between them for this one not only are you going to need if you want to follow this whole tutorial along yourself you'll need what Native tokens whatever chains you're using you'll also need link tokens which is the chain link token that's what the Oracle nodes are compensated in for doing work you'll also need ccip test tokens which are tokens specifically for these examples on the test Nets there is ccip B and M which is burn and mint there's also lock and mint so you can generate those you can mint those to your wallet right here I'm going to change to optimism gorily real quick so here you can either add the token to your wallets you can also mint so the token right from our doc stage into your you also need to make sure that you are working on a a network that is supported by ccip is kind of a limited number right Essence we just launched um is base indoor exported by CCP so base is not supported by CCI yet um the supported chains are right here under supported networks if you have more it's basically ethereum optimism Avalanche arbitrum polygon currently so in silver fashion I already have this open but this contract will not walk through all the code because it is a massive contract kind of the approach that we've taken with this tutorial contract is this is like the everything and the kitchen sink contract uh it does this ton of stuff we're going to go through one use case here but in remix we'll need to open this up in Pilots we'll need to deploy it um we'll need to give it some native token and some of the b m token as well so let's go ahead and get going with that so I've got the contract here um just kind of walk through a few of the things you can see we're importing our ccip contracts up here at the top in our Constructor there's two things that we're interested in it's the router which will be determining that's basically the contract that determines what network we're sending these messages or tokens to and then also the uh address for the link token on the current Network that we're deploying on if we're using link token to fund this that becomes more important the example I'm going to walk through is going to use native token we also have a whitelist function to whitelist the chain that we're sending to so that's something that we need to be aware of and then we have a function to transfer token and pay a native so this will actually allow us to transfer that b m token from optimisms Gorly to ethereum's Folia so we'll see how that works here in just a minute all right so we've got this compiled again if you don't have the green check mark and you're following along you'll need to turn on auto compile or actually click compile and we will change this to be our objective provider and we'll deploy here now we'll need our router address the link token address where do we find those if we go back to the documentation and to the supported networks page we are on optimism gorley so the router address is here we can copy that put it in here and then the link token address it's right here for us snang those two items real quick so we'll deploy this contract all right we've got deployed and like I mentioned this is kind of a everything sync contract here right we've got a lot of stuff going on uh we are going to focus on white list chain first so we'll need to whitelist the chain that we're going to in this example we're going to ethereum sepolia so we'll use the chain selector for that so we'll copy that value she's been a hair all right so why was it that and now we're going to do the transfer tokens pay native but before we can do that we need to add fund this contract with some of the tokens and some of the Native uh balance so how do we do that well it's as simple as just sending it to this contract so metamask the sinned give it our contract address make sure that's right yep and in this case we'll send it some of the b m so we'll just set it a little bit we can say that like 0.
002 and then we'll also want to send it some East and we can send it 101 should be plenty Okay so we've deployed our contract and we have funded it with token that we're going to be sending and we've also funded it with the native token so they can actually run transactions on its own now we need to get our destination chain selector again which would be the same value that we white listed so this will be for sepolia for the receiver this could be another contract or it could be an eoa a wallet for example so I'm just going to use my wallet address or this the token so now you know and make sure that we put in the right values here uh so transferring tokens paying a native so the token is going to be the token address on the source chain so this is the chain that we are coming from right so if we go to our supported chains we're coming from optimism go early and we need the ccip b m token so we'll get the address here a stat in if we go back to diminish we're going to send .001 or do one followed by a bunch of zeros I'm going to copy it just to make sure I don't mess that up and we will run this transaction all right so it's been successful our transaction has been mined we have our transaction hash here we're going to grab this it's important I got to this by opening up the little debug menu uh to grab the transaction hash right here you can also get it from your wallet so you'll see when we need this in just a minute though so if we go back and the fact that we have our ccip Explorer so we go to ccib.chain.link you'll see our Explorer and this is where you'll put your transaction cash in right here and this will actually take you to this transaction in this or so you can't see what's going on so basically what happens is we have reached out to the router and we said hey we want to transfer these tokens that you have that we gave you you know over to this other chain um so it's going to burn those tokens I'm just going to new tokens on sepolia while it's waiting for a few things to happen though so this does take time um so we're waiting for finality what that means is we're waiting for things to get to a point where they can't be reverted back before we continue forward this security feature if you will so I had to think of this as like a baking show you know we're gonna put this in the oven and let it bake but surprise surprise I already have one that I baked before that was in the oven so this is what it looks like when it's completed you can see here the status is Success instead of waiting for finality um when it comes to this you can see also what token was transferred how much of it was transferred how much cost uh in link we did pay in Native tokens there's like you know version process there so it ends up paying the Oracle now it's in link oh who went from to and the amounts how long it took when it happened so I don't know it makes it really simple to like watch this tutorial and be like yeah you just click a few buttons um but essentially with ccip we're sending tokens from optimism correlate to ethereum's polia and it's ridiculously fast like I haven't even been talking for 30 minutes yet and this is only a small part of it uh in order to set that up and do that you can also send data you can send data and tokens as well if you get back to the documentation we have examples how to send tokens with data send just data transfer tokens between eoas or externally owned accounts wallets so yeah that is the basics of chain link data feeds and ccip like a super quick introduction to them and what chain link is we've got time for questions if you have questions I'm more than happy to answer any questions you'll have cheers thanks Richards yeah feel free to type them in the chat or to take yourself off mute and ask live we got a few questions coming in Eduardo asks when mainnet there's two regular questions where or when main net for what um CCAP it's already in a limited beta there for mainnet um if you go to another chain.link and products and DCI you can sign up for Access right here super tiny but you can sign up for Early Access right there how efficient is he said P compared to Native bridging um I think probably the way that I'll answer that question is by saying is focused on security and ensuring that you can transfer and have that reliability um that is adherent to chain link in your transfers and your Communications across chain um not only is it bridging tokens it also adds the ability to Ridge data if you will to send messages cross chain I think too for your specific question I'll depending on which specific Bridges we're talking about I don't know if I missed this but did you answer or Bruno's question about uh the source of any kind of tokens erc20 or ERC 721 yeah let's see here if we go to where was I out of that docs here um so in order for this to work supported tokens-wise uh we have the test net tokens right that are supported by the routers and in our examples natively um if you wanted to set up your own token essentially it can support any token um because what it's doing in my mind I think of it as you can create functionality such that any token you wanted can be sent to the contract um either locked or burned on that side as it sent across and it's that data going across that can generate the minting of tokens on the other side right so the logic of it if you were to look at this like what's happening when you do this is it's going to make sure as the tokens to burn before it mints them on the other side and it's passing that data along through there so you can kind of if it's a build your own build your own ability for each token basically does that make sense I feel like I'm stumbling through that answer it doesn't make sense Bruno let me know cool and we still have some time if anybody has any questions feel free to tap them in the chat or take yourself off from you uh oh there we go um as far as new chains go that would be part of chain link would need to support uh the different chains when it comes to what you can do like once the ability to send a message across is there uh it's pretty open as far as like what you can create with it right because if you think about it like uh when you're sending tokens across chain you're not actually any sort of bridge isn't actually sending that information across right it's not like the token is here and it's actually the token is moving uh it's just a data that's moving across right so saying over here I got rid of 10 tokens and over here I need to Mint 10 tokens so it's just a data exchange that's happening across chain this is how I think of it personally also cheers for I think we're a little bit over time now but thank you Richard for this uh great workshop and thank you everybody else for attending uh this will be on a YouTube as well in case uh you have uh friends that missed it um but uh yeah oh uh space and Zora will be supported in ccip from ADB yeah uh more change we'll be supported in the future I'm sure I'll answer it that way all right awesome cheers well thank you all everybody for attending and thanks again Richard and uh yeah hopefully everybody has a great rest of the day cheers but thank you
Automatic transcript — names and jargon may be misspelled.