Questions tagged [modifiers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
18 views

Does the OpenZeppelin nonReentrant modifier block calling all functions that have the modifier on them, or it keeps a separate state for each function

Would the nonReentrant modifier from the OpenZeppelin ReentrancyGuard library prevent the user from calling stake() when the unstake() function hasn't yet been fully processed (in the example below)? ...
Mila A's user avatar
  • 202
0 votes
1 answer
35 views

Can I modify a smart contract's code? [duplicate]

I get scammed big time, not proud! The worst? I can see the ETH on a watched only account. I think there's not really withdraw function at all in the code. Can I modify it to withdraw the funds and ...
Lucie Maheux's user avatar
2 votes
0 answers
13 views

How to inherite modifier into multiple contracts ? Best practice?

I have a project with severals contracts. To put some security, I've created a "onlyContract" modifier on a Roles contract so some functions in diferents contracts can only be called if the ...
noubidev's user avatar
0 votes
1 answer
25 views

How do modifiers effect function signatures?

I want to change a function that my contract inherits to have a modifier, but are you allowed to add modifiers to overridden functions that didn't previously have a one?
Rohan Nero's user avatar
  • 1,069
1 vote
1 answer
25 views

Solidity modifier attachment expression onlyOwner vs onlyOwner() | any difference?

Can I use onlyOwner() and onlyOwner modifier calls interchangeably in Solidity? Is there any particular difference between these 2 functions below considering that address owner; constructor() { ...
Mila A's user avatar
  • 202
0 votes
1 answer
24 views

ParserError in solidity

I wrote the following contract (for educational purposes): // SPDX-License-Identifier: MIT pragma solidity 0.8.8; contract Coin{ holders[] public investors; mapping(address=>...
Fawzy Hegab's user avatar
3 votes
1 answer
55 views

Modefiers Overloading

Compiling this code: pragma solidity ^0.8.17; contract OverloadModifier { uint public a = 0; bytes public b = 0x00; modifier m(uint _a) { _; } modifier m(bytes _b) { _; } ...
Ahmed Rami Berrahal's user avatar
2 votes
1 answer
131 views

Can I change Openzeppelin access control without having the right permissions?

If you check this link: openzeppelin github access control you will notice they use 2 function for granting a role: function grantRole(bytes32 role, address account) public virtual override onlyRole(...
Crypto Man's user avatar
0 votes
1 answer
70 views

Why the default mint() signatures in OpenZeppelin's ERC1155 wizard use "onlyOwner" modifier?

If you visit OpenZeppelin's ERC1155 wizard (https://wizard.openzeppelin.com/#erc1155) and check the "Mintable" checkbox, two functions will be created in the contract: function mint(address ...
errata's user avatar
  • 139
0 votes
1 answer
54 views

Modifier vs function call

What is more gas efficient and secure, using a modifier(for example only owner) or calling a function to verify state(calling a function that returns owner address and compares that to the address ...
NFT_king's user avatar
0 votes
1 answer
22 views

How to put error inside modifier?

Lets say i have this error: error Main__ContractNotAllowed(); And also i have this modifier which checks this mapping: mapping (address => bool) private isAllowed; modifier onlyAllowedContracts() ...
Alireza's user avatar
  • 350
0 votes
2 answers
48 views

Does Interface inherits modifiers?

Lets say i have contract that has couple functions which i want to call them by my other contracts, so i add some modifiers which help to doing this and. For interacting with my contract i use ...
Alireza's user avatar
  • 350
0 votes
1 answer
56 views

contract recursive dependency

i have two contracts the first one has a function which must be called only by the second contract : contract A { address contractBAddress; uint256 number; modifier onlyB() { ...
noro meb's user avatar
  • 328
0 votes
1 answer
79 views

what does the underscore mean in this modifier situation? [duplicate]

Came across this little confusing situation of underscores in modifier so I want to post it here to check if my understanding is correct. contract whatever{ bool public locked; uint public x = ...
Simon Zhao's user avatar
0 votes
2 answers
50 views

Undeclared identifier for OnlyOwner modifier

So I created a modifier to make it so for certain functions only the deployer of the contract can use the function. But once I created it, I'm getting an undeclared identifier error. Heres my ...
Ron's user avatar
  • 13
0 votes
3 answers
38 views

Undeclared identifier error for modifier

I am new to solidity and am confused on why I am getting this undeclared identifier error: I have this modifier: modifier isRegistered(uint ID_num){ require (Array[ID_num].exists, "Object DNE&...
Ron's user avatar
  • 13
0 votes
2 answers
435 views

modifier vs function which method is more efficient in terms of gas?

contract test { address public _onwer; error NotOwner(); modifier OnlyOwner1() { if(msg.sender != _onwer) { revert NotOwner(); } _; } function OnlyOwner2() ...
imelon2's user avatar
  • 425
0 votes
1 answer
38 views

nested mapping not working during test

I have a function that have a modifier that it must be the owner before it can cancel the order and I'm using the nested mapping that i've created for this struct as below //mapping mapping(bytes32 =&...
0xhaz's user avatar
  • 3
0 votes
0 answers
33 views

Custom error not working during test

I tried to use custom error instead of using a require in modifier like so: modifier tokenExist(bytes32 ticker) { if(tokens[ticker].tickerAddress != address(0)) revert Exchange__TokenNotExist()...
0xhaz's user avatar
  • 3
1 vote
1 answer
113 views

Declaratively creating an array of structs with one statement in Solidity

I want to create a modifier that accepts a dynamic array, like this: modifier parameterizedTest(Set[] memory sets) { // ... } Where the Set struct is defined like this: struct Set { uint256 x;...
Paul Razvan Berg's user avatar
1 vote
1 answer
51 views

modifiers overriding simple question with inheritance

just wanting to be sure of this. If I have a contract that inherits from another contract and overrides a function of that contract with NonReentrant modifier on it. Will that NonReentrant modifier ...
Mauro's user avatar
  • 11
0 votes
1 answer
38 views

Passing different parameter to function and modifer

I want to know that is there any way to provide different parametres to function and modifer while declaring them . Below is the code // SPDX-License-Identifier: MIT pragma solidity ^0.8.16 ; ...
Brijesh's user avatar
  • 43
0 votes
0 answers
242 views

How can I check the state of an uninitialized contract variable?

I have something like this: import "./Null.sol"; //ERC20 token contract WrapperCon { Null public nullToken; } then later on I launch the token in the contract with function ...
sudolink's user avatar
2 votes
0 answers
34 views

Silence error: State-changing modifier on a view function

In the past it was possible to use state-changing modifiers on view and pure functions. It was very useful when used properly because one could work out what the state would be and will be when the ...
Rob Hitchens's user avatar
  • 54.5k
1 vote
1 answer
60 views

Add modifier in child contract

I'm trying to implement my own ERC20 using openzeppelin. contract MyERC20 is ERC20 { ... } And I want to make function from ERC20 pausable using openzeppelin Pausable contract. The question is - do I ...
Dzianis Czaplia's user avatar
0 votes
1 answer
198 views

Is it possible to make certain fields of a structure only available to contract owner?

For example, given the following structure, I want some fields to be visible only for the contract owner struct Participant{ address participantAddress; // can be seen by anyone string team; //...
AndrewHoover898's user avatar
1 vote
1 answer
2k views

Member "xxx" not found or not visible after argument-dependent lookup in type

How can I access to fields of struct that is in mapping from different contract? pragma solidity ^0.8.0; contract Contract1 { struct User { bool isValid; uint value; } ...
Emrah's user avatar
  • 1,524
0 votes
1 answer
48 views

Allowing only contract B to call contract A

I have a structure of the following form: contract A { uint num; function setNum(uint target) public onlyB { num=target; } } contract B{...} I want the modifier onlyB to check ...
user3799934's user avatar
5 votes
1 answer
675 views

Can calldata be used in every function visibility?

When I look at it in general, everywhere it says calldata is used only with external visibility, but I can also use it with public while writing a contract? Because when I use public, there is no ...
Whisrambol's user avatar
0 votes
1 answer
34 views

A function made in my contract while trying to compile the contract showed this; TypeError: Referenced declaration is neither modifier nor base class

//SPDX-Licence-Identifier: MIT pragma solidity ^0.8.11; contract PurchaseAgreement { // VARIABLES uint public value; address payable public seller; address payable public buyer; ...
Prime Relaxation's user avatar
0 votes
0 answers
31 views

Contract getFunds call which should send wrapped ERC20 token to owner reverts, why?

My smart contract holds a few WETH. I have this function in my contract: function getFunds(address tokenAddress) external onlyOwner{ IERC20 token = IERC20(tokenAddress); uint ...
flo's user avatar
  • 123
-1 votes
1 answer
56 views

How to restrict a function call only to the owner of a private key of a public key in a parameter (many users)?

Let's say, there's something like a lottery. And there's a function in a smart contract that allows ANY user among users to check whether he's won something or not. If he has, it'll allocate the coins ...
arumichi's user avatar
0 votes
2 answers
180 views

Why does gas usage differ so much for two very similar functions that just check a condition and set a boolean?

I am facing one issue when interacting with my smart contract. Just to add, I have deployed by smart contract in bsc testnet. It has two similar functions- enableQuestion & disableQuestion, whose ...
VikasGS's user avatar
  • 85
0 votes
1 answer
162 views

How to create a "hasBalance" modifier in solidity for any token address?

I've been researching if it's possible to create a modifier that checks if msg.sender has any given amount of a token address. Use Case: limit certain functions to owners of a given token or NFT. I've ...
matlemad's user avatar
0 votes
0 answers
25 views

Solidity Parson Error Expected Primary Expression

I'm trying to create a Multi-Sig Wallet in Solidity and I'm following along with a youtube video to do it. He put this snippet of code in the contract: > modifier txExists(uint _txIndex) { > ...
GLDPHEZ's user avatar
1 vote
2 answers
651 views

How to add modifier to public state variable?

I have a contract that looks like this pragma solidity >=0.7.0 <0.9.0; contract SomeContract { uint256 public id; address public creator; enum Status {ACTIVE, INACTIVE} ...
fahadh4ilyas's user avatar
0 votes
1 answer
719 views

TypeError: Member "isContract" not found or not visible after argument-dependent lookup in address

pragma solidity ^0.8.4; This modifier: modifier onlyNotContract() { require(!msg.sender.isContract(), "Contracts are prohibited"); _; } Is generating this error: ...
alpo's user avatar
  • 144
1 vote
1 answer
99 views

Whats the point of modifiers? [duplicate]

So let's assume the following code: modifier Owner() { if (msg.sender == owner) _; } function uploadContent() external Owner { uploadContent() .. } Why not use this? function checkOwner() ...
redigaffi's user avatar
  • 213
0 votes
1 answer
686 views

How to restrict function to only callable from one external contract?

I have a Reputation contract which has a function foo() that sets some point. In another contract called Market I want to use the foo() function. But I don't want any one to be able to call foo() ...
Amin's user avatar
  • 76
0 votes
2 answers
332 views

Can you ! a modifier?

I have a modifier for a few functions that check if a mapping exists, for one function I need the modifier to verify the mapping doesn't exists, is there any way to !modifier as you would a function ...
user3316323's user avatar
2 votes
1 answer
299 views

UnhandledPromiseRejectionWarning: Error: nonce generation function failed or private key is invalid in Ganache

In Go I am using go-ethereum to read data from the ethereum smart contract. My smart contract is maintained with truffle. I am trying to fetch candidate information based on candidate id. I have a ...
NinjaMAN's user avatar
  • 409
0 votes
0 answers
307 views

Accessing modifier of another smart contract - Role Based Access Control

I am trying to create a simple role based access control system for the contracts I have created. I have two smart contracts, one named Users that stores all of the users details as well as the type ...
Declan Morgan's user avatar
5 votes
2 answers
4k views

How does the re-entrancy guard modifier work?

Following is code for a re-entrancy guard, but not sure if I understand it properly: contract Test { using SafeMath for uint256; uint256 private counter = 1; modifier entrancyGuard() { ...
Kevvv's user avatar
  • 777
0 votes
1 answer
30 views

Adding modifier for mappings

can I add a modifier (for ex: onlyOwner) to a mapping? only I must see the value of mapping's key by myself(onlyowner). For example: mapping (address => bool) onlyOwner getAddress; Thank you.
sollover's user avatar
  • 105
1 vote
1 answer
2k views

Function modifier effect on return value

Having the following code pragma solidity ^0.6.4; contract TestModifier { mapping (address => bool) public authorities; mapping (address => address) public authorized; modifier ...
Mehran Shakeri's user avatar
1 vote
2 answers
1k views

Should I use the 'external' modifier to return a large array?

If I need to access a large array from my contract... say for my front end. Should I be using external to make it cheaper for myself? A comment by William Entriken on this question is what got me ...
Duncan Brain's user avatar
0 votes
1 answer
481 views

Read access control solidity smart contract

Let's say that we have a contract that not anyone can access to view function : contract AccessControl { mapping (address => bool) authorized; function getSomething () public view returns ...
maroodb's user avatar
  • 1,081
3 votes
2 answers
2k views

Solidity modifiers in library?

Isn't it possible to define modifiers in libraries? I'm really asking myself why, because thats some functionality you would need over and over again. If I would like to hypothetically implement some ...
AirUp's user avatar
  • 363
2 votes
1 answer
531 views

Solidity: call from function to modifier with array [closed]

I have the following problem, I'm trying to call a function from Solidity function to Solidity modifier: contract B is A function checkIfIsValid() external pure onlyValidAddresses([manually put ...
Radek_pl's user avatar
  • 761
7 votes
2 answers
331 views

Is there a widely-accepted convention for when to use a modifier and when to use a simple assertion?

I've read this answer, which is good in general, but it doesn't quite tell me when to use a modifier (at the function declaration) and when to use assert/require (inside the function). I do ...
goodvibration's user avatar