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.

v0 source pure

Readme View source

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.

Functions 2

func Call

1func Call(fn string, args ...string) string
source

Call returns a URL for the specified function with optional key-value arguments, for the current realm.

Types 2

type Realm

ident
1type Realm string
source

Realm represents a specific realm for generating tx links.

Methods on Realm

func Call

method on Realm
1func (r Realm) Call(fn string, args ...string) string
source

Call returns a URL for the specified function with optional key-value arguments.

type TxBuilder

struct
1type TxBuilder struct {
2	fn        string   // function name
3	args      []string // key-value pairs
4	send      string   // optional send amount
5	realm_XXX Realm    // realm for the URL
6}
source

TxBuilder provides a fluent interface for building transaction URLs

Methods on TxBuilder

func AddArgs

method on TxBuilder
1func (b *TxBuilder) AddArgs(args ...string) *TxBuilder
source

AddArgs adds multiple key-value pairs at once. Arguments should be provided as pairs: AddArgs("key1", "value1", "key2", "value2").

func SetSend

method on TxBuilder
1func (b *TxBuilder) SetSend(amount string) *TxBuilder
source

SetSend adds a send amount. (Only one send amount can be specified.)

func URL

method on TxBuilder
1func (b *TxBuilder) URL() string
source

URL generates the final URL using the standard $help&func=name format.

Dependencies

Imports 4

/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/txlink/v0

Imported by indexer

Source Files 4