Search Apps Documentation Source Content File Folder Download Copy Actions Download

dice package

Overview

Package dice implements a provably-fair on-chain dice game for gno.land.

There is no true randomness on-chain: every node must reach the same result deterministically. Instead, each roll derives its 1-6 face from public block entropy (chain height) mixed with the caller address and the caller's roll count. The derivation is fully reproducible from public data, which is what "provably fair" means here — anyone can recompute a roll and verify it.

Functions

Distribution

func Distribution() [6]int

Distribution returns the global per-face counts, faces 1-6.

Command

gnokey query vm/qeval -remote "https://rpc.test13.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/dice.Distribution()"

Result

Render

func Render(path string) string

Render returns the realm's gnoweb Markdown view.

Render is NOT a crossing function (no `cur realm` param) — it is a read-only query surface. It shows the total roll count, a distribution bar chart for faces 1-6, and the most recent rolls.

Param

Command

gnokey query vm/qeval -remote "https://rpc.test13.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/dice.Render()"

Result

Roll

func Roll(cur realm) int

Roll performs one dice roll for the calling account and records it.

It is a crossing function (gno 0.9 interrealm convention: `cur realm` first parameter). Callers invoke it as Roll(cross(cur)). The result is derived deterministically from the current block height, the caller address, and the caller's prior roll count — no stored secret, fully verifiable.

Command

# 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/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/dice" -func "Roll" -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "test-13" -remote "https://rpc.test13.testnets.gno.land" ADDRESSgnokey query -remote "https://rpc.test13.testnets.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/dice" -func "Roll" -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "test-13" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.test13.testnets.gno.land" call.tx
  

RollsOf

func RollsOf(addr string) []int

RollsOf returns the recorded roll history for an address (oldest first). Read-only helper, safe to call as a query.

Param

Command

gnokey query vm/qeval -remote "https://rpc.test13.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/dice.RollsOf()"

Result

Total

func Total() int

Total returns the global roll count.

Command

gnokey query vm/qeval -remote "https://rpc.test13.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/dice.Total()"

Result