Questions tagged [modifiers]
The modifiers tag has no usage guidance.
109
questions
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)?
...
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 ...
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 ...
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?
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() {
...
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=>...
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) { _; }
...
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(...
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 ...
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 ...
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() ...
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 ...
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() {
...
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 = ...
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 ...
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&...
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() ...
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 =&...
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()...
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;...
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 ...
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 ;
...
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 ...
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 ...
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 ...
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; //...
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;
}
...
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 ...
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 ...
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;
...
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 ...
-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 ...
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 ...
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 ...
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) {
> ...
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}
...
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:
...
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() ...
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() ...
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 ...
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 ...
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 ...
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() {
...
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.
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...