Learn to import code into your contract.
EnumerableSet
under Utils. This library will allow you to create sets of bytes32
, address
, and uint256
. Since they’re enumerated, you can iterate through them. Neat!
pragma
and license identifier.
In Remix, you can import libraries directly from GitHub!
EnumerableSet.sol
pop into your workspace files, nested deeply in a bunch of folders.
SetExploration
. Review the extensive comments within the contract itself.
To use the EnumerableSet
, you need to use the using
keyword. This directive attaches all of the library methods to the type. Doing so allows you to call the method on the variable with dot notation, and the variable itself will be supplied as the first argument.
Follow the pattern in the example in the comments, but name the variable visitors
:
registerVisitor
that makes use of the library’s add
function to add the sender of the message to the visitors
set.
_add
function, which is private.Reveal code
numberOfVisitors
. Thanks to using
, this can cleanly call the length
function:
Reveal code
using
keyword.