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

README.md

1.74 Kb · 35 lines

gno.land/r/moul/demo/data

Step 3 of the r/moul/demo walkthrough: realm state that persists between transactions.

1var total int
2
3func init()          { total = 1000 }
4func Add(nb int) int { total += nb; return total }

total is a package-level variable in a realm, so the VM persists it after every call. init runs once, at deploy time, not on each call. Call Add(42) then Add(295) and the second call returns 1337: the mutation from the first one was committed to chain storage.

That is the whole difference between a p/ package (no state of its own) and an r/ realm.

Previous: args. Next: render exposes state through gnoweb.


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

On mainnet: deployment status transactions unique callers deployed revision

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.