The Voting example based on MoonZoon and Solana + Anchor framework.

Overview

MoonZoon Solana logos

Warning: The implementation is blocked by https://github.com/project-serum/anchor/issues/883 - Anchor seems to be designed to work only with JS clients and I don't have enough free time and motivation to go through xxx lines of macros and JS atm, help welcome. See the original Rust-only Voting example with the "raw" Solana API.

Voting example (with Anchor)

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

  • MoonZoon is a Rust Fullstack Framework.

  • Solana is a decentralized blockchain.

  • Anchor is framework for building and interacting with smart contracts on Solana.

  • Notes:

    • This is not an official Solana example. The author is the MoonZoon's creator.
    • The original Voting example with the "raw" Solana API.

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...
⚓ Solana Sealevel Framework

Anchor ⚓ Anchor is a framework for Solana's Sealevel runtime providing several convenient developer tools. Rust eDSL for writing Solana programs IDL s

CosmWasm-Examples is a collection of example contracts and applications built using the CosmWasm framework

CosmWasm-Examples is a collection of example contracts and applications built using the CosmWasm framework. CosmWasm is a secure and efficient smart contract platform designed specifically for the Cosmos ecosystem.

Example worker for ethereum-based applications

Ethsig-rs Example worker for ethereum-based applications. Features: Verify arbitrary messages and their signature from an Ethereum Address Verify EIP-

A suite of programs for Solana key management and security.
A suite of programs for Solana key management and security.

🔑 goki Goki is a suite of programs for Solana key management and security. It currently features: Goki Smart Wallet: A wallet loosely based on the Se

Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana (WIP) ⛏👷🚧⚠️
Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana (WIP) ⛏👷🚧⚠️

Solana BPF Boilerplate Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana This boilerplate provides the following. Si

🧑‍✈ Version control and key management for Solana programs.

captain 🧑‍✈️ Version control and key management for Solana programs. Automatic versioning of program binaries based on Cargo Separation of deployer a

Making Token Exchange program with Solana(Rust), Web3, and Vue
Making Token Exchange program with Solana(Rust), Web3, and Vue

Escrow program for Solana blockchain Tech stack Program (Smart Contract) Rust crates: solana-program, spl-token Solana CLI for test validator UI Types

Galleries of NFTs using Solana and Rust for contracts

About this Package created to simplify the process of parsing NFTs on Solana. It consists of: Package basic things like fetch all NFTs for specific wa

hello-world geyser plugin to stream accounts and transactions from a solana node

src/lib.rs: entrypoint src/plugin.rs: main plugin code to run: cargo build && solana-test-validator -r --geyser-plugin-config config.json note: make s

