HOW NFT SMART CONTRACTS REALLY WORK - Can metadata be changed? How staking works?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
i will show you in this video what nobody shows you which is how smart contracts actually store your nfts what happens behind the scenes how is the metadata stored how does the contract actually know where the metadata is also you will understand how marketplaces like openc for example have the right the permission to actually transfer your nft from your wallet to someone else's wallet when it gets sold without you having to approve that transaction because let's say you were asleep at that time and that's actually vital information so you understand how it really works so you can take better care when you buy nfts but also when you sell nfts and you know who to trust and who better not to trust because you now understand how it actually works hey i'm michael and on this channel i talk about blockchain technology if that's something you'd like to know more about then make sure to subscribe to the channel and also throughout the video make sure to not hit the like button unless you hear something useful and interesting that's how we like to do things around here so without further ado get your coffee we are also coffee addicts over here did i mention that you are an awesome audience and you give me a lot of energy and without you this channel would be nothing yeah there you go cheers throughout the video if you hear something you want to know more about then make sure to let me know down in the comments all right first of all i want to talk about what nfts are made of and then dive into the technicalities of it and no worries i'm here to explain technical concepts in an easy way so even if you're not a tech person you will definitely understand what i'm talking about here and it will give you a much better way of analyzing nft projects after you watch this video simply because you know much more what's going on in the background and you can apply that knowledge when you're doing your research for an nft project okay i'm pretty sure you are aware that nfts are made out of layers they are put together and stitched together to create unique images which is why all of these nfts here bought aviator they all look different and the reason for that is basically that these layers are put together in a random way they have some kind of rarities so there are a lot of videos explaining you all of this stuff that's the stuff that you find all over the place now let me show you what actually happens in the background now in the background you have this nft on the blockchain so here's the contract of that nft by the way you can do that with any nft here on openc you just simply find the contract and the contract is also the address here in the url of openc now if you want to see the contract then there is for example etherscan you can click on this link here and that's where you're going to end up and then you see all of this gibberish here and those are all the transactions a lot of information but what i want to show you and to direct your attention to is the contract tab over here and you can see it has a green checkbox which means that the board at yacht club they open source they put their code here for everyone to look at now that's very nice of them to do they don't have to do that but they do it because it shows that their code is fine they're not afraid to show what their contract looks like a very welcome side effect of revealing the code is that etherscan over here can show you the contracts read and write functions and this is actually exciting stuff and that's what we're going to talk about now over here in the read tab you can see all the functions that allow you to read from that smart contract now for example so you see what i'm talking about if we want to know who is the owner of ape number 13 then we can simply ask the contract and the contract will say hey the owner is this address over here you can see that's a basic function because an nft smart contract stores ownership of a specific nft but now does it really store the nft or does it actually just store who is the owner of which id which is exactly what it's doing it's just storing that you own number 13. what kind of metadata is behind number 13 how does it look like which properties does it have which levels does it have you have no clue unless you understand the next function you have to know about make sure to hit the like button if you heard something that you didn't expect and didn't know before because that's the whole point of this videos and my channel to bring knowledge to your brain as easy as possible and also make sure that your brain has enough coffee to digest all of this crazy stuff all right moving on to the next function which is vital and necessary and the most important function when it comes to nfcs which is the token uri the token uri is basically a function that you tell which nft you want to get the metadata for and what it will return you is basically this uri it's an identifier for the tokens metadata where it's stored it's not a url because you cannot just copy this and put it in the browser because you don't gonna not gonna get far instead what you have to do is copy this part of the uri so forget the ipfs slash part just copy this and let me show you here how it's done and you just simply put ipfs.io slash ipfs slash so that's the url actually it's http https right so that's the actual url now if you copy this and put it in the address bar then what you're getting is the metadata of this nft yeah cool finally we get to the metadata but you know right that it's not part of the contract the contract is just linking you to a location where this metadata is stored okay where is the image now well the image is simply here and again ipfs which is actually cool and you can copy this part now and you can put it here instead of this other one right and you can get to the next resource and that's the image of the nft again it's far away from the smart contract the contract just pointed you in the right direction why am i stressing so much that the metadata and the image is not part of the smart contract well because when i first started with nfts i thought somehow they are close together so you cannot change them and so the nft will live forever well sure the nft can live forever but only if it's done right as you have seen in the previous section and also if the developers or the project owners don't decide to change stuff right they can always change because they are the owners of that smart contract now the only way to not have access to change these things anymore is to resign as the owner of that contract there is a function for that and they have to call it and remove themselves as the owner and so the owner becomes nobody and then you can't make any changes anymore but seldom nfd projects do that because they still have plans for the future and they still want to be able to make changes now as you can see over here the uri basically consists of a base part and this never changes even though when we put in here other ids then this part stays the same and only this part at the end changes which represents the id of the token so basically you can see the first part as being a folder somewhere and then slash 16 would be the file 16 and the file 16 will contain the metadata of that particular nft what does that mean exactly well it means that somebody stored in ipfs a bunch of nfts usually 10 000 or so and if you want to get there you have to know the path to that folder and this is exactly what happens over here and ipfs is basically a decentralized file storage it stands for interplanetary file system and i will show you on the screen right now the website but basically it's just a decentralized way of storing data it's pretty similar to s3 from amazon but it's decentralized meaning that nobody can shut it down and the files are all gone which would be pretty bad for nfts which is also why most nft projects are storing their data on ipfs or on the competition called are we now going back to the smart contract if you see something else over here maybe a https or something standard url to a server then keep in mind that this only makes sense when the nft metadata should change for example when you play a game and you can level up your characters other than that the data should be stored on ipfs or rv for something decentralized otherwise the data can change and without you knowing and that's pretty bad next time when you are researching an nft project you can now find out where they're storing their data and if they're doing it correctly okay that's all nice and all but how do they set this information in the first place because it's not part of the contract if we search for this over here then it's not like it's part of the code anywhere you see so they have to set it somehow from the outside and that's exactly what they're doing with one of these right contract functions so what they can do is they can connect to metamask over here for example and then they can trigger one of these functions that allow them to set this path and the path is set by set base uri and basically what they're doing is they're setting the base uri like this and clicking right and if i do that then i could do that but then of course insufficient funds that's one problem but the other problem is of course that i'm not the owner of this contract in set base uri as you can see here in the contract let me check it out set base uri is a function that can only be executed by the owner the owner in this case meaning the owner of the contract the one that has deployed the contract so not everyone can do that but now imagine if they had a bug in the contract and they forget to put only owner over here then everyone could change the path to where the metadata is stored so another function that you should know about set base uri which is also pretty much standard so that's how they do it and that's also the reason why they can change the path where the metadata is stored meaning that the metadata can change even after minting right now when we connect the dots of the information we just heard then this is a possibility and of course if they had any bugs in creating the metadata or creating the images they can still make changes by simply pointing to a different folder on ipfs for example where the nfts have been fixed but just keep in mind that nfts can change because of this set base uri function okay we know how to find out who's the owner of a specific id but can we find out how many nfts a particular address has in the wallet yes we can there is a function called balance off and let me copy this address over here and put it in balance off and let's see how many board apes this address has it has 11. honey i found a whale it's a lot of board apes this is also the explanation why your metamask on your phone has to know which contract you're trying to show nfts from because only that contract understands and knows the ownership and the urls and all this stuff which is why you have to click on import nfts on your phone and tell him which address of the contract do you want me to look into and then the metamask app would basically ask questions like balance off on or off token uri and all this great stuff in order to show which entities you own funny enough in the board api cloud contract sales is active is still true so why can't i mint anymore well because the minting function over here has this nice little little check here if total supply is smaller than max apes and max apes is a number they have set from the outside and max apes is basically this max supply that they have sent in when they have created the contract at the moment of creation they put in 10 000 in this case so what is this total supply function well let's check it out read contract and we have total supply and total supply over here returns 10 000 which means that that's the total supply that is in circulation right now if you want to know how many there will be maximum in this case it's this number here and because board apes have sold out they have sold all their nfts these numbers are the same now you might ask yourself can they still change max apes after the fact can they now sell another 5 000 or another 10 000 with the same contract well it's easy to find out you simply search for max apes in the contract and see if there is any setting of the variable somewhere down the line so the constructor doesn't count because it's only executed once when the contract is deployed but if you find any other max apes equals basically setting the variable somewhere in the contract then there might be a function but in this case there is no function which means that there is no way to change how many nfts there ever will be in this one contract which is what you expect let's talk about the juicy part of earning money for the owners of the contract and how they can get to that money how they can withdraw the money and as you can see here on the screen there is a function called withdraw and it doesn't have any parameters you can just basically invoke it and it will pop up a meta mask and i will not have the permission to do that but what does it do well it basically transfers the balance of this one contract here and they did that already a long time ago and sends it to the owner's address now let's see how the code for that looks like so it's called withdraw and so the withdrawal function basically only owner which is good right anyone else could just um steal the money otherwise so the balance is this balance of this address of this particular contract and in this case it means also that the contract earns the money so the contract holds all of the ethereum and the contract has to have a function to hand it over otherwise it's there forever and i've seen contracts that have forgotten this function and that means that the money is locked there forever and that's of course not ideal because the project needs those funds to continue on the roadmap and continue investing into the project but this function has to exist in the contract and usually people just copy the function from some other guy's contract and use it in their own but in any case it has to transfer the balance to the message sender and the message sender could be anyone but only the owner can call this function so only the owner will get the money you can do this actually in a more secure way but whatever this is not a coding video maybe i should do one let me know down in the comments but this function is mega important it always withdraws the whole balance of the contract you see here withdraw withdraw so this is the way the project gets to their funds and check this out 400 ether over here they must have been very happy about that all right another thing that you should know about is how staking of nfts works because that's becoming kind of a trend right now now let's go to wizards and dragons again i don't want to find the contract any other way other than the legit way so that's the official collection that's an official nft if i click on contact address over here i will arrive on the official nft contract right so here again i can click on contract and i can see the code and well i will be a bit faster on this one because it's pretty complicated but long story short what they're doing over here is they have multiple contracts that work together in tandem so you have an nft contract just storing the ownership and the metadata pointer to the right place and so on but they also have other contracts that play together with this one and for example they have one for storing the staked nfts and here i think it's called tower and you see here the variable basically points to another contract so if i go to the tower over here and by the way they can change this address and point to a new fresh staking contract but of course it comes with some ups and downs if you want to know more about that technically then let me know down in the comments and then here in the contract there is a function that is called stake add many to tower and flights whatever the name is and the interesting thing over here how staking works so check this out is basically that what it does here it calls the nft contract the original one and calls transfer from and transfer from is a function that is standard in erc20 so there is a function called transfer from now you can transfer an nft from one address to another address and you can say which one now not everyone can do that right that would be a security risk but in this case what you're doing is telling him hey transfer my nft number whichever i told him and this is me right the message sender and transfer to address this and address this is this contract over here the tower contract which means now that the tower owns your nft so it's the owner of your nft and that's fascinating to understand because it means also that the tower has to remember who is the original owner so when you get it back out of the staking contract it will look over here in the owner and he will send it back to you because it was yours but because it's not yours while it is staked you cannot sell it right so you're not creating any selling pressure on the collection which is fascinating stuff i will not go much deeper into this because it's pretty complicated but one thing i still want to show you is basically how you can get rewards from staking of course every project can do it in a different way but the essence is always the same so now after i've added myself to the staking contract the staking contract has remembered who i am and then there is something called a claim function or unstake function whichever and in this particular case here there is a reward calculated and the reward is calculated somewhere here and calculate rewards basically and here it calculates based on time stamp whatever but the interesting thing is that there is another contract in this case which is a coin they have their own coin right erc20 and it gets minted to your address gp token in this particular case so whenever you claim some something back from the tower and you want to have it back or you want to just claim your rewards then what will happen over here is that it will mint you some of those tokens of course this this erc20 token has been written in a way that the administrator which is them they can mint as many tokens as they want so that the gameplay keeps on going but this is how it works so there are some basic functions that every smart contract has to have when it comes to nfts and tokens which is minting burning transferring and of course ownership information and everything else is basically just additional stuff that makes the project unique all right you've gotten a ton of knowledge in this video make sure that you put it to good use now you understand the basics of how nfts are created how the code looks like and that the ownership is the most important thing that is stored in the contract the assets are outside of the contract and they can be changed anytime especially when you're playing an nft game then of course the nfcs will change all the time so the metadata is constantly in motion of course that also means that you have to have trust to the team and the developers that are actually behind those smart contracts the smart contract contains functions in order to look into its data set and understand who is the owner of what and also what are the variables set to for example the max supply and stuff like this and there are also functions to write into the contract which happens when you mint when you burn when you transfer all right i hope you liked this video and if that's the case then make sure to also watch this video or that video whichever i will put up there but make sure to suck up all the knowledge that you can get before you run into any issues until next time cheers [Music]
Info
Channel: Michael Ionita
Views: 24,844
Rating: undefined out of 5
Keywords: launch, create, tool, easy, fast, howto, how to, business, learn, build, blockchain, nft, solidity, evm, smart contrat, secret, secrets
Id: Wu436_IwWmo
Channel Id: undefined
Length: 19min 56sec (1196 seconds)
Published: Wed Jan 19 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.