Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 source realm

Package polls is an on-chain poll / voting realm for gno.land.

Readme View source

Polls & Voting

⚠️ Experimental — generated with no human supervision. This realm was produced automatically by an MCP-driven agent to exercise the gno MCP server and tooling, and to generate test content for gno compilers, linters and formatters. Not audited. Not for production. Full context & folder README: r/moul/x/daily


An on-chain poll and voting realm for gno.land (sapphire, gno 0.9). Anyone can create a poll with a question and a comma-separated set of options; every caller address may cast exactly one vote per poll. The realm's Render page lists each poll with its options, live tallies drawn as ▓░ bar charts, per-option percentages, and the total number of votes.

Realm path

gno.land/r/REPLACE_ADDR/polls

Exported transactions

  • CreatePoll(question string, options string) int — create a poll. options is a comma-separated list (blank entries are dropped; at least 2 required). Returns the new poll's id.
  • Vote(pollID int, optionIndex int) — cast one vote for optionIndex on poll pollID. One vote per caller address per poll; a second vote aborts.

Both are gno 0.9 crossing functions (first parameter cur realm); the caller address is read via runtime.PreviousRealm().Address().

Read path

  • Render("") — index of all polls with bar-chart tallies.
  • Render("<id>") — a single poll by id.

Example calls

 1# create a poll (returns its id, e.g. 0)
 2gnokey maketx call -pkgpath "gno.land/r/REPLACE_ADDR/polls" \
 3  -func CreatePoll -args "Best L1 for smart contracts?" -args "gno,eth,sol" \
 4  -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid sapphire-1 mykey
 5
 6# vote for option index 0 on poll 0
 7gnokey maketx call -pkgpath "gno.land/r/REPLACE_ADDR/polls" \
 8  -func Vote -args 0 -args 0 \
 9  -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid sapphire-1 mykey
10
11# view results in gnoweb
12#   https://gno.land/r/REPLACE_ADDR/polls
13#   https://gno.land/r/REPLACE_ADDR/polls:0

Testing

1gno test .

Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

Dependency graph:

gno.land/r/moul/x/daily/polls/v0 dependency graph

🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.

Overview

Package polls is an on-chain poll / voting realm for gno.land.

Anyone can create a poll with a question and a comma-separated list of options. Each caller address may cast exactly one vote per poll. Render draws every poll with its options, tallies as ▓░ bar charts, percentages and the total vote count.

Functions 4

func CreatePoll

crossing Action
1func CreatePoll(cur realm, question string, options string) int
source

CreatePoll registers a new poll. options is a comma-separated list; blank entries are dropped. Returns the new poll's id. Crossing function: an EOA invokes it via MsgCall; another realm via polls.CreatePoll(cross, q, opts).

func PollCount

Action
1func PollCount() int
source

PollCount returns the number of polls created so far (read-only helper).

func Render

1func Render(path string) string
source

Render produces the Markdown page for gnoweb. It is NOT a crossing function.

  • "" -> index of all polls
  • "<id>" -> a single poll by id

func Vote

crossing Action
1func Vote(cur realm, pollID int, optionIndex int)
source

Vote casts one vote for optionIndex on poll pollID. Each caller address may vote at most once per poll. Crossing function.

Types 1

type Poll

struct
1type Poll struct {
2	ID       int
3	Question string
4	Options  []string
5	Tallies  []int
6	Creator  string    // bech32 address of the poll creator
7	voted    *avl.Tree // address string -> struct{}{}, one vote per address
8}
source

Poll is a single question with its options and per-address vote tracking.

Imports 5

Source Files 3