In this video Emmanuel Henri explores the basic types available in Solidity.
- [Instructor] Solidity is aesthetically typed language. In other words, each variable types must be specified. So, let's take a look at the major types. So, let's erase all this and let's start with the string type. And it's basically string and then the name of your string, and then, if you want to initialize it, you can put a string. So, you could do simply declaring or initialize it, as well.
Then you have integers and you have the uint and you can initialize like we've done before. So, store data at 34. (mumbles) Perfect. And then you have also boolean and you declare it with bool and then the name of the boolean.
So our true or false value, and you can initialize it with false or true. You have also what we call an address and this is really something that's useful for solidity or ethereum because you have addresses all the time, and they usually are called wallets or wallet address. And they usually come in a bunch of numbers and characters that looks like this, 72 and a whole bunch of numbers.
I'm just typing anything. Like that. Then you also have arrays. An arrays can be declared in any of the types like integers, strings. And simply put those characters in there to declare this as an array. Then you have the byte type. And bytes can come in between bytes.
So the way you declare bytes, you can declare bytes like this, which is dynamically and will basically initialize with what you've put in the value. You can also specify the number of characters or the number of bytes this way. By doing from byte one to 32. So, if I were to do bytes 32 and then call this code, this is how I would declare it. If you want to create and declare you own types you can do so with something that's called struct.
And that's very familiar for some of you that have done other programming languages. And you would define it like so. So, struct and then the name of your structs, so if we create a user struct and what you pass as values inside that struct. So, for example, first name and then a string of last name. So this specific struct would take a string of first name and a string of last name. You also have enums.
And enums are pretty much the same as any other programming language that uses it. So user, type and then you define what are the user types. So a buyer and the seller and close your braces, like that. And a final one that I wanna talk about are mappings, which are pretty much like dictionaries in some other programming languages. You have a key value pair that goes inside and you can define your mapping this way.
So, takes an address, which takes an integer in public or private and then a name of your mapping. And we'll do a mappings when we create a contract in the next chapter. So let's move on.
- Installing Solidity
- Solidity programming basics: types, variables, functions, and conditionals
- Creating a smart contract in Solidity
- Setting variables
- Adding modifiers
- Finalizing functions
- Testing your contract