Comments
  • thread 'tokio-runtime-worker' panicked at 'get_recent_blockhash failed

    thread 'tokio-runtime-worker' panicked at 'get_recent_blockhash failed

    Hi there,

    Getting below error when building, kindly advice on a fix or workaround:

    thread 'tokio-runtime-worker' panicked at 'get_recent_blockhash failed: ClientError { request: Some(GetLatestBlockhash), kind: RpcError(RpcResponseError { code: -32601, message: "Method not found", data: Empty }) }', backend/src/solana_helpers.rs:67:14
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    thread 'main' panicked at 'get_recent_blockhash task failed: JoinError::Panic(...)', backend/src/solana_helpers.rs:70:6
    
    opened by jjoek 0
  • Solana Moonzoon Connection

    Solana Moonzoon Connection

    When I start the Monsoon front end, the Solana connection doesn't work. I can verify my Solana test cluster through CLI and visiting http://localhost:8899

    % ./mzoon start -o
    Start { release: false, open: true }
    Building frontend...
        Finished dev [unoptimized + debuginfo] target(s) in 0.43s
    [WARN]: ⚠️   There's a newer version of wasm-pack available, the new version is: 0.10.2, you are using: 0.10.1. To update, navigate to: https://rustwasm.github.io/wasm-pack/installer/
    Frontend built
    Building backend...
        Finished dev [unoptimized + debuginfo] target(s) in 0.56s
    Backend built
    Run backend
    Open http://localhost:8080 in the default web browser
    voting_state_pubkey: 4MPyVsUgCHHmapxrGNA79MZZtaciEUiLGCvusdDQfmqU
    thread 'tokio-runtime-worker' panicked at 'get_recent_blockhash failed: ClientError { request: Some(GetLatestBlockhash), kind: RpcError(RpcResponseError { code: -32601, message: "Method not found", data: Empty }) }', backend/src/solana_helpers.rs:67:14
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    thread 'main' panicked at 'get_recent_blockhash task failed: JoinError::Panic(...)', backend/src/solana_helpers.rs:70:6
    
    opened by awcchungster 1
  • Readme Instructions Error

    Readme Instructions Error

    Hi there,

    I wanted to modify this application for a Node.js app I want to build. When I run the setup instructions:

    solana program deploy -C ./config.yml --program-id ./keypairs/program-keypair.json ./target/deploy/voting_program.so

    I get an error:

    ====================================================================================
    Recover the intermediate account's ephemeral keypair file with
    `solana-keygen recover` and the following 12-word seed phrase:
    ====================================================================================
    utility party scissors feed scene model dilemma yellow fly notable describe hedgehog
    ====================================================================================
    To resume a deploy, pass the recovered keypair as the
    [BUFFER_SIGNER] to `solana program deploy` or `solana write-buffer'.
    Or to recover the account's lamports, pass it as the
    [BUFFER_ACCOUNT_ADDRESS] argument to `solana program close`.
    ====================================================================================
    Error: Account ABvSTfThyznpECJqQiJ8vffsrHjnHCn7FzCGDUM2YUxC has insufficient funds for spend (1.7578524 SOL) + fee (0.00127 SOL)
    

    The current wallet also needs SOL to run. solana airdrop 10 -C config.yml

    opened by awcchungster 1
Owner
Martin Kavík
MoonZoon.rs creator, OpenHope.net founder and Seed-rs.org maintainer
Martin Kavík
Solana NFT marketplace boilerplate with anchor & react & candy-machine-cli

The Heros NFT Marketplace Boilerplate project is designed to let users fork, customize, and deploy their own nft marketplace app to a custom domain, ultra fast.

null 30 Dec 15, 2022
Solana NFT marketplace boilerplate with anchor & react & candy-machine-cli

Solana_Marketplace_HerosNFT The Heros NFT Marketplace Boilerplate project is designed to let users fork, customize, and deploy their own nft marketpla

null 30 Dec 15, 2022
Write Anchor-compatible Solana programs in TypeScript

Axolotl Write Achor-compatible Solana programs using TypeScript. Writing Rust is hard, but safe. It's also the go-to language for writing Solana progr

Anthony Morris 17 Nov 27, 2022
L2 validity rollup combined with blind signatures over elliptic curves inside zkSNARK, to provide offchain anonymous voting with onchain binding execution on Ethereum

blind-ovote Blind-OVOTE is a L2 voting solution which combines the validity rollup ideas with blind signatures over elliptic curves inside zkSNARK, to

Aragon ZK Research 3 Nov 18, 2022
Marinde Anchor-Based, first on mainnet, liquid-staking-program and mSOL->SOL swap pool

marinade-anchor Marinade-finance liquid staking program for the Solana blockchain Audits & Code Review Kudelski Security: https://marinade.finance/Kud

Marinade.Finance 42 Dec 11, 2022
Demonstrates Solana data account versioning used in supporting the Solana Cookbook article: Account Data Versioning

versioning-solana This repo demonstrates ONE rudimentary way to upgrade/migrate account data changes with solana program changes. What is data version

Frank V. Castellucci 6 Sep 30, 2022
Token management program (vesting and mining) implemented in Anchor

Deep Dive into Anchor by Implementing Token Management Program Author: @ironaddicteddog, @emersonliuuu [Updated at 2022.5.21] You can find the full co

Jim 31 Jun 13, 2023
A framework for creating PoC's for Solana Smart Contracts in a painless and intuitive way

Solana PoC Framework DISCLAIMER: any illegal usage of this framework is heavily discouraged. Most projects on Solana offer a more than generous bug bo

Neodyme 165 Dec 18, 2022
Simple (not simplest) UST vault that integrate with Anchor Protocol

Simple (not simplest) UST Vault Building a simple UST Vault that generate yield from Anchor while also have UST reserved for lending, and etc. This co

Kiettiphong Manovisut 2 May 3, 2022
Anchor Design of contract - Accounts, Parameters

MarketplaceDesign Anchor Design of contract - Accounts, Parameters Main Instructions are Initialize ListForSale AcceptOffer CancelList MakeOffer Cance

James Johnson 8 Sep 1, 2022