> For the complete documentation index, see [llms.txt](https://democrachain.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://democrachain.gitbook.io/docs/smart-contracts/voting.md).

# 🗳️ Voting

Election smart-contract in 5 minutes.

Election processes would be easily managed with a smart-contract as simple as:

```javascript
// EVENT: VOTE
// START: 2024-01-01T00:00:00.000Z
// END: 2024-02-01T00:00:00.000Z
// COMUNITY: Example Community
// TYPE: Anonimous vote
// QUESTION: ¿Should we modify the constitution to allow ...?
// OPTION_1: Yes
// OPTION_2: No

var seleccion =
  // INPUT
  {
    voto: "Null",
  };
// INPUT END

var checkVoter = get({
  scope: contract.hash,
  name: "voters/" + block.by,
});

if (checkVoter) {
  throw Error("Rejected, already voted.");
} else {
  if (block.timestamp < 1687628800000) {
    if (
      seleccion.voto === "Yes" ||
      seleccion.voto === "No" ||
      seleccion.voto === "Null"
    ) {
      var votes = get({
        scope: contract.hash,
        name: "votes/" + seleccion.voto,
      }) || 0;
      put({
        scope: contract.hash,
        name: "votes/" + seleccion.voto,
        value: votes + 1,
      });
      put({
        scope: contract.hash,
        name: "voters/" + block.by,
        value: seleccion.voto,
      });
      result({
        message:
          "Vote (" +
          seleccion.voto +
          ") by user " +
          block.by +
          ", correctly registered.",
      });
    } else {
      throw Error("Invalid vote:" + seleccion.voto);
    }
  } else {
    throw Error("Votation ended.");
  }
}

```

And to add votes the content of the block should be:

```javascript
// IMPORT d1d259e37...037401fdb

{
  voto: "Yes"
}
```

Or

```javascript
// IMPORT d1d259e37...037401fdb

{
  voto: "No"
}
```
