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

Loading player…

Imports

BaseMon, Oct 9, 2023, 12:00 AM

Import and use code from another place in Remix, specifically importing files from the OpenZeppelin library. You'll see how simple it is to extend data types from the imported library and utilize its functionality to create and manage data sets. This will help you leverage existing code and improve your smart contract development productivity. Don't miss out on this powerful feature! 📚💻 📚 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

all right in this lesson we are gonna learn how to import and use code from another place in remix in this case we are going to import files from the open sapling Library and we're gonna see the actually importing functionality is a simple as saying import and then we simply paste that bar okay so if you notice when I said import and I pass the URL that ends being a file in GitHub because it has the extension.sol the remix environment is actually bringing the whole structure and in fact we are getting access to this particular file which is a library called a numerable set okay let's just start by creating a contract and let's call it import and what we're gonna do here is we are going to make use of this Library called a numerable set and the way we use libraries in solidity is simply saying using a numerable set which is the name of the library 4 and here we are going to refer to a structure within the enumerable set Library that is called address set address set okay dot address set all right by using this Library we are essentially extending the address set type and it's gonna allow us to access the functionality specified in this Library so we are already Italian to solidity that we are extending these enumerable set dot address set type with this Library now let's use it by simply doing a declaration of let's say a variable called visitors okay and what we're gonna do here is we are going to create two functions the first one is register visitor let's say it's going to be external and what we're gonna do is we simply gonna say visitors at MSG dot sender okay and that's it so what we are doing here is essentially if you notice visitors is a variable of type enumerable set dot address set so this is a variable that this is the type but now we have access to the add function this is because this using is extending this type and now when we look at this Library we now have access to the functions like let's see and now we have access to in this case add remove contains and Len also add values and so on okay this is because this library is extending this particular data type all right so it's currently working so the expectation is that if a party comes and call register visitor we are essentially adding visitors to this address set let's include another function to verify to verify let's say number of visitors let's just make it external View and returns let's see a uint and then if you remember here we have access to Lan that is a function so we can call it here we can say return visitors Dot length okay and that should be working all right then let's test and what we are going to do here let's deploy and now let's register a visitor then we call number of visitors and is one and let's try to register again and we still get one visitor this is because asset implies that there cannot be duplicated values within this collection in this case we cannot have duplicated addresses and if we check the logic of the library we are gonna see here we call add and here is the implementation we are going to see that if the value exists sorry if the value doesn't exist we are pushing it otherwise we don't do anything and that's why it's not adding duplicate values all right we can let's say change account register and now we have to

Automatic transcript — names and jargon may be misspelled.