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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/txlink/v0

Directory · 4 Files
README.md Open

gno.land/p/moul/txlink

Build a clickable "call this function" link for a realm's Render output, so a page can offer a transaction instead of telling the reader what to type.

1// current realm, one arg
2txlink.Call("AddTodo", "todo", "buy milk")
3// -> /r/moul/home$help&func=AddTodo&todo=buy+milk
4
5// builder, with a send amount
6txlink.NewLink("Donate").
7	AddArgs("message", "thanks").
8	SetSend("1000000ugnot").
9	URL()

The output is the gnoweb $help&func= form: following it opens the help page with the function selected and the arguments pre-filled. The user still signs. Nothing here broadcasts, and nothing here can.

Three prefixes, picked for you

Realm.prefix() decides what the link is relative to:

Realm value link
"" (the default) the current realm, read from CurrentRealm().PkgPath()
a path on this chain /r/..., chain domain trimmed
a path on another chain https://<that domain>/r/...

So txlink.Call(...) in a realm links to itself, and txlink.Realm("gno.land/r/other/x").Call(...) links to a neighbour, without either caller hardcoding a domain. Do not build the string yourself: a hardcoded self-link is wrong the moment the realm moves, which r/moul/demo/render still demonstrates by accident.

Details that bite

  • Arguments are key/value pairs, so an odd count panics. AddArgs takes them flat ("k1", "v1", "k2", "v2").
  • A key starting with . panics. .send is reserved; use SetSend.
  • The builder is nil-safe. NewLink("") returns nil and every method on a nil builder returns nil, so a chain never panics halfway; URL() on it returns "".
  • func= is kept first in the query string on purpose, ahead of the url-encoded rest, so the links stay readable.

Related: p/moul/helplink is the fuller version of the same idea; txlink is the streamlined one. For parsing the path on the way in, see p/moul/realmpath.


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

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