Tellor School – How to make a dynamic NFT using the Tellor oracle 

By Tamsay | Tellor | 5 Aug 2022


Links 

Youtube link: https://www.youtube.com/watch?v=SNfkvbX-bH0 

Official links: https://linktr.ee/ 

 

Summary 

Hey everyone, welcome to I think this will be a Tellor school. I'm going to teach you guys how to create a dynamic NFT using Tellor. So, for those of you that don't know what a dynamic NFT is, it's actually just an NFT that changes based on something. So, in this case we're going to have we're going to create an NFT that changes based upon a price. So, obviously from the Tellor network. What I wanted to do was I wanted to make an NFT that once you minted it grabs a start price from whichever ID you want and then if the price goes up it's one picture and if the price goes down it's a different picture. So, you know green if it goes up right if it goes down super simple. And yeah, I'm going to show you guys how to do it so first off you will go here I am walking through in a lot of ways. So, I'll put this in so I'm not an NFT expert but Namya, she apparently is and she wrote this awesome tutorial and I'm basically doing everything in this tutorial the only difference is I'm adding the Tellor specific piece. So, if you have any questions, I'm going to post all of these in the links you can literally just walk through it if it's a specific solidity code question that's where you would ask me. But the first thing that we're going to want to do is you will want to upload your images to ipfs. So, you need a place to point them and. So, I uploaded them here. So, I use in our crypto you can just upload them here just drag and drop your images and then you'll get it's going to give you these paths so these are this is how you would do it and then what you have to do is come and create what's called the metadata for the NFT using those. So, the metadata for the down picture is this metadata structure this is very similar or this is sort of what Opensea wearable they all need to see this metadata in this format. So, you can just either copy mine they have lots of ways to do it you can put different attributes in there but the big thing that you guys are going to want to change is this this ipfs image link. So, you would go and from the picture from the ipfs picture that you wanted you would post it in there and then you would go and it looks almost identical this is the metadata for the up picture you would want to put your up picture in there and now what you're going to want to do is go take this file. So, these are json files and you're going to want to upload those to ipfs. So, that's actually what Opensea or any of them will be looking for they'll be looking for a file that looks just like this and then it will describe all of your pieces so you would come here and you would upload metadata down.json metadata up.json and again you're going to need these guys so now let's go into the code. So, this I'm just using a standard uh hard hat repo here nothing special about it you're going to need to do an npmi on two things. One is using Tellor and the next you're going to have to [email protected] and that's going to bring in all of the open zeppelin contracts and we're here we need the erc721 contract and the 721-storage contract. And that's what we'll be using as kind of the base of our NFT. So, now let's kind of just give sort of a basic walkthrough of the code here. The big things that you're going to need as far as storage goes. So, you can see whenever you're doing a constructor, you're going to have a token name token symbol for your nfc and then you're going to need a Tellor id so what's a Tellor id? This says like what price you're going to have so I can show you guys how we make these so in in the tests how we would make its query id here basically it's just the encoded. So, you would use adi.code and then we're going to do spot price and then it's etheusd or you can have a different coin etc/usd depending on which ones you want to actually look you know Tellor update certain ones but you can even request your own if you had your own cryptocurrency and this is obviously just for a spot price so that's how you would create it. So, it's the hash of the encoded spot price btc usd for us we enter that in the constructor and we'll kind of show you that in remix whenever we do it we can show you how to get one too if you're easy there's lots of places online you can just grab the current ones and the last one is the Tellor address. So, where do you get the Tellor address so we can go to docs.Tellor.io contract references didn't actually go there and then here there's ones on mainnet Rinkeby. So, you're going to want the oracle address here, but for this is testing if you're on testing which you want to use is the playground. So, the playground is one that you can actually go and update your own. So, you can update the price whenever you would want so what we'll do is let's kind of go and I'll show you guys how to do that. So, this is the Rinkeby I actually have it up here and you would want to come down connect and then you can submit a value. So, we're going to have a start price so we'll just do yeah. So, zero this will be kind of our start price so you need a query id. So, this is the query id that you're going to be submitting for this one I picked Ricochet RIC the RIC token Ricochet is a user of ours over on polygon they do dollar cost averaging go give them a look we'll be using that price the query data you'll also need if you remember in the tests this is uh the query data. So, it's just the avi doesn't coded spot price for me it's rick usd we have a query builder in our docs too. So, if you just go in the docs, it'll teach you how to build that but then yeah then we'll write it and we'll update it should be we'll update the price so I'm down here. So, we're on rank fee we'll confirm it and this is going to give us our start price the nft you didn't want the start price to be zero because then it's always going to go up because I don't know if anybody's ever requested the RIC price on the playground so we're just making sure. Anyway, back to here go back to our code that's the constructor you got everything you need and then I basically just have two functions that you're going to need to worry about here the first one is mint token who are you going to link it to pretty standard stuff but underneath the hood let's see what it's doing. So, it's going to actually query here get data before from Tellor. So, since we're in since we did npmi using Tellor you put in a constructor using Tellor up there we're inheriting it. So, we have this function called get data before now you're like what is get data before this grab the Tellor value for the Tellor id at. So, we're making sure that it's at least 10 seconds old usually in practice you want to make sure that it's five minutes old an hour old because that's actually how Tellor works it's kind of optimistic in that sense once somebody puts the value on chain you wait a certain period of time check it yourself for a dispute. So, some usually they're pretty quick on catching disputes themselves the other reporters will and then they'll dispute it but you don't want to use it right away. So, you want to make sure it's a little bit old since we're just testing and we don't actually care we're just going to make it 10 seconds. So, we're going to make sure that we get it and then we're going to decode the value and this is our uint value so that's going to be that price that we just did and it's going to make the start price. So, our start price is the value and now we're going to go and we're going to mint it we're going to mint it and then we're going to set the token URL. So, we're going to set it to the metadata URL up so if you remember we had created that and we uploaded it and this is a variable so this ipfs link this is the same as it's at the time metadata up right here and then metadata down is obviously the other one and you'll see how we use that. So, this mints it and now let's say fast forward some time oh no the price the price went down from there let's go and we'll update our URL you just enter the id obviously if you're the first person to mint it which we will be we're going to have an id of one it's just the number of tokens here. And what it does is now it's going to check the Tellor data again and it's going to see did the price go up from the store price then set it as URL up else set it as URL down pretty simple things we're obviously just going up or down but there are some you know you could write really complicated ones you could have a rank of you know you mean 10 NFTs and then you rank them based upon some value or you could have you know 100 of them and you can have it get cooler as time goes on you know if you got in really early coin or something like that lots of different ideas that you can do with it so anyway so I also wrote some tests for this. So, you can just run npx hardhat test and it will run these tests test my two functions make sure that they work I know we're doing live coding here. So, we'll just npx hard hat test make sure that that guy works see it's up testing token in the URL it works it's cool and now what you're going to run is flatten. So, I'll just show you that guy whenever you run flatten since there's a lot of inheritance in here it's kind of hard like how do you deploy this like we could ever see to play from a script right here and that would be. Cool but I wanted to show you guys using remix makes it a little bit easier for a lot of people just getting into it so if you run flatten it kicks out this flattened soul file and this is the using Tellor all of those 721 contracts all in just one giant file you know and then you can see down here at the bottom this is our here's this guy dynamic kind of t down here at the bottom and then what you're going to do is you're going to cut and paste it or copy it I guess right now and you're going to come over here to remix and you're going to paste it here. So, I already did that make sure that it worked but that's all you're going to be doing and now that you have your code here it has those URLs. So, the up and down already hard coded in what you're going to do want to do is deploy it so you'll come down here you'll well first you'll come here and compile it and then you'll come down one more and you're ready to deploy it now it's going to take some constructors which we had talked about so you're going to need a name I'm calling this one Tellor dynamic NFT symbol td Tellor dynamic and then it takes two things. So, a query id I'll post some for you since we're actually on the playground and set them you can just actually set it to whatever yeah it doesn't have to be a specific one and then you're also going to need the Tellor address. So, for me I have the playground address here that we can update so let's go okay. So, we'll just click deploy here we go now we wait so while it's deploying lots of fun things that we can do. What you want to do now is actually we can go we'll go over to Opensea so Opensea that's the biggest NFT marketplace and this is my account two this is who we're going to mint it for copy him he has nothing he's an NFT noob we should send him something as you note if you go to normal Opensea this isn't going to work because you're not on test and start Opensea but we'll go back to remix and let's mint him a token. So, you see dynamic NFT down here came up we'll go to mint token and it just needs an address. So, we're going to paste in his address and rent him a token by the way I don't know if anybody's talk doesn't use this code in production there's like no controls on how many you can mint how many anybody can vent have to do a little bit of work before it's ready for that but they're really cool. So, you can get a test that's different from um anyway. So, that seems to go through so now we have an NFT let's go see if we have an NFT it might take a minute I know. Oh, I was on my other account so how do I refresh this guy now everybody's going to be like you didn't actually do this. So, while this is going on. So, this will take a second here because test nuts are always kind of slow ah there we go. So, I collected one all right so you can see this is my NFT. It has Tellor dynamic NFT themandalore this is if you remember from our metadata up that's what the base is the name is themandalore they're both actually named Angela but yeah super cool. So, we just minted ourselves in NFT that's kind of cool but anybody can invent themselves in NFT the cool thing is when it changes. So, how can we get it to change so let's go over here. So, what we're going to do is we're going to change it so we want it to go down in price. So, how do we make it go down let's just change some of these values to zeros and then I know it's in bytes and like hex so it's like man this is never going to work anyway. So, I'll just write it zeros almost always go down wow and we'll wait for that to mine and then we'll come back to remix fingers crossed this actually works we're going to come down and we're going to update our URL so if you remember what's our id what does it have an id in here, I don't know where you can tell the id there oh it just says one yeah that's id1. So, id1 and then we'll run update URL before that one confirms what you can do is you can come down here and check it already confirmed. So, we'll see that one should be the down one now so URL uh but let's go we'll see how long this one take refresh if we check back in a minute okay so we'll check back in a minute but fingers crossed this ah it worked. So, as you can see now it's red so I changed it from green to red that was the cool thing I wanted to surprise you guys but not showing you the pictures yeah. So, that's kind of the entire walkthrough hopefully you guys learned something here hopefully it sparks some imagination some things that you can do and the cool piece about using Tellor. So, like obviously you could make NFTs that you can just change the picture on which is sort of also cool now you can have NFTs that change in a decentralized way so you know that somebody can't tamper with this price if you're you know actually going on a real Tellor now on a real Tellor contract because Tellor's in charge of it, they would get disputed so these NFTs you know if you had them change in color as you know the price got went higher and higher you would know that it's done in a decentralized way and it could be like a proof that you bought earlier. Obviously, there's other things that you can do as with Tellor does cross chain calls. So, you could make NFTs that have to do with bitcoin transactions that you did all in a completely decentralized way lots of different cool ideas, if you want ideas, I have plenty of ideas, definitely reach out, but yeah thanks everyone for watching hopefully you guys found this cool. 

 

How do you rate this article?

11



Tellor
Tellor

In this blog I will post transcriptions of videos made by the Tellor team.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.