New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Structs

BaseMon, Oct 9, 2023, 12:00 AM

Level up your Solidity skills by learning about structs 📚💪 In this exercise, you'll discover how to define new types using structs and store more information about users in your smart contract. By the end, you'll be able to create powerful data structures to enhance your Ethereum projects. Let's dive in and build more advanced functionalities together! 💻🚀 📚 Head to Base Camp for full courses on smart contract development: https://docs.base.org/base-camp/docs/welcome ✅ Subscribe to our channel here: https://www.youtube.com/@BuildonBase ► Build on Base: https://base.org ► Follow us on Twitter: https://twitter.com/buildonbase ► Join our Discord: https://base.org/discord

Transcript

in this exercise we are gonna learn about Strokes which is a way to define new types in solidity okay let's go to remix let's first clean the environment and we're gonna create a new file called structs okay then we are gonna copy the pragma and the license let's create a contract called extracts okay now if you remember in the advanced storage lesson we allow users to register in our smart contract what we're gonna do is we are gonna take this code we are going to put it in our contract however now we are going to allow users to register more information about them okay and to do so we need to create a stroke and we're gonna call it user okay and now we can Define types inside this structure for instance we can store the age and we can also store the name of the user okay now instead of storing here simply the age we can store the user and let's rename this mapping to be called users okay now here we are going to allow the users to pass the age and also a stream for their name all right and when we are restoring the users with the key MSG sender and then we are going to say user age and name okay so we are saying to the mapping users with key msg.sender I want to assign the value of a type user that is gonna contain these two values all right and here we need to specify in the string memory all right and now is working okay so let's test I'm going to deploy the contract and now I'm going to register by passing my age and my name transaction and now I'm going to access the value to see what I'm gonna get yeah all right and as you can see I'm getting H and name all right then let's go to the next exercise

Automatic transcript — names and jargon may be misspelled.