Questions tagged [modifiers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
2answers
27 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
120 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
96 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 ...
0
votes
1answer
38 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
2answers
109 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 ...
2
votes
2answers
85 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
1answer
27 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
21 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 ...
0
votes
1answer
118 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
25 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 ...
3
votes
1answer
2k 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
100 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
262 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
32 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
40 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
107 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
30 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
388 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{...
1
vote
1answer
68 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
142 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
33 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
28 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
310 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
440 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
138 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 ...
1
vote
0answers
136 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: ...
0
votes
1answer
257 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: ...
2
votes
3answers
271 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; } ...
1
vote
1answer
186 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 ...
1
vote
2answers
201 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(); ...
1
vote
1answer
304 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
113 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
21 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
2answers
451 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 ...
0
votes
1answer
568 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
438 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` ...
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 ...
5
votes
2answers
2k 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
98 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
494 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 ...
2
votes
2answers
227 views

Can we apply modifier to an event in solidity just like function?

Let's say as per business I want to restrict certain users(addresses) from seeing the logs for a contract. I know there is "modifier" which can be set to function, to give access rights but Can we do ...
2
votes
1answer
210 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
1answer
37 views

When are modifiers evaluated?

I have a code like modifier inTime { require(now <= starttime + duration);//easy peasy _; } applied to a fallback function like this function() payable inTime{ depositDone(msg.sender,...
60
votes
2answers
20k 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 ...
1
vote
1answer
212 views

Contract Security - When to include modifiers

Just some pretty high level questions here. When is it best to include modifiers? Are there any safeties needed to be placed on the initial contract creation function? In the last function of my ...
5
votes
1answer
2k views

Override parent method and modifiers

For example, we have a contract: contract A { modifier checkCaller() { require(msg.sender == 0x123); _; } function doSmth() checkCaller {} } We make child contract and ...
2
votes
2answers
624 views

Could not compile source code. Expected primary expression in modifier onlyAdmin

Why do i get this error message? Code: pragma solidity 0.4.8; contract Adminstrator { address public admin; function Adminstrator() { admin = msg.sender; modifier onlyAdmin() { ...
0
votes
1answer
268 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; _; } ...
1
vote
1answer
101 views

Splitter contact: is payable modifier missing?

I am using the geth javascript console, trying to split pre-fork ETH using the ReplaySafeSplit v2 contract 0xaBbb6bEbFA05aA13e908EaA492Bd7a8343760477 (code here). I am doing this as follows: ...
0
votes
1answer
414 views

On Solidity, calling event from modifier seems to fail

Two modifiers on a contract throw an "Exception during execution. (invalid opcode)." error when not being satisfied as expected. Both of them are calling an event when the condition they check is not ...