Hey folks,
I am facing this error can anyone tell me why is this error popping.??
Code:
Hi, i want to create a function that authorizes people to execute a function.
It should be dynamic, So. i created a seperate function named :-
mapping(address=>bool)authUsersAll;
address owner;
constructor(){
owner=msg.sender;
}
modifier onlyAuth(address _newUser){
require(authUsersAll[_newUser] ==true || msg.sender==owner,'Sorry, Not authorised');
-;
}
AuthoriseUsers(address _newUser) public onlyAuth(msg.sender) {
authUsersAll[_newUser]=true;
}
This function works fine when i am the owner, But shows"Sorry, Not authorised" when using any other wallet address.
I have first authorised that wallet address and then trying to use it.
The issue that i get is.
1. Not authorised
2. Too much gas fee as compare to when i am running the contract as owner. (owner gas fee=0.03, other addrrss=1.2)
3. Unable to decode chain Id 1337
I assure you there is no syntax error. If it pops here, it might be because i typed it here roughly.
Though, when i am deploying this using truffle migrate, it is successfully recording as well as showing data. But, when i did it with web3js. It is showing this error.
Using: Truffle, Web3js, Metamask.
Jun 3, 2022, 12:24 AM
Jun 3, 2022, 12:25 AM
try make it public mapping(address => bool) public authUsersAll so you can check if it is set to true. think you need to do it like this require(authUsersAll[msg.sender] == true
in the modifier
Jun 3, 2022, 12:35 AM
okay so i need to make mapping public. Only that?
Jun 3, 2022, 1:57 AM
require(authUsersAll[msg.sender] == true in the modifier, msg.sender instead of _newUser
Jun 3, 2022, 1:58 AM
okay, but in _newUser, I am storing the address of msg.sender
But i will try this and let you know if it works.
Jun 3, 2022, 2:01 AM
you need to compare it to msg.sender on your require, if it's true. Like you also do with owner, just here it's a direct comparison to address.
Jun 3, 2022, 2:04 AM
ok
Jun 3, 2022, 2:07 AM