Questions tagged [modifiers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3
votes
1answer
229 views

error: invalid opcode using modifier

Im getting the following error when trying to run my js test file using truffle: Error: VM Exception while executing eth_call: invalid opcode The js test file is the following: var DebitService = ...
0
votes
0answers
26 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 ...
1
vote
2answers
546 views

function () public payable modifier can trigger actions when sending tokens or only works when sending ether?

Modifier payable triggers an action when an address sends ether to a contract. For example: function () public payable { require(msg.data.length == 0); DoSomething(); } Is this ...
1
vote
1answer
217 views

Calling onlyowner functions using owner's private key

I need to call a function with onlyOwner modifier in my smart contract via web3.js. I want a user of my site to be able to send their information to a white list, but it sends the transaction from ...
0
votes
1answer
279 views

Modifiers misunderstanding

pragma solidity ^0.4.0; contract test { bool test_bool1 = false; bool test_bool2 = true; modifier test_modifier(bool _test_bool){ if (_test_bool == false) throw; _; } ...
2
votes
2answers
212 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
1answer
211 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 ...
0
votes
1answer
71 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 ...
0
votes
1answer
13 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.
2
votes
2answers
213 views

Solidity modifiers: good or bad?

I've heard arguments both for and against Solidity modifiers. On the one hand, they make the code very readable, and the intents behind the calls are very clear. On the other, they increase the ...
0
votes
0answers
11 views

Custom modfier in erc20 transfer [duplicate]

Is it possible to add a custom parameter in the erc20 transfer function without breaking the erc20 standard? What I want to do is have off-chain whitelist base on the signatures, I would like users ...
1
vote
1answer
381 views

how to use multiple modofier to form combinations of boolean conditions?

I have read this article and this SO. And I understand the functionality of modifier. When modifiers are placed on a function with a spacing they will be evaluated in the order of placing thus ...
0
votes
2answers
72 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
1answer
234 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 ...
7
votes
2answers
121 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 ...
1
vote
1answer
75 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 ...
1
vote
2answers
254 views

modifier consumes all gas

Given a modifier: modifier yetNotCalculated() { require(calculated == false); _; } and then using it in my function: function calculateResult() public yetNotCalculated { calculate(); ...
0
votes
1answer
30 views

Revert Assert best option

I have a contract(A) function with the standard onlyOwner access. If I call directly from the deployed account the function works fine. But when I import this contract(A) into another contract(B) and ...
0
votes
1answer
38 views

Read storage struct from a modifier

If i read a struct(storage) Human storage human = humans[2]; in my modifier is there a possibility that the function that uses this modifier can use the "human"? Otherwise i have to scope the storage ...
64
votes
2answers
23k views

Solidity: What is the difference between `view` and `constant`?

Solidity 0.4.16 introduced the view and constant function modifiers. The documentation says: constant for functions: Same as view. Does this mean view is just an alias for constant? If so, why do ...
0
votes
1answer
283 views

Is it possible to send Ether using delegatecall?

I tested this in Remix and it seems that the ether remains in the delegator contract and doesn't get forwarded. Using the code below to test: contract SomeContract { address public sender; ...
0
votes
1answer
31 views

How to make transaction of some ether in Buyer Seller type of contract?

In this I have set modifier (msg.sender == sellerAddress) which is not valid. But in this scenario, I want to allow only and only sellerAddress to take ether from my contract. How can I allow only ...
4
votes
1answer
290 views

Use modifier function to create heirachy of smart contracts

I have 3 contracts that I want to implement. The contracts are master , admin and customer. So the master contract is initiated by a single person, the owner of the private chain (based on geth). The ...
7
votes
1answer
4k views

calldata keyword as parameter in solidity v0.5.0 function?

What purpose does the "calldata" serve in this parameter _owners? Is it a new keyword? function setup(address[] calldata _owners, uint256 _threshold, address to, bytes calldata data) Taken from ...
1
vote
0answers
172 views

Modifier to only allow access via staticcall

I'm trying to create a modifier that only allows a function to be called using staticcall. Using the view declaration in Solidity 0.5.0 guarantees that a function won't change state, but it still ...
1
vote
1answer
441 views

Emit event while require statement fails

I would like to be able to log a result of a condition: if(time > 5) { emit Result("time is larger than 5"); } else { emit Result("time is less than 5"); } This will work just fine, but ...
0
votes
0answers
40 views

Are function modifiers added to the stack in solidity? [duplicate]

I've got a function with a decent number of modifiers and I hit the CompilerError: Stack too deep, try removing local variables error. If I remove one of the modifiers though, everything's all right. ...
0
votes
1answer
51 views

Does function inherit variables from modifier?

In a contract where a modifier like this would be reused a lot, is ID inherited by the function that uses the modifier? If not, this check would need to be in the function. If yes, is there any ...
0
votes
1answer
151 views

Use same argument name in modifier and function

If I have a function function b(address _foo) verifySomeClause { } and a modifier that can take different addresses as an argument, so that msg.sender can be one of those, modifier c(address _foo) {...
0
votes
1answer
35 views

onlyOwner modifier works in truffle test but not in console

In the following code, the console.log returns an empty string, but the truffle test works fine! const certificate = contract(Certificate); certificate.setProvider(web3.currentProvider); var ...
2
votes
2answers
538 views

Is it possible to use a modifier from a different contract?

Is there a way to use modifiers from a different contract? My attempt did not work. contract con1{ modifier supermod(uint _value){ require(_value == 1); _; } } contract con2{...
17
votes
2answers
5k views

Can Solidity function modifiers access function arguments?

I would like to have a modifier that looks like this: modifier restrictTargetType(uint contractType) { if (contractTypes[target] != contractType) { throw; } _ } Where target is an address ...
2
votes
1answer
120 views

Are Solidity modifiers functionally equivalent to Python decorators?

I understand that in Solidity if a function has a modifier, this modifier runs first, prior the the logic within the function running. This is done for checks of ownership, checks of state, etc. In ...
4
votes
1answer
198 views

Call parent class modifier possible?

I want to do the following: contract Base { bool public active; modifier canSetMetadata() { require(active == false); _; } } contract BaseWithMetadataControl is Base { ...
0
votes
1answer
50 views

Dealing with parameter overflow

Can parameter overflow be prevented in the contract, or does it have to be dealt with on the frontend? Solidity: contract parameterOverflows { uint8 selectedCharacter; modifier ...
0
votes
1answer
33 views

cryptozombie external modifier

One of the tutorials in crypto zombies mentions about external function. contract KittyInterface { function getKitty(uint256 _id) external view returns ( bool isGestating, bool isReady, ...
0
votes
2answers
493 views

Pass parameter to access modifier

how can I pass a parameter to an access modifier both in Solidity and Web3. Let's assume I have the following code: modifier passwordRequired(string _pw){ require(keccak256(_pw) == keccak256("...
0
votes
1answer
654 views

Calling a function inheriting onlyOwner via other contract

I need to call mint() function in MyNFToken.sol via MyContract.sol. Ownable.sol pragma solidity ^0.4.20; contract Ownable { address public owner; function Ownable() public { owner = msg.sender;...
0
votes
1answer
144 views

Truffle Test: How to send ether to a contract from a contract?

Would like to test the modifier below modifier isNotAContract(){ require (msg.sender == tx.origin, 'Contracts are not allowed to interact.'); _; } How can I invoke a function using this ...
0
votes
1answer
368 views

Calling External Contract Function with Modifiers - Results in Unknown Error

I am attempting to call an external contract function, but modifier on the function is throwing an error. And I can't figure out why. Any help is appreciated! Info is below: I have two contracts: ...
1
vote
0answers
161 views

Modifiers: can I pass an array or specify that not all of them have to pass, but one is enough (OR functionality instead of AND)

Say I want to restrict a function to only authors and editors. And later on, I want to restrict another function to authors and contributors only. So ideally, I would add a modifier like this: ...
5
votes
2answers
3k views

Using require or modifier?

If you create a function that you only want the owner to interact with would you use require(msg.sender == owner) or modifier onlyOwner() { require(msg.sender == owner); _; } Which ...
2
votes
3answers
309 views

Why cannot I get uint returns without 'view' modifier?

I have very simple contract as.. contract myContract { function foo() public returns(uint) { return 10; } function foo1() public view returns(uint) { return 10; } ...
0
votes
2answers
122 views

Is it safe to remove the “view” modifier from the function “getTokenAmount” in the OpenZeppelin crowdsale contract?

This function from the openzeppelin crowdsale sample is marked view as seen here: // Override this method to have a way to add business logic to your crowdsale when buying function getTokenAmount(...
1
vote
0answers
22 views

Can't check if time is over using NOW

I'm coding a smart contract for an ICO and I have a problem. I have a modifier wich checks if NOW > timestamp, but it's not working for some reason. Here is the function: function DeleteModerator(...
1
vote
1answer
656 views

Is it Okay to use if else in modifiers?

In solidity use of require and assert is recommended than using if else conditions but in every solidity example where modifiers are used instead of require if else is used. So is it Okay to use if ...
2
votes
1answer
494 views

Can't call function with modifier from another contract even if the owner himself calls

So I have multiple contracts that use the same modifier. contract Token is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; Owned private owned; /// @dev `owner` ...
6
votes
2answers
3k views

What's the order of execution for multiple function modifiers? [duplicate]

I don't know why nobody is asking this question (I've done my homework and did tons of Googling for an answer) but I am having hard time understanding how function modifiers actually work. Sure it's ...
0
votes
0answers
107 views

Using modifier on view function works locally, but fails on Ropsten

Hey I'm trying to make it inconvenient to view stored data in a contract, but it seems that the function is returning null values when I add a modifier. The modifier makes sure someone is approved ...
2
votes
1answer
569 views

Solidity store storage pointer in storage variable for accessing it from distinct functions

In a contract, using Solidity, is it possible to store a pointer to a storage variable in a storage variable (or somewhere else that may be suitable) and access it from distinct functions? Consider ...