Dynamic NFTs without blockchain limits
ETHCC 7 · 10 Jul 2024 · 36:15
In this hands-on workshop, Solange Gueiros of Chainlink Labs shows how to build a dynamic NFT that is not limited to on-chain data. She explains how a decentralized oracle network brings external data into smart contracts, and how an SVG image and JSON metadata can be generated inside the contract itself. The example collection is deployed on Ethereum Sepolia: its background color depends on the chain it was minted from, and its face changes with Bitcoin price moves from a Chainlink data feed. Attendees follow in Remix and MetaMask, then mint from Avalanche Fuji using Chainlink CCIP cross-chain messages and track the transfer in the CCIP explorer.
Speakers
Topics
From ETHCC 7, hosted by Ethereum France.
Transcript
Hello everyone, welcome. So I'm here to talk to you about dynamic NFTs and different ways that we can have a dynamic NFTs, and even don't have uh the blockchain limit, it means that your NFT NFT can have information that is not inside the blockchain, stuff like that. So, this is me. My name is Soleji Gayus. I am a DevRel engineer at Chainlink Labs, and I came from Brazil. I used to add all my talks and workshops, what I'm doing, I post on my Twitter, and also you can see my website with the past talks in different languages.
So I have Portuguese, English, and Spanish. Almost done. Okay, let's go.
Yes, perfect. So please go there because I'm sharing exactly what we are doing on this collaborative pad. This is a place where everyone can write together. And I'm going over there as well. So can you can you add your name? Yes.
Can you add here your name and CD country? I think we have people around the world here. So I came from Sao Paulo, Brazil. Ah yes, this is no problem. Yeah. Welcome. Welcome, Jake. From Lisbon. And wow, we have people from Paris. How can I say your name?
Nice one. So is this? Oh, I did something wrong. Yes. It's not to add more. Siriu. Oh, nice to meet you, Cyrio. And Heather as well from Amsterdam. Oh. Love to see people around the world. So for you that would like to do this with me. I'm adding now here in the pad some things that we needed, like our requirements. Then I'm starting the presentation, and in this time you can do the requirements.
So I will change a bit the order only to you to go to the requirements first. First of this. And it will be something like that. Let's copy here. So the requirements to us. We are using the token link. And we are doing the practical part, it will be mint an NFT from Avalanche Fuji to Ethereum Sepolia. And also I'm using other things as well.
So I like to you to do this part. And I'm talking about you something technical aspects before that, some views related to the NFTs. So do this part related to the connections, and then we can do the other together. Okay, you can follow in the path, and I'm coming back to the presentation. So the way that we can have an NFT without limits can be using Oracles. Because Oracle is the way that we can connect the blockchain with the external world.
So I can have any kind of data or any kind of resources that are not on blockchain and use this inside the blockchain. And this can be like a temperature or something related to a satellite or my watch, my steps, or the weather, or sports, or any financial data. And when we talk about oracles, okay, even if the source it's centralized, it's one API. Try to get this information in a way that at least to get this information is decentralized.
When you talk about blockchain, we are talking about a decentralized Oracle network. So the idea is to get all the information that's possible in the same way. So imagine that I'd like to call an API that is not on blockchain, it's only source. But if I have one node, like one operator getting this information, he can manipulate the information. But if I have three or four or more nodes like a decentralized Oracle network, calling the same API, getting the information, getting a consensus that yes, this is the same information, and then bring this to save in inside your smart content, we can have this in a more trustable way, because at least to get the information it was decentralized. And this is something that we are talking more today.
So this is a bit what Chainlink does. And uh Chainlink is not a blockchain, chain link is a set of services that is deployed in different blockchains. I usually some of them uh in the NFT's uh side. Let's start now to talk about the NFTs itself. First of all, when talking uh about an NFT, not necessarily the NFT must have an image. But uh most part of them has animation. Uh but if you are uh um save this image, where the image is stored, I have NFTs that they must disappear.
Yeah, and now I have something that I don't know what you do with that. So when we have the image in a uh in an off-chain, like only a URL, and this is not like an IPFS or something that maybe can be stored for more time over there, this can happen, this can disappear. Another approach is to have the image directly on chain. It's hard, like if it's a normal image can be huge. But today I'm doing this using an SVG.
And I'm creating the image inside my smart content as well. This is one of the cool things that we are doing today. Another point related to the NFTs is we have the image and we can have the metadata. And again, this is not like an obligation, but it's uh most part of the NFTs collections have the same structure talking about the metadata because it will be compatible with some marketplaces like OpenC. And this is the standard from OpenC.
And when we call a standard, it's not an obligation, but a uh a recommendation that if you follow that doing that way, everyone can interact because they know how is that. It's the same like if the ERC20 token, ERC271. It's a standard. If you say that your token is in that standard, we are expecting to see some functions over there in the same way. And exactly when we talk about the standard that is used by OpenC many, many others, this is the basic thing. It's a JSON file structure.
When we have a name, a description, the image that can be uh a URL or no, and some kind of attributes that we are creating today as well. And in the same way, uh, you can store the metadata off-chain, like using IPFS or in any URL, or you can store on chain. Today we are starting on chain as well, including doing string manipulations to create our metadata on chain. And the last point before go to the practical side is the concept of a dynamic NFT.
Because at the beginning, everyone thinks that the NFT is something static. You create and you be the same all the time. But I like to say that uh I am a dynamic NFT. And you are a dynamic NFT as well, because we are unique. So everyone, uh each of us has your own DNA, so you are unique, but we're changing all the time. We are being older, I hope to not be fat, but my body is changing as well. So I can't say that I am a dynamic NFT because I am unique, but in the same way I'm changing all the time.
In a collection, it's the unique ID, but can be updated, even the metadata or even the image itself. And this is some examples to you related to that. We have some NBA game and N EBA player like the Lamelle. Uh, they have a uh he has a dynamic NFT that change the scores according with uh when he plays. And you can define any rule to update your NFT. I put some examples over there.
And uh in the same way, I already talked about that. So let's go to the practical part. Our dynamic NFT today, it will be a cross-chain NFT. So this will be another approach. And what I like to do, I'm creating an NFT collection in one blockchain. It will be Ethereum Sepolia. Then I'd like to mint an NFT on this collection being another chain. I will be in a Valanche Fuji that will be faster to us now. Okay, and you can do this in any chain.
And my NFT will be something like that. So the first one, the background color, you change according with the source chain. When I'm minting from Sepolia, it will be blue. If I'm minting from uh Avalanche Fuji, it will be red. I was minting before from Mumbai, Mumbai is dead now, but it was purple, could be a moine now, and some others. You can see that I have faces like said and happy and neutral faces, and these faces are based in the BTC price.
So I'm getting another uh different point over there because I'm using the chain link data fit to get the price of the BTC and compare the price with the last time I minted an NFT. And if the price is the same, I'm neutral. If the price is high, now I'm so happy, or if the price is down, I'm set. And this is we are creating an NFT that the image will be based. And the emoji itself depends on the Bitcoin price.
So I told you that I'm using data fit. And all the references are in the presentation. So let's go forward. And let's start creating the first smart content, then I talk about interoperability. So in order to do that, you know that you already did this part. And by the way, maybe you need do you need the Ethereum Sepolia or you are good on that? Good? Okay. So for now, let's go forward.
Let's start on Sepolia. And we are using remix. So I'm copy and paste this from other uh like my personal notes to be faster with you. And I will ask you to share this with me if you you can. And the idea is I can add here the code that I'm using, and I am on a Trium Sepolia. So I'm creating this file now. This is the cross-chain price NFT.
And if you don't create all of them, maybe you can create only the last one. But let's see if you can create that. So I'm here in the second icon, create a new file, and here I can create this: the cross chain price NFT. Is that you are creating that? Uh the code is here. Okay. And let's deploy and I'm explaining what I have to you. In order to deploy, I have no idea.
Yes, I think I am on Sepolia. Yes. And but not here, the environment. Remember that in the icon number five, deploying the run transactions, you must connect with MetaMask, use the injected provider. So environment, injected provider. Now I am connected. And I can deploy my NFT. In a few minutes, I you see my NFT over there.
I have some pinned, but it's not that. You must check the deployed unpined part. And yes, now I have it. If you are doing with me, please could you share your NFT with me? This is mine. And okay, let's see our content now. What I have. And then I'm importing the chain link aggregator interface to use the data feed.
So this is uh when I'm importing this interface, I can have uh an address, an address, and I can have a pair. So for me, I like to get the pair between BTC and USD looking on Sepolia. After that, you can see that I'm managing the counter, and this is my uh codes, my uni codes that I'm using here, and I have the price indicator that will be the last one. And I create a chain struct. So remember that I can mint from different chains.
For each chain, I'd like to have a code that will be a code from the CCIP documentation, the name like Sepolia or Fuji, and the color that will be the background color. And this on my struct, I'm initializing this in the constructor, like I have the cross-chain price. And here we are, Sepolia is blue, Fuji is red, and I have a base sepolia as well on black. And I'm here I'm initializing the Sepolia BTC USD and minting the first NFT.
So every time that I'm minting now, here I'm minting the same chain. So the mint is going to the mint from uh with the zero. That is the Sepolia chain. And the mint from exactly get the chain and update the metadata that is the important part for you. On the metadata side, you can see that I'm creating an SVG. We are going over that in a few minutes. But let's see how can I create a JSON exactly inside my smart content.
I have this ABI encoded pack, and I can encode and concat uh the string. So I'm creating the JSON file over there, the name, description, the image that's you come from the build SVG, and the attributes over there will be the chain and the latest price on Bitcoin. After that, I have the build SVG where here I'm using the color to have the background color and the emoji itself. The price is up, down or nothing.
And here is the compare price to define which emoji I'm using. This is the collection itself, and I have over there different points that can be interesting for you because it's a different approach. Oh, I'm doing a loan, you didn't create your NFT. Oh, okay.
I'm going forward, but I'll be happy if someone shared this with me as well. So, in order to move forward, um, I'd like to I told you that I like to use CCAP. It means that I must have a contract on this chain, prepared to mint the NFT, and prepare to receive cross-chain messages. This will be the cross-chain minter. Let's get the cross-chain minter for you. Or if before that you'd like to see your collection on OpenC, it's working.
Oh yes, I have one more. Thank you. I love you, you are with me now. So I am on OpenC now, and this is my collection. By the way, the first NFT is always happy because we are starting from zero. So must be happy. And here we are. I have a happy face and a blue one because came from uh Sepolia. And if I move forward now, I can I will not mint more NFTs now. I I have uh the time is not so uh good.
This is a fast workshop. So now we are going here to create the cross-destination minter. Okay, and I have it here, so cross-destination minter is that you can copy and paste from here. Okay, copy and paste here, okay. And here, in order to deploy this, I must add the address of my NFT that I create in the step before. I'm deploying it first.
So let's go to the deployment during transactions. Copy the address of the NFT, and come up here cross destination minter, paste the address, and click on deploy. In a few minutes, I have this done. So this is a smart content that I interact with my NFT and the mint NFTs for me. But we are in the same chain until now. The next step will be the cross-chain part.
Yes, I have it. And this is mine. If you'd like to try mine as well, you can. It's public. And what I have here. Here I have the I'm importing the CCIP part to, and this part is to receive messages. So this content is prepared to receive a cross-chain message. And this is the receiver prepared to that. And I'm using the client as well. It's only to get the structures that uh chain link CCIP use.
And I'm interacting with my NFT, but I don't need all the functions on my NFT. I only need the mint from. So I create an interface only with this function. And when I pass the address of my NFT, I'm using this. Over there. Here we are. I'm creating the interface. And the only point here that is important is this the underscore CCIP receive. It's a function that you must have it if you are using the CCIP to do cross-chain transactions. And I'm getting here, this is the important part for you.
In that NFT, I'm calling wherever what I have in this data part of my message. And what do you think that I have here? It will be the mint command. Yes. So I'd like to mint the NFT here. And in order to have to be sure that this is working, I created this function here in the same chain, but this is what I'm calling from the other chain in five minutes. This is my message.
So this is my message.data. And what I have over there, I have the mint from the address who is calling the transaction. And here I'm still on Sepolia, so I'm using zero here. And it's the same. You can see here that I'm calling the NFT address and with this mint from function. And this is I'm doing this locally now, but I'd like to do this from another chain in one minute. And this is if I'd like to change the NFT when I'm doing tests.
So I already deployed. And on Sepolia, uh it's not updated so fast like the main chain, so probably I have the same price now. So in a minute, I should have a new one. And then let's add it to you the part.
Yes, I have a new one here. If I came here, I should have two now. Not yet. Probably I need more time here. But let's go. Hey American. Thank you. I'm so happy that you are doing this with me. And let's go forward because now we are going to Fuji. Remember that I asked you to configurate Fuji in the beginning. And now we are doing this part here. So what I'm doing on Fuji.
And so take this to be better for you. Not copy. And now I must interact with my minter in the other chain. So remember that we must uh update the chain. So let's go on my MetaMask and go to Avalanche Fuji. On Avalanche Fuji, you must have the Fuji token to deploy it. And you must have the link token because when I'm doing cross-chain transactions, I'm paying the fees in the Cersei blockchain. I can pay using the Nativity token or I can pay using link.
I decided to pay using link. Yes. Okay. I'm sharing a secret file set if you now. Don't share with everyone, please. Don't put on your GitHub or your Twitter. Um and we used to change this password frequently. So for now, this is the password. And let's go to the right faucet because you need to go to Fuji. So go to this faucet now.
On Fuji, you can see that I have no, I still on Sepolia. I shouldn't. Oh, this was alright. Okay. So here you can get a bit of link and a vax. Oh, I don't have a link over there. Maybe I try to get you later. Link you you can get in the normal faucet, the faucets.chain.link. Okay. But the other is hard. So this is to help you.
Okay, this is the faucet. So let's go. I'm moving forward. I must uh update my chain. So change now. Yes, I am on Sepolia. I must create this now. Let's open it first. Uh this is the cross chain destination minter. So this will be in the Cersei blockchain. And I must deploy it now. Let's get the destination minter.
And I must use that here because in one chain, this content is communicate with the content in the other chain. So I'm deploying this on Avalanche Fuji and this content. You communicate with the other destination mentor on Sepolia. It's done. This is fast, it's good. So this is mine. You can use mine if you like it. Let's see if now I have it to here.
Yes. And like I said before, I was not expecting that the price change on this time. No problem. And I'm ready to uh do that. I'm first in doing the transaction that then I am explained because it is we need to have like some minutes, four minutes, and the workshop will be finished. So uh what I'm doing here, I'm using the mint on Sepolia. Remember that I am on a Valanche Fuji and I'm minting the collection with other chain. No, I can't.
Why I can't? I forgot to send the link to my content. So send the link to your content first, and now I can. How I can do that. So copy my Cersei Minter, K me to MetaMask. I added over that the way that you can add the link here as well. Paste it. This is my content. Five is too much, but I'd like to be sure. And okay, after I have a link on my content to pay the fees, now I can mint it.
So mint on Sepolia. Now it will work. And okay, let's understand our content on this moment. Like here, um, and I prefer to come here a bit to you understand what is the cross-chain interoperability protocol. Uh remember that a blockchain, it's an isolated network. And uh, if I'd like to communicate between blockchains, I can send tokens, but I can send the message. This is what I using now.
Maybe if you you can send uh ERC20 token and then uh lend your boring or stake in other chain, you can do that as well. But our goal is talking about messages now. And this is what we are doing. So we start in the end. We create the NFT, then we create the destination minter. This destination minter, you uh calling its uh it's communicating with the router. This is the off-chain part that's the CCAP part, and we just create the Cersei Minter where I have an application. This is the Cersei Minter that is sending the message to the router telling which is the destination chain.
So we did this now. And uh all the information that you need here related to the requirements as well. And uh like now I must wait four minutes to have my transaction done because I'm in a real network. If you like to do this local, uh, you can use the local simulator that it's same second, it's only to simulate this, okay? Like this is the simulator. And uh let's go here again because I'd like to see me uh my transaction. My last transaction that was the mint is here.
I'm copying the transaction ID, and I'm going now to the CCIP explorer and paste the transaction. And you can see now that is blessed. I know that IRA passed the phase that is the CERC finalized. That moment that your transaction is in a block. There are many blocks after yours. And we are sure that this will not be here, and your transaction is not disappeared. This is the point.
And like if you are sending money, you cannot do a double spend, something like that. Okay. After the blessed, in a few minutes, we have the commit and then the transaction in the other chain. This used to be from Fuji to Sepolia for minutes. So we have more time. And I can come here to explain more for you now. What am I doing here? Handle like the errors that I can have. And this is an important part for you. You must get some configuration related to the CCAP. So I'm getting this here from the supported networks.
My router is this address. And I'm paying using the Licking token. And I'm going to Sepolia. So this I got from the documentation as well. The chain ID is not the chain ID, but the destination chain selector is that. And when I'm clicking on Sepolia, what I'm doing here, I'm creating the message. So it's going to the destination minter, my wallet. And the messages that you saw before.
I'm using the mint from command calling from another chain now. This is my address, but now I'm not on chain zero. I'm on chain one because this is Avalanche Fuji. Remember that list of chains. And this is a tricky point. This is I must increase the gas limit, otherwise I have an error over there. And is this I mean I'd like to be sure that I have enough fees to pay that, enough link to pay. I'm uh checking that.
The router is calculating the fees for me and send the transaction. Is this because I send the link to my content? If I'd like to withdraw the remain link later, I have this part. And let's come back here. Yes, it sucks. So if I came on my collection now, I should have a red NFT. Yes, I have it. And like I said before, the price didn't change too much now.
Uh this is normal because uh we are on on Sepolia, it's not updated so frequently. So like the price is updated by time, like on Sepol, it's every hour, like on Mainnet, it's five minutes, something like that or less. Or if the price uh change more than 0.5%, probably nothing of this happened now on this moment. But is this if I open this NFT, you can see over there as well that it's came from Fuji, and this is the price now 58,000 something. Okay.
And uh I think I only finished something here in the presentation for you. I have more information that I could talk about, but imagine that you can uh create an NFT with information related to external APIs, uh, calling a JavaScript code inside the Ordismatch content, you can do that. I was creating one uh related to the weather. I cannot show you now. It was so fast. And if you are in the hackathon, we have some prices in the hackathon. And we have a conference in Hong Kong in October.
I have a 50% discount for you. And again, if you need the presentation, is this? And my time is finished. Thank you so much.
Related talks
- Tips and Tools to Create Dynamic NFTs
- Build a Dynamic Asset Monitoring NFT by Solange Gueiros
- NFT Interoperability with Shane Vitarana of Stargaze
- Dynamic NFTs and real-world utility with Chainlink
- Dynamic NFTs
- Polygon 🛠 Create Evolving NFTs with On-Chain, Mutable Data - Steph Orpilla
- Beyond CryptoKitties: building tradeable, interoperable ERC721 digital assets by Devin Finzer
- The Interaction of Oracles and Real NFTs
- NFT Metadata