The Voting example based on MoonZoon and Solana.

Overview

MoonZoon Solana logos

Voting example

The Rust-only Voting example based on MoonZoon and Solana.

  • MoonZoon is a Rust Fullstack Framework.

  • Solana is a decentralized blockchain.

  • Note: This is not an official Solana example. The author is the MoonZoon's creator.

Pages


Run on a local machine

Follow the steps in ./program/README.md and then the ones in ./app/README.md.


Pages

Add Voter

The page allows you to add a voter.

  • A voter is a regular Solana account. The app makes the voter eligible for voting by creating a voter votes account associated with the given voter and the voting state.

  • A voting state is an account created by the app during the start (if not created yet) and associated with the voting owner. Voters are allowed to vote for 1 week - the deadline is set in the voting state account.

  • A voting owner is an account fully controlled by the app.

  • You can find the pre-filled text input values in:

Note: See the section Architecture for the visual representation of all relations.

Add Voter page

Add Party

The page allows you to add a party.

  • A party is an account created by the app with the required party name and associated with the voting state.

  • Everybody with a sufficient amount of lamports can create a party.

  • You can find the pre-filled private key in:

Note: You need to insert the private key in the text input because wallet integrations is out of scope of this example.

  • There wasn't (?) a Rust wallet connector at the time of writing and developing a new one from scratch or writing binding for JS libs like sol-wallet-adapter is too time consuming.

Add Party page

Parties

The page allows you to vote for the selected party.

  • You can vote if you are eligible for voting (i.e. you've been registered on the page "Add Voter".)

  • You have 2 positive votes and 1 negative votes.

  • You can vote only once for each party.

  • You can send your negative vote only after you've already spent all your positive votes.

  • Party votes are updated in real time (just like adding a party).

  • You can find the pre-filled private key in:

Note: This kind of a voting system is called D21 - Janeček method.

Parties page


Architecture

The frontend part is based on the VDOM-less Rust frontend framework Zoon and compiled to Wasm. It means we can use the crate solana-sdk directly instead of using intermediate Javascript libraries (@solana/web3.js).

The advantages are:

  • Reduced complexity caused by multiple languages and their ecosystems in one project. It leads to faster development, better Developer eXperience and fewer bugs.

  • Improved performance thanks to Wasm + Rust. I can imagine that especially cryptographic operations are much faster in the Wasm runtime and could be parallelized in the future (if we can't use native browsers APIs like Web Crypto API). Also Zoon is faster than React or Svelte according to the benchmarks.

  • Onboarding and collaboration among team members should be easier thanks to one language in the tech stack and Rust static typing and other features.

The frontend doesn't communicate directly with the blockchain because:

  • There is a business logic implemented in the backend. It also needs the access to the voting owner's keypair.

  • The crate solana-client isn't suitable for the frontend - e.g. the transitive dependency url may even double the output Wasm file size. serde is another "heavy" dependency that could be replaced in the future.

  • solana-client doesn't cover all Solana real-time APIs currently.

  • Solana APIs are rate limited. We can, for instance, cache responses to avoid client fails.

  • The combination Fetch + Server-Sent Events may be superior to WebSockets in some cases (e.g. better compatibility with proxies and firewalls). However it depends on the app requirements.

  • The blockchain isn't very suitable for (complex) queries. You can query data mirrored in a database instead.

Note: The schema below has been generated from the file ./docs/architecture.puml.

Architecture


Contributing

  • Share your ideas and opinions on the MoonZoon Discord.

  • File an issue in the GitHub repo when you encounter a bug or problems in docs.

  • Please use cargo fmt and cargo clippy and squash commits if it makes sense (I rebase PRs).


Solana Questions & Answers

It's my (@MartinKavik) first project with Solana / blockchain. Naturally, I had some beginner questions about the API, architecture and best practices. And I was lucky enough to get answers from the Solana master @jstarry who works in Solana Labs.

So I recommend to read these Q&A before your start to work on your Solana project. (Note: The repo hasn't been updated to follow recommendations mentioned in the answers.)

Questions.md

You might also like...
Example of structuring a proc macro crate for testability

testing-proc-macros Example of structuring a proc macro crate for testability. See accompanying blog post for details. License Licensed under either o

A example bevy application using bevy-kajiya for its renderer
A example bevy application using bevy-kajiya for its renderer

☀️ bevy-kajiya playground A example bevy application using bevy-kajiya for its renderer NOTE: only tested on Windows. For more context, check out the

Example of reading the BME280 sensor on an ESP32-C3 using Rust

Rust ESP32-C3 BME280 Example of reading the BME280 sensor on an ESP32-C3 using Rust Hardware: ESP32-C3 microcontroller BME280 sensor Breadboard Jump w

dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle!

dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle (such as rewriting/refactroing your DM code).

Pbot - pan93412's extensible userbot, which is full-documented, enginnered and based on Actor model.

pbot pan93412's extensible user bot, which is full-documented, engineered and based on Actor model. Usage Run cargo run --release [--features modules

Equilibrium substrate-based node implementation and runtime
Equilibrium substrate-based node implementation and runtime

Equilibrium & Genshiro Equilibrium is a DeFi 2.0 cross-chain money market protocol with high leverage. With Equilibrium users can: Lend: lend out asse

A dynamic output configuration tool that automatically detects and configures connected outputs based on a set of profiles.

shikane A dynamic output configuration tool that automatically detects and configures connected outputs based on a set of profiles. Each profile speci

Swayidle alternative to handle wayland idle notifications, sleep and lock events in Rust with Lua scripting based configuration language

swayidle-rs This is intended as a replacement of sway's idle management daemon. I use it as a tool to understand rust message passing and state manage

mdzk is a plain text Zettelkasten system that is based on the mdBook API.

mdzk A lovingly designed system and static publishing tool for your plain text Zettelkasten mdzk is a plain text Zettelkasten system that is based on

Owner
Martin Kavík
MoonZoon.rs creator, OpenHope.net founder and Seed-rs.org maintainer
Martin Kavík
NFT Marketplace with Rust on Solana

NFT Marketplace with Rust on Solana Compile and Deploy Contracts make sure you have solana installed make sure you have rust installed install phantom

null 37 Dec 16, 2022
Solana Escrow Program

Environment Setup Install Rust from https://rustup.rs/ Install Solana from https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-to

Nathan Ramli 0 Nov 12, 2021
Solana NFT Rust

HI, There Compile and Deploy Contracts make sure you have solana installed make sure you have rust installed install phantom wallet on the browser or

gSofter 4 Mar 30, 2022
01 Solana program application interface.

01 abi The abi is a repository for interfacing with the 01 program either through a rust client or through CPIs from another Solana program. Program A

Zero One Global Foundation 19 Oct 16, 2022
Minimalistic solana minter program if you don't want to use Metaplex

Minimalistic solana minter program The objective of this repository is to be only a minimalistic template for NFTs projects on Solana, so you can buil

Gabriel 23 Sep 6, 2022
An example project demonstrating integration with Rust for the ESP32-S2 and ESP32-C3 microcontrollers.

Rust ESP32 Example An example project demonstrating integration with Rust for the ESP32-S2 and ESP32-C3 microcontrollers.

Espressif Systems 303 Jan 4, 2023
A basic rp2040-hal project with blinky and rtt logging example code.

A basic rp2040-hal project with blinky and rtt logging example code. With this you can quickly get started on a new rp2040 project

rp-rs 202 Jan 6, 2023
An example Kibana plugin written in Rust and Typescript

An example Kibana plugin written in Rust and Typescript

Aleh Zasypkin 3 Dec 24, 2022
Rust / C / Cgo example

whatever How to build (This has been tested on Linux & macOS) Build the Rust code: $ cargo build The library is in ./target/debug/libwhatever.a Build

Amos Wenger 6 Jun 21, 2022
An example of Brainf*** JIT-compiler with only the standard library.

jit-compiler An example of Brainf*** JIT-compiler with only the standard library. Prerequisite Rust(1.56.0-nightly or later, but it must work kind of

Akihito KIRISAKI 18 Jan 22, 2022