@@ -402,9 +402,7 @@ them to the `msg.sender`'s balance.
402
402
403
403
We now have a full structure, with a roof to shelter us from the weather. The
404
404
only problem is that we didn't create any openings for anyone to enter or leave
405
- the house.
406
-
407
- We can think of entering the house as ` minting ` new tokens or increasing the
405
+ the house. We can think of entering the house as ` minting ` new tokens or increasing the
408
406
total supply, and leaving the house as ` burning ` tokens or decreasing the total
409
407
supply. But these doors don't exist in our contract just yet.
410
408
@@ -441,9 +439,7 @@ contract MyToken is ERC20 {
441
439
```
442
440
443
441
When we define our ` mint ` function, we decide who will be the receiver of said
444
- new tokens.
445
-
446
- For the ` burn ` function on the other hand, we are ** only** letting holders burn
442
+ new tokens. For the ` burn ` function on the other hand, we are ** only** letting holders burn
447
443
their own tokens by using ` msg.sender ` as the address to call the internal
448
444
` _burn ` function.
449
445
@@ -458,21 +454,15 @@ We have now created doors to our house, but we haven't put locks in them!
458
454
## Lock the Door!
459
455
460
456
In our present state, our functions for minting and burning can be called by any
461
- address.
462
-
463
- That's ok for ` burn ` since people can only burn their own tokens (or their
464
- approved allowances), but we don't want anyone to ` mint ` tokens and increase the
457
+ address. That's ok for ` burn ` since people can only burn their own tokens, or their
458
+ approved allowances. But we don't want anyone to ` mint ` tokens and increase the
465
459
total supply of our new token.
466
460
467
461
To be able to limit the access to minting tokens, we are going to use a pattern
468
462
that OpenZeppelin calls AccessControl to give granular access to functionality
469
463
within our code. For that we will inherit yet another great contract from the OZ
470
- library.
471
-
472
- We can basically define ** roles** and assign or un-assign them to any address we
473
- need.
474
-
475
- In our case, we will only create a ` MINTER_ROLE ` to allow access to our ` mint `
464
+ library. It basically lets us define ** roles** and assign or un-assign them to any address we
465
+ need. In our case, we will only create a ` MINTER_ROLE ` to allow access to our ` mint `
476
466
function:
477
467
478
468
``` solidity
@@ -511,7 +501,7 @@ Let's break down our changes in the code:
511
501
- Created a ` bytes32 public constant ` variable for the minter role
512
502
- Inside our ` constructor ` :
513
503
- Granted the ` DEFAULT_ADMIN_ROLE ` to contract deployer to be able to grant
514
- roles to others
504
+ roles to others. Our contract inherits this by default from Access Control as the starting point for all admin roles.
515
505
{ /* is a part of Access control by default - i.e. it is inherited starting admim role for all roles */ }
516
506
- Granted the ` MINTER_ROLE ` to contract deployer to be able to mint tokens
517
507
- Added the modifier ` onlyRole(MINTER_ROLE) ` to the ` mint ` function to restrict
0 commit comments