Access Control | Solidity 0.8

Поделиться
HTML-код
  • Опубликовано: 11 янв 2025

Комментарии • 52

  • @ethancemer8679
    @ethancemer8679 3 года назад +36

    You are pretty much the only content creator on RUclips that continuously uploads advanced solidity tutorials! I don’t think I would have been able to break into the blockchain development industry as a self taught developer as fast as I did if it weren’t for your amazing tutorials.

    • @skeleskele
      @skeleskele 2 года назад +5

      Literally this. I always end up coming back to his videos for help.

  • @hernanphillip334
    @hernanphillip334 3 года назад +13

    Bro, I'm so grateful for your channel, I'm on the half way yet, but I know I'll learn all perfectly.
    I was trying to learn from someone called "dapp University" but it wasn't useful to be honest, he just explains everything in a hurry and skipping a lot of critical topics while you are systematic and clear on your lessons.

    • @MrCoreyTexas
      @MrCoreyTexas 6 месяцев назад

      Yeah, the person you refer to is overrated, he has stupid clickbaity titles like "learn solidity in 20 minutes" and he calls smart contracts shmart contracts

  • @bertrandfossung1216
    @bertrandfossung1216 3 года назад +10

    You're hands down the best in this game. Thank for all you do to make us better Solidity programmers.

  • @ericxcn
    @ericxcn 3 года назад +3

    Appreciate you making these videos, please keep it up!

  • @nellykantu8428
    @nellykantu8428 2 года назад +1

    i smiled while watching this video because i understood it very well due to the other videos i've watched, thanks a lot you're really a gem

  • @lafk-lottyenaforrokave4700
    @lafk-lottyenaforrokave4700 11 месяцев назад

    THX for the contect, i love how you also explain the logic too.

  • @californiasunshine956
    @californiasunshine956 3 года назад +1

    Great work bro. Much appreciated for ur effort. Keep making videos it's really helping people. Love from india❤

  • @sherajr
    @sherajr 2 года назад

    Exactly what I needed to see, thank you 🙌🙌🙌

  • @MrCoreyTexas
    @MrCoreyTexas 6 месяцев назад

    At 9:42 you forgot to set the private constants directly to the precomputed hash. I understand the point of my confusion now, when you talk about saving gas, you're talking about not having to run keccac256() in the contract at deploy time. The only reason you set them as public temporarily is so you could compute those hashes in remix offline.

  • @TheSun128
    @TheSun128 2 года назад

    Great ! Thanks for your explanations in AC. Much Appreciated .

  • @shibuthomas6384
    @shibuthomas6384 8 месяцев назад

    Thank you for creating this

  • @miceuud
    @miceuud 3 года назад +5

    Thanks for this. Please can you explain the concept of calling an interface with a contract e.g IERC72(address).safetransfer.
    I don't understand this logic, can't find an explanation in the solidity documentation.

    • @casweeney
      @casweeney 2 года назад

      There are two ways in which interfaces can be used in solidity. Firstly as a guard in a contract where you have to implement all the functions in the interface inside your contract. Secondly as a base or instance for interacting with a smart contract, here you pass the address of the smart contract you are interacting with just like you did in your question. Ensure that the interface you are using to interact with the smart contract, have the same function selectors with the smart contract.
      I hope I didn't confuse you more.

  • @Ggs-fe8ji
    @Ggs-fe8ji Год назад

    at 3:55 roles[_role][account] = true I thought we are declaring an array to store all roles... Can someone explain the difference here please I am so confused! Anyways your content is awesome!

  • @marindraganov
    @marindraganov 2 года назад +2

    Hi and thanks for the video. Why we are hashing the roles instead of using mapping(string...? In theory, there is a chance the hashes of two different roles to be the same.

    • @smartcontractprogrammer
      @smartcontractprogrammer  2 года назад +3

      hash is 32 bytes. string can be more than 32 bytes

    • @EntertainingTheEarth
      @EntertainingTheEarth 7 месяцев назад

      To save gas bruh

    • @MrCoreyTexas
      @MrCoreyTexas 6 месяцев назад

      The chances of 2 different roles to be the same hash is what you call astronomically small, if it ever happened it's be at the top of every crypto news website in existence!

  • @MrMahesh7001
    @MrMahesh7001 2 года назад

    Much useful. Thank you

  • @blockmaxi
    @blockmaxi Год назад

    Is it possible to make the 'grantRole' function public with same modifier for admin instead of external and internal explicitly? Any difference?🤔

  • @markgalang7832
    @markgalang7832 2 года назад

    Hi is there a way to set a user role in frontend? i want to create a minting function but for specific addresses only at a given time. thanks!

  • @MrCoreyTexas
    @MrCoreyTexas 6 месяцев назад

    I've been wondering about this for a while, if you have a modifier that's only used in 1 function, wouldn't it save gas to just write out the requisite require()'s in said function? I guess it adds clarity and readability?

  • @aviralraj3937
    @aviralraj3937 2 года назад

    Hey, great video thankyou. Just a request can you demonstrate doing the same thing on truffle in vs code or command line. It would be really appreciated.

  • @dinub8414
    @dinub8414 2 года назад +1

    Great content! Why not use a simple enum for roles? Do we expect there to be more than 2**8 - 1 roles? Because we'd be better off storage-wise using uint8 ( 1 byte of storage ) for a role, instead of bytes32 (32 bytes of storage) for a role. Or what am I missing?

    • @smartcontractprogrammer
      @smartcontractprogrammer  2 года назад +2

      Roles are limited with enums. You can't decide to add new role after the contract is deployed

    • @dinub8414
      @dinub8414 2 года назад +1

      @@smartcontractprogrammer I see, thanks!

    • @RunForPeace-hk1cu
      @RunForPeace-hk1cu 2 года назад +2

      @@smartcontractprogrammerwhy do you need to hash the role? Moreover, hardcoding the roles as hashed constant isn’t it the same as enum?
      Wouldn’t it make more sense if the contract has another lookup table to load the roles onto the table?

    • @MrCoreyTexas
      @MrCoreyTexas 6 месяцев назад

      @@smartcontractprogrammer Oh this is the explanation I needed. I guess you could just use a bytes[124] and just discard the concept of an enum and just add new unused integers on the fly. Honestly it does seem like Ethereum overdoes it with 32 byte values everywhere (this is coming from a guy whos first computer was 16 bits!)

  • @saidelkarim8317
    @saidelkarim8317 Год назад

    thank you so much , is it necessary to learn vyper or just focusing on solidity ? have a nice day

  • @MrCoreyTexas
    @MrCoreyTexas 6 месяцев назад

    I wasn't aware that private variables aren't stored onchain, I thought it was just an isolation safety mechanism borrowed from object oriented programming. Don't understand how that works at the moment.

    • @smartcontractprogrammer
      @smartcontractprogrammer  6 месяцев назад

      private variables are stored onchain

    • @MrCoreyTexas
      @MrCoreyTexas 6 месяцев назад

      ​@@smartcontractprogrammerWhen you said, "we don't need to store it on chain as a public state variable. when we do store this variable as a public state varible, this contract will use a little bit more gas. by making it private, this contract will use a little bit less gas.", that threw me off. So private / public variables use different amounts of gas?

  • @bhavikdoshi4866
    @bhavikdoshi4866 Год назад

    how you get admin row hash? please explain me

  • @fedes9626
    @fedes9626 3 года назад

    Please could you teach how to make a PFP nft project?

  • @zedwong2486
    @zedwong2486 2 года назад

    Bro thank you so much!

  • @adityabhattad4614
    @adityabhattad4614 2 года назад

    Need SBT Implementation, please🙏.

  • @darktools186
    @darktools186 2 года назад

    Can i make a contract that authenticates the eth in a account ?

  • @theodorosconstantinides7417
    @theodorosconstantinides7417 3 года назад +1

    Hi great video! What are the benefits of having two functions to grand roles one internal and one external and why don't you just have one like the revoke role case?

    • @ThePersepolis32
      @ThePersepolis32 3 года назад +3

      If I'm right, it's because we need to give the ADMIN role to the contract deployer. we are doing it in the constructor function. so here using an internal function will cost a lower fee.

    • @theodorosconstantinides7417
      @theodorosconstantinides7417 3 года назад +1

      @@ThePersepolis32 That makes sense thanks!

    • @mikhaillobanov9774
      @mikhaillobanov9774 2 года назад

      @@ThePersepolis32 we can do it simply by using “roles[ADMIN][msg.sender]=true;” in the constructor. Question opened.

  • @MrCoreyTexas
    @MrCoreyTexas 6 месяцев назад

    Seems like you could just use an enum instead of 2 bytes32 to store ADMIN and USER. I suppose you are trying to show an example of a mapping of a mapping. I can't think of any other examples that would require strings of > 32 bytes, but maybe my imagination sucks?

    • @smartcontractprogrammer
      @smartcontractprogrammer  6 месяцев назад

      Using enum, it hard codes the roles which cannot be changed after the contract is deployed.
      Using bytes32, roles can be added after deployment

    • @MrCoreyTexas
      @MrCoreyTexas 6 месяцев назад

      @@smartcontractprogrammer Interesting point, but it seems esoteric, like admin and user should be fixed concepts that cannot change. For example on Beefy Finance under their 'generic description' of a vault they talk about whether or not an admin can change the contract with a timelock or multisig. I'll have to make my own version with enum and mess with it.
      Also it seems like bytes8 would be more than enough space for a role. I guess I'm an oldtimer who remembers DOS file names with 8.3 characters, LOL

  • @gosuto-inzasheru
    @gosuto-inzasheru 2 года назад

    why separate the logic into `_grantRole`? why not do everything at once, just like you do in `revokeRole`?

  • @ashishkmr
    @ashishkmr 2 года назад

    Why are we using mapping like role => account => bool, key has to be unique right?
    eg: ADMIN=>0x123=>true
    ADMIN=>0x345=>true
    Wouldn't second line overwrite the first line?
    Why aren't we doing it like, account => role(enum) ?

    • @smartcontractprogrammer
      @smartcontractprogrammer  2 года назад +3

      account => role
      account can have only one role
      role => account => bool
      account can have many roles