Current location: Current location: Home > cs > Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep23 Text
Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep23
[cs] Time: 2025-07-11 11:26:53 Source: AIHackNode Author: rust Click: 13 times
firstcontract now solidity has multipledifferent types or ctmu explainedprimitive data typesand if you go to the soliditydocumentation which again is in ourGitHub repository you can read more andlearn more about the different typesthat are in here the four most basictypes are going to beBoolean uint int and an address or byteswhich is a lower level type which we'lltalk about a little bit later Booleandefines some type of true false a uintis going to be an unsigned integer whichmeans it's going to be a whole numberthat isn't positive or negative it'sjust positive we have an integer whichis going to be a positive or negativewhole number and then we have an addresswhich is going to be an address likewhat we see in our metamask here thereare some other types as well that you'lllearn later on the reason that we havethese types is we use them to Definewhat different variables are variablesare basically holders for differentvalues for example we could create avariable called hasfavorite number to represent if somebodyhas a favorite number and we would putthis Bull keyword before has favoritenumber to say okay we have a variablecalled has favorite number and it's oftype Boolean so this has favorite numberis going to represent a true or a falseto set its value we could say hasfavorite number equalstrue now has favorite number is going tobe true we could also say has favoritenumber equals false so this Boolean hasfavorite number is now going to be falsefor uints we could say uint favoritenumber equals and then set a number 1 23 this means that our favorite number isgoing to be 1 2 3 uint is specialbecause we can actually specify how manybits we want to allocate to this numberbits and bytes are pretty fun m alpieces of information for computerscience we're not going to go over ithere however there's a fantastic videoin the GitHub repository that explainsit more basically it's how much storageor memory to allocate to this number howbig can it get if we say a uint 8 it canhave 8 Bits all the way up to uint 256if you don't specify how big it is itautomatically defaults to uint 256 oftentimes it's better when writing our codeto be very explicit so usually you'llsee me just do U 256 to represent a u256 we could also do an INT favoritenumber equals 1 2 3 or an INT 256 I'mjust going to go ahead and add thisBoolean back here we're going to changethis back to uint 256 and let's changeour favorite number to five here wecould also do something called stringsstring favorite number intext equals five strings representbasically words and you can representthem by putting them in these quotesit's going to be some word or phrase orreally really just kind of anycombination of keystrokes in here ourins can be positive or negative so wecould say neg five or positive five bothare going to be valid in we can also doaddress my addressequals and grab our address right frommetamask paste it in you'll notice thatwe end all of these lines of code withthe semicolon also have bytes objects ora bytes 32 again representing how manybytes we want them tobe and this says that we have calledfavorite bites and we're just going toset it equal to cat so strings areactually really interesting becausestrings are secretly just byes objectsbut only for text so cat is actually astring but can automatically getconverted into one of these byes objectbyes objects typically look like zeroxand then some random letters and numbersthat represent the bytes object but catcan automatically get converted down tobytes we'll talk about bytes more Inccoming sessions you could also do bytestwo bytes three bytes 5 bytes 22 you getthe picture for our and our in 256lowest we can go is eight bits becauseeight bits is a bite and we can go up bysteps of eight so we can do eight 16 32Etc all the way to 256 for example downhere we can't do byes64 and if we go ahead and try to compilethis we get a little red thing here andif we scroll down we get a declarationerror identifier not found or not uniquewhite 64 favorite btes equals cats andwe even get a little red warning signhere in ourremix this is remix telling us there'ssomething wrong with this line so we canswitch back to byes 32 since bytes 32 isthe maximum size that a bytes Can Be Youcould also do just a bytes object whichmeans it can have any size but wetypically want to be explicit and we'regoing to stick with bytes 32 for now ifyou want to learn more about thedifferent types and how to use them andall the different features with them besure to check out the soliditydocumentation for now for our simplestorage let's say we only want to storenumbers so let's go ahead and deleteeverything except for the favoritenumbersection now in solidity if I do this andI remove the equals 5 this favoritenumber actually does get set to adefault value the default value forsolidity is going to be whatever thenull value is which in solidity case iszero so saying U and 256 favorite numberis going to be the same as saying U and256 favorite number equals 0 since itgets initialized to zero so for nowlet's not initialize it to anything sothat favorite number will automaticallystart off as zero now if you getconfused as you're coding along andyou're following along with me be sureto write comments in your code so youknow what's going on so maybe forexample a great comment here would bethis getsinitialized to zero and then if that'seven confusing you you could say thismeans that thissection is acomment now let's go ahead and create afunction functions or methods areself-contained modules that will executesome specific set of instructions for uswhen we call it if you're familiar withJava or python or JavaScript or anythinglike that functions work the exact sameway functions get identified by thekeyword function let's create a functioncalled store that will change the valueof favorite number to some new value andthe number that we're going to
(Editor in charge: html)
Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep131GenAI Essentials – Full Course for Beginners - Ep31
Related content
- Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep234
- Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka [DownSub.com](1).txt - Ep14
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep8
- Harvard CS50’s Artificial Intelligence with Python – Full University Course - Ep1
- Harvard CS50’s Artificial Intelligence with Python – Full University Course - Ep4
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep92
- Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka [DownSub.com](1).txt - Ep25
- Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka [DownSub.com](1).txt - Ep5
- GenAI Essentials – Full Course for Beginners - Ep184
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep179
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep64
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep65
- Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep25
- Record turnout in South Korea election after failed martial law bid _ BBC News - Ep1
Wonderful recommendations
- Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep107
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep148
- Harvard CS50’s Artificial Intelligence with Python – Full University Course - Ep23
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep89
- Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep70
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep36
Popular Clicks