So if I set a proposal to be one week long, how would I end that proposal and count the votes after one week? Would I have to make a transaction to do this or is there any way to do this automatically?

Basically, how do I close a proposal after the set time?

  • A contract cannot execute itself at a later time. It should be another address executing the function.
    – Ismael
    Jan 5, 2023 at 2:38

1 Answer 1


Am not sure if I am understand you but try this code and let me know if that helps.

pragma solidity ^0.8.7;

import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";

contract TimeLocked {
  using SafeMath for uint;

  uint public lockPeriod;
  uint public startTime;

  constructor(uint _lockPeriod) public {
    lockPeriod = _lockPeriod;
    startTime = now;

  function closeProposal() public {
    require(now >= startTime.add(lockPeriod), "TimeLocked: lock period has not expired");

    // Code to close the proposal and count the votes goes here
  • Yes, I was thinking of doing something like this but then I would have had to call closeProposal() manually. Is there any way to close the proposal automatically? Do you know how more popular DAOs do it, or is it done manually? I aim to have thousands of 24h proposals and it is inefficient and costly to do it manually. Jan 4, 2023 at 17:52
  • The best solution is as you said to use an external contract or service to monitor the proposal and close it automatically when the time limit has been reached. But sadly I have no Idea about this. Jan 4, 2023 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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