Questions tagged [modifiers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
16 views
3
votes
1answer
238 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 = ...
1
vote
2answers
637 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
288 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
232 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
2answers
32 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 ...
0
votes
1answer
186 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
275 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 ...
2
votes
0answers
80 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
0answers
53 views

truffle solidity unit test modifiers: How do you test modifiers dependent on the sender account?

QUESTION: How do you write unit test code that would test that a non-owner can't execute a function modified by a requirement that they be the owner using in solidity and truffle? I am trying to write ...
0
votes
0answers
37 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 ...
2
votes
2answers
359 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
17 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
360 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 ...
1
vote
1answer
477 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 ...
1
vote
2answers
130 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
380 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
132 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
129 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
299 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
33 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
41 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 ...
66
votes
2answers
24k 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
521 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
35 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
302 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 ...
9
votes
1answer
6k 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
287 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
566 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
45 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
61 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
182 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
44 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
621 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{...
18
votes
2answers
6k 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
177 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
238 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
59 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
34 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
626 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
808 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
166 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
418 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
188 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
4k 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
335 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
130 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
756 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
526 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` ...