# Create your own vote system with Leo

By [gameovermachine.eth](https://paragraph.com/@gameovermachine) · 2024-05-28

---

**Summary**

`vote.leo` is a versatile voting program that allows anyone to issue new proposals, proposers to issue tickets to voters, and voters to cast their votes anonymously. This guide is inspired by the Aleo community's `aleo-vote` example.

### **Noteworthy Features**

*   **Anonymity**: Voter identity is concealed by privately passing a voter's ballot into a function.
    
*   **Transparency**: Proposal information and voting results are revealed using the public mapping datatype in Leo.
    

### **How to Run**

First, follow the Leo Installation Instructions. To run the `vote` program locally, use the following bash script:

Copy code

`cd vote ./run.sh`

The `.env` file contains a private key and address. This account signs transactions and checks for record ownership. When executing programs as different parties, ensure the `private_key` field in `.env` is set to the correct value. For a full example, refer to `./run.sh`.

#### **Functions Overview**

1.  **Create a Proposal**
    
2.  **Voter 1 Issues a Ticket and Votes**
    
3.  **Voter 2 Issues a Ticket and Votes**
    
4.  **How Votes Are Tallied**
    

##### **Step 0: Create a Proposal**

We'll act as three different parties:

1.  **Proposer**
    
    *   **Private Key**: `APrivateKey1zkp8wKHF9zFX1j4YJrK3JhxtyKDmPbRu9LrnEW8Ki56UQ3G`
        
    *   **Address**: `aleo1rfez44epy0m7nv4pskvjy6vex64tnt0xy90fyhrg49cwe0t9ws8sh6nhhr`
        
2.  **Voter 1**
    
    *   **Private Key**: `APrivateKey1zkpHmSu9zuhyuCJqVfQE8p82HXpCTLVa8Z2HUNaiy9mrug2`
        
    *   **Address**: `aleo1c45etea8czkyscyqawxs7auqjz08daaagp2zq4qjydkhxt997q9s77rsp2`
        
3.  **Voter 2**
    
    *   **Private Key**: `APrivateKey1zkp6NHwbT7PkpnEFeBidz5ZkZ14W8WXZmJ6kjKbEHYdMmf2`
        
    *   **Address**: `aleo1uc6jphye8y9gfqtezrz240ak963sdgugd7s96qpuw6k7jz9axs8q2qnhxc`
        

To propose a new ballot, set up the `.env` file for the proposer:

Copy code

Run the propose function:

Copy code

`leo run propose "{ title: 2077160157502449938194577302446444field, content: 1452374294790018907888397545906607852827800436field, proposer: aleo1rfez44epy0m7nv4pskvjy6vex64tnt0xy90fyhrg49cwe0t9ws8sh6nhhr }"`

This generates a new record with the proposal information and sets a public mapping with the proposal ID.

##### **Step 1: Voter 1 Issues a Ticket and Votes**

Set up the `.env` file for voter 1:

Copy code

`echo " NETWORK=testnet3 PRIVATE_KEY=APrivateKey1zkpHmSu9zuhyuCJqVfQE8p82HXpCTLVa8Z2HUNaiy9mrug2 " > .env`

Create a new ticket:

Copy code

`leo run new_ticket 2264670486490520844857553240576860973319410481267184439818180411609250173817field aleo1c45etea8czkyscyqawxs7auqjz08daaagp2zq4qjydkhxt997q9s77rsp2`

Vote using the ticket:

Copy code

`leo run agree "{ owner: aleo1c45etea8czkyscyqawxs7auqjz08daaagp2zq4qjydkhxt997q9s77rsp2.private, pid: 2264670486490520844857553240576860973319410481267184439818180411609250173817field.private, _nonce: 1738483341280375163846743812193292672860569105378494043894154684192972730518group.public }"`

##### **Step 2: Voter 2 Issues a Ticket and Votes**

Set up the `.env` file for voter 2:

Copy code

`echo " NETWORK=testnet3 PRIVATE_KEY=APrivateKey1zkp6NHwbT7PkpnEFeBidz5ZkZ14W8WXZmJ6kjKbEHYdMmf2 " > .env`

Create a new ticket:

Copy code

`leo run new_ticket 2158670485494560943857353240576760973319410481267184429818180411607250143681field aleo1uc6jphye8y9gfqtezrz240ak963sdgugd7s96qpuw6k7jz9axs8q2qnhxc`

Vote using the ticket:

Copy code

`leo run disagree "{ owner: aleo1uc6jphye8y9gfqtezrz240ak963sdgugd7s96qpuw6k7jz9axs8q2qnhxc.private, pid: 2158670485494560943857353240576760973319410481267184429818180411607250143681field.private, _nonce: 6511154004161574129036815174288926693337549214513234790975047364416273541105group.public }"`

##### **Step 3: How Votes Are Tallied**

Votes are kept private, but the total number of agreements and disagreements are displayed on-chain in the public mapping. You can query this data on-chain.

By following these steps, you can effectively use the `vote.leo` program to create proposals and cast votes while maintaining voter anonymity. This secure and transparent voting mechanism showcases the powerful capabilities of Leo in handling complex cryptographic tasks.

---

*Originally published on [gameovermachine.eth](https://paragraph.com/@gameovermachine/create-your-own-vote-system-with-leo)*
