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.
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.
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
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.
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.
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.
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!
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.
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!
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?
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.
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?
@@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?
@@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!)
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.
@@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?
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?
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.
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 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
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) ?
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.
Literally this. I always end up coming back to his videos for help.
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.
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
You're hands down the best in this game. Thank for all you do to make us better Solidity programmers.
Appreciate you making these videos, please keep it up!
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
THX for the contect, i love how you also explain the logic too.
Great work bro. Much appreciated for ur effort. Keep making videos it's really helping people. Love from india❤
Exactly what I needed to see, thank you 🙌🙌🙌
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.
Great ! Thanks for your explanations in AC. Much Appreciated .
Thank you for creating this
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.
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.
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!
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.
hash is 32 bytes. string can be more than 32 bytes
To save gas bruh
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!
Much useful. Thank you
Is it possible to make the 'grantRole' function public with same modifier for admin instead of external and internal explicitly? Any difference?🤔
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!
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?
it's your choice
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.
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?
Roles are limited with enums. You can't decide to add new role after the contract is deployed
@@smartcontractprogrammer I see, thanks!
@@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?
@@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!)
thank you so much , is it necessary to learn vyper or just focusing on solidity ? have a nice day
Focus on Solidity
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.
private variables are stored onchain
@@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?
how you get admin row hash? please explain me
Please could you teach how to make a PFP nft project?
Bro thank you so much!
Need SBT Implementation, please🙏.
Can i make a contract that authenticates the eth in a account ?
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?
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.
@@ThePersepolis32 That makes sense thanks!
@@ThePersepolis32 we can do it simply by using “roles[ADMIN][msg.sender]=true;” in the constructor. Question opened.
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?
Using enum, it hard codes the roles which cannot be changed after the contract is deployed.
Using bytes32, roles can be added after deployment
@@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
why separate the logic into `_grantRole`? why not do everything at once, just like you do in `revokeRole`?
Logic is used in 2 places
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) ?
account => role
account can have only one role
role => account => bool
account can have many roles