Count
Count reports how many addresses have a reaction on page.
Command
gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/reactions/v0.Count()"
Result
Package reactions is a reaction block any realm can embed, keyed on the page it appears on rather than on the realm that stores it.
It is the shape the web settled on for this in 2010: one hosted widget, the same snippet pasted everywhere, deciding what to show from the page identifier it is handed. Here the snippet is two lines of gno:
1import "gno.land/r/moul/reactions/v0"
2
3func Render(path string) string {
4 return body + reactions.RenderBlock()
5}
RenderBlock takes no argument because it does not need one: a plain read exported by a realm and called by another opens no realm frame, so unsafe.CurrentRealm() inside it reports the CALLER. The host realm's own path is the page key, and nothing has to be configured, registered or passed. RenderBlockFor is the explicit form, for a realm that renders more than one page or already holds its path as a constant.
The host realm stores nothing. Every tally lives here, so a realm can add reactions without a redeploy the next time it wants to change them, and a reader's reaction survives the host realm being replaced.
Not a comment system. There is no text field anywhere, which is what makes it possible to run with no moderation at all: six emoji, one reaction per address per page, changeable and removable. The page shows the tally and who reacted last. That is the whole feature.
Count reports how many addresses have a reaction on page.
gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/reactions/v0.Count()"
CountOf reports how many addresses hold one particular reaction on page.
gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/reactions/v0.CountOf(,)"
Pages reports how many pages have ever been reacted to.
gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/reactions/v0.Pages()"
React records the caller's reaction to page.
page is a package path, the full one: "gno.land/r/moul/home". It does not have to be a realm that embeds the block, and nothing checks that it exists. A page is just a name, which is what lets a realm key the block on something finer than itself.
key is one of the palette names, not a glyph: "up", "heart", "fire", "party", "rocket", "eyes". Render("") lists them with their emoji.
One reaction per address per page. Reacting again with a different key moves it; reacting with the same key changes nothing but the "last reaction" line.
# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.
gnokey maketx call -pkgpath "gno.land/r/moul/reactions/v0" -func "React" -args $'' -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/reactions/v0" -func "React" -args $'' -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
ReactionOf returns who's current reaction key on page, or "" when they have none. A host realm can use it to say "you reacted" without reading the tree.
gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/reactions/v0.ReactionOf(,)"
Render serves two views:
1"" the getting-started page: how to embed the block, plus the board
2"<page>" one page's tally, where <page> is a package path
The page view's path is the key itself, so the link under any embedded block is just this realm's path, a colon, and the page. That is why a page key may contain a colon of its own: "gno.land/r/you/blog:hello" reads back whole.
gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/reactions/v0.Render()"
RenderBlock returns the block for the realm CALLING it, which is the form a host realm embeds.
It has no cur realm parameter on purpose. A plain read is borrowed: gno opens no realm frame for it, so unsafe.CurrentRealm() reports the caller's path and the block keys itself with no argument. Adding a cur realm here would silently reverse that and key every embed to this realm instead.
Calling it from inside this realm therefore keys on this realm, which is never what a caller wants; the views below use the unexported blockFor.
gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/reactions/v0.RenderBlock()"
RenderBlockFor is RenderBlock for a named page. Use it from a crossing function, where there is no caller to read off the stack, or when one realm renders several pages.
gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/reactions/v0.RenderBlockFor()"
Unreact removes the caller's reaction from page. It aborts when there is none, rather than succeeding silently, so a misspelled page key is visible instead of looking like a no-op.
# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.
gnokey maketx call -pkgpath "gno.land/r/moul/reactions/v0" -func "Unreact" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/reactions/v0" -func "Unreact" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx