A smart contract has an enter() function where participants can send 1 Ethereum to enter a raffle. Is there an easy way to stop allowing the others calling this function while the winner is picked?


Yes, you can set up a "pauseable" function modifier to any of the functions which you want to control access to.

Here is an example of how to implement this from Open-Zeppelin.

You can then use it in your contract like so:

pragma solidity 0.4.24;

import "path/to/Pausable.sol";

contract MyPausableContract is Pausable {

    myFunction() whenNotPaused {
        do things...


To explain what is happening simply:

  • There is a global variable which tracks if we are "paused" or "not paused" (bool)
  • Then there is a function modifier which simply requires that the global variable is in the "not paused" state

  • Then there is a function which can only be called by a privileged user which can change the value of the paused variable.
  • I added a bit more detail too at the end. Hope this helps! – Shawn Tabrizi Sep 18 '18 at 19:04

I forgot that solidity allows to use if statements. I'm still learning it. I went on a different way and basically

bool Pause; 

function setPause(bool anInput) public limited {
Pause = anInput; }

(limited is a modifier which I declared to check if the msg.sender is the contract owner)

function enter() public payable {
if (Pause == false) {
...do that...}
revert("raffle is in pause. We are picking the winner"); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.