Transaction
FDAC9BFA9F1B82…D2AD52521AA5
Block 26,004 · index 0 · indexed
Summary
- Hash
- FDAC9BFA9F1B827F15C7A347B38EAC783671D37F7F0EC1AB32ADD2AD52521AA5
- Block
- 26,004
- Size
- 6362 bytes
- Gas used
- 10,648,723 / 12,778,527
- Fee
- 1000000ugnot
- Memo
- gnopublish
- Status
- success
Messages
Arguments · 9
- #1counter
- #2README.md
- #3# Counter Club > ⚠️ **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](https://github.com/moul/gno-contracts/blob/main/r/moul/x/daily/README.md) --- A single shared integer counter that anyone on the chain can nudge. Every call to `Inc`, `Dec`, or `Reset` mutates the global value and appends a record to a rolling log of the last 20 changes (caller address, delta, new value, block height). The realm's `Render` shows the current value big, the total number of changes ever made, and a table of the recent history. **Realm path:** `gno.land/r/REPLACE_ADDR/counter` ## Example calls ```sh # Increment the shared counter gnokey maketx call -pkgpath "gno.land/r/REPLACE_ADDR/counter" \ -func Inc -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid sapphire-1 KEY # Decrement it gnokey maketx call -pkgpath "gno.land/r/REPLACE_ADDR/counter" \ -func Dec -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid sapphire-1 KEY # Reset back to zero gnokey maketx call -pkgpath "gno.land/r/REPLACE_ADDR/counter" \ -func Reset -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid sapphire-1 KEY ``` View the current value and history by rendering the realm in a gno.land explorer or with `gnokey query vm/qrender --data "gno.land/r/REPLACE_ADDR/counter:"`. <!-- BEGIN GNOCONTRACTS FOOTER (generated by `make readmes`; do not edit below) --> --- Part of **[moul/gno-contracts](https://github.com/moul/gno-contracts)** — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage. > 🧪 **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](https://github.com/moul/gno-contracts/blob/main/DISCLAIMER.md). <!-- END GNOCONTRACTS FOOTER -->
- #4counter.gno
- #5// Package counter implements "Counter Club": a single shared integer counter // with a rolling history of the last 20 mutations. Anyone may Inc, Dec, or // Reset the value; every change records the caller, the delta applied, the // resulting value, and the block height it happened at. package counter import ( "chain" "chain/runtime" "chain/runtime/unsafe" "strconv" "strings" ) // maxHistory is the number of recent changes kept in the log. const maxHistory = 20 // change is a single recorded mutation of the counter. type change struct { caller address // who triggered the change delta int // how much the value moved (+1, -1, or reset amount) value int // the resulting counter value after the change height int64 // block height at which it occurred } // value is the current shared counter. var value int // total counts every mutation ever applied (not capped, unlike history). var total int // history holds the last maxHistory changes, oldest first. var history []change // record appends a change to the history, trimming to the last maxHistory. func record(delta, newValue int) { c := change{ caller: unsafe.PreviousRealm().Address(), delta: delta, value: newValue, height: runtime.ChainHeight(), } history = append(history, c) if len(history) > maxHistory { history = history[len(history)-maxHistory:] } total++ chain.Emit( "CounterChange", "delta", strconv.Itoa(delta), "value", strconv.Itoa(newValue), ) } // Inc adds one to the shared counter and logs the change. func Inc(cur realm) int { value++ record(1, value) return value } // Dec subtracts one from the shared counter and logs the change. func Dec(cur realm) int { value-- record(-1, value) return value } // Reset sets the shared counter back to zero and logs the change. The recorded // delta is the amount required to bring the previous value to zero. func Reset(cur realm) int { delta := -value value = 0 record(delta, value) return value } // Value returns the current counter value (read-only helper). func Value() int { return value } // Total returns the total number of mutations ever applied. func Total() int { return total } // Render produces a Markdown view: the big current value, the total number of // changes, and a table of the most recent changes (newest first). func Render(path string) string { var b strings.Builder b.WriteString("# Counter Club\n\n") b.WriteString("A shared counter anyone can Inc, Dec, or Reset. ") b.WriteString("The last ") b.WriteString(strconv.Itoa(maxHistory)) b.WriteString(" changes are logged below.\n\n") // Big current value. b.WriteString("## Current value\n\n") b.WriteString("# ") b.WriteString(strconv.Itoa(value)) b.WriteString("\n\n") b.WriteString("**Total changes:** ") b.WriteString(strconv.Itoa(total)) b.WriteString("\n\n") // Recent history, newest first. b.WriteString("## Recent history\n\n") if len(history) == 0 { b.WriteString("_No changes yet — be the first to count!_\n") return b.String() } b.WriteString("| # | Caller | Delta | New value | Height |\n") b.WriteString("|---|--------|-------|-----------|--------|\n") n := len(history) for i := n - 1; i >= 0; i-- { c := history[i] b.WriteString("| ") b.WriteString(strconv.Itoa(n - i)) b.WriteString(" | ") b.WriteString(c.caller.String()) b.WriteString(" | ") b.WriteString(signed(c.delta)) b.WriteString(" | ") b.WriteString(strconv.Itoa(c.value)) b.WriteString(" | ") b.WriteString(strconv.FormatInt(c.height, 10)) b.WriteString(" |\n") } return b.String() } // signed formats an int with an explicit leading sign for non-negative values. func signed(n int) string { if n >= 0 { return "+" + strconv.Itoa(n) } return strconv.Itoa(n) }
- #6gnomod.toml
- #7module = "gno.land/r/moul/x/daily/counter/v0" gno = "0.9"
- #8/gno.MemPackageType
- #9 MPUserProd
Result log
msg:0,success:true,log:,events:[]