Skip to content Search Apps Documentation Source Content Run Reset Eval Playground 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.

v2 source pure

Package engine is the "art as code" contract, version 2 (design §5.2, mainnet plan §2.3): what an engine implements, ...

Overview

Package engine is the "art as code" contract, version 2 (design §5.2, mainnet plan §2.3): what an engine implements, what core hands it, and the conformance rules both core and engine authors check against.

v2 adds media engines (uploaded raster/IPFS art that core itself can serve as TokenURI), per-collection trait types and a launch gate. Input, Trait, SampleInput and SampleSeed are byte-for-byte the v1 definitions, so an engine's sample fingerprint does not move when it is re-issued against v2.

An engine is registered from its own /r/ adapter realm. Because the adapter's methods are declared in that realm, core calling them runs the engine with the adapter's authority, never core's (interrealm v2 borrow rule #1). Methods receive and return plain values only: an engine never gets a reference into core state.

Constants 5

const KindSVG, KindMedia

1const (
2	// KindSVG: Render is the token's art (an allowlisted SVG).
3	KindSVG = "svg"
4	// KindMedia: Media is the token's art (a checked raster/SVG file or an
5	// ipfs:// CIDv1); Render is the token's "card", an allowlisted SVG that
6	// SVG-only clients and gnoweb show.
7	KindMedia = "media"
8)
source

Engine kinds (Manifest.Kind).

const MaxSVGBytes, MaxTraits, MaxTraitLen, MaxNameLen, MaxVersionLen, MaxDescLen, MaxLicenseLen, MaxParamsSchema, MaxFeeBps, MaxMediaBytes, MaxMediaSVGBytes, MaxDim

 1const (
 2	MaxSVGBytes     = 65536
 3	MaxTraits       = 32
 4	MaxTraitLen     = 64
 5	MaxNameLen      = 64
 6	MaxVersionLen   = 32
 7	MaxDescLen      = 1024
 8	MaxLicenseLen   = 64
 9	MaxParamsSchema = 4096
10	MaxFeeBps       = 500 // 5%: hard cap of an engine author's fee
11
12	// Media limits (I-15).
13	MaxMediaBytes    = 262144 // on-chain raster per token
14	MaxMediaSVGBytes = 16384  // on-chain SVG served as media (AssertSVG cost)
15	MaxDim           = 4096   // px per side, decompression-bomb guard
16)
source

Limits core enforces on every engine.

const ModeReveal, ModeOpen

1const (
2	ModeReveal = ""
3	ModeOpen   = "open"
4)
source

Launch modes as core passes them in Collection.Mode (the same values as types.ModeReveal and types.ModeOpen).

const IPFSScheme

1const IPFSScheme = "ipfs://"
source

IPFSScheme prefixes Media.URI.

Functions 9

func CheckMedia

1func CheckMedia(m Manifest, md Media) error
source

CheckMedia is the rule core applies to a media engine's Media before it serves it as TokenURI (I-15). Accepted:

  • Data: Mime one of the four media types; SVG <= MaxMediaSVGBytes and AssertSVG; a raster <= min(m.MaxMediaBytes, MaxMediaBytes) whose magic and header dimensions (1..MaxDim) match Mime; Sha256 equal to sha256(Data);
  • URI: "ipfs://" + a CIDv1 (base32, raw or dag-pb, sha2-256); Mime one of the four types; Sha256 "" or 64 lower-case hex, and for a raw CID equal to the CID's digest.

Everything else — both or neither set, another scheme, CIDv0, an unknown mime — is an error.

func CheckSVG

1func CheckSVG(m Manifest, svg string) error
source

CheckSVG is the output rule core applies to every render (art of an SVG engine, card of a media engine).

func Conformance

1func Conformance(e Engine, samples int) error
source

Conformance is the self-test engine authors run in their _test.gno before registering: manifest, default params and trait types, determinism, size, SVG hygiene, traits, media (KindMedia: CheckMedia or Media{}; KindSVG: Media{}), and — for non-living engines — independence from the living fields.

func SampleSeed

1func SampleSeed(i int) string
source

SampleSeed returns the i-th Studio/conformance sample seed (as v1).

func ValidateManifest

1func ValidateManifest(m Manifest) error
source

ValidateManifest checks sizes, text hygiene, the author address and the kind.

func ValidateTraitTypes

1func ValidateTraitTypes(tts []string) error
source

ValidateTraitTypes checks a trait list: at most MaxTraits non-empty, unique names that pass CheckText(MaxTraitLen).

func ValidateTraits

1func ValidateTraits(m Manifest, ts []Trait) error
source

ValidateTraits checks one Traits() result against the manifest's trait list (v1 signature; static engines).

func ValidateTraitsFor

1func ValidateTraitsFor(tts []string, ts []Trait) error
source

ValidateTraitsFor checks one Traits() result against a collection's trait list: known types, each at most once, values CheckText(MaxTraitLen).

func SampleInput

1func SampleInput() Input
source

SampleInput is the fixed input of an engine's fingerprint: core renders it at registration and stores sha256(svg); anyone can recompute it later. Identical to engine/v1's.

Types 8

type Collection

struct
 1type Collection struct {
 2	ID        string  // the collection id (bare, e.g. "12")
 3	Creator   address // the creator core records (a wallet or a realm, K-2)
 4	Params    string  // already accepted by ValidateParams
 5	MaxSupply int64
 6	// Mode is the launch mode in GateLaunch (ModeReveal or ModeOpen); ""
 7	// in GateCreate (a Draft has no mode yet).
 8	Mode string
 9	// Soulbound: the collection's tokens can never be transferred or
10	// approved (fixed at creation).
11	Soulbound bool
12}
source

Collection is what core tells an engine's gates about one collection. Plain values only: an engine never gets a reference into core state.

type CreateGate

interface
1type CreateGate interface {
2	GateCreate(c Collection) error
3}
source

CreateGate is the create-time check with the creator: core.CreateCollection calls GateCreate after ValidateParams and TraitTypes accepted the params; an error aborts the creation ("create refused by engine: …"). This is where an engine checks who may use which params (e.g. that the creator owns the asset store the params name) instead of reading OriginCaller.

type Engine

interface
 1type Engine interface {
 2	Manifest() Manifest
 3	ValidateParams(params string) error
 4	// TraitTypes is the trait list of a collection created with params
 5	// (already accepted by ValidateParams). Static engines return
 6	// Manifest().TraitTypes.
 7	TraitTypes(params string) []string
 8	// CheckLaunch is the engine's launch gate: an error aborts core.Launch
 9	// (e.g. an upload collection without a bound store, T14). Everything it
10	// needs is passed in; nil for generative engines.
11	CheckLaunch(cid, params string, maxSupply int64) error
12	Traits(in Input) []Trait
13	// Render is the token's art (KindSVG) or its card (KindMedia).
14	Render(in Input) string
15	// Media is the token's art for KindMedia; Media{} for KindSVG.
16	Media(in Input) Media
17}
source

Engine is implemented by a stateless value declared in the adapter realm.

Contract: deterministic in its arguments; ValidateParams("") must accept the engine's defaults; Render returns raw SVG (core does the base64); Traits only uses types listed in TraitTypes(params), each at most once.

Where core runs engine code (I-12/I-16): every read; and on a state-changing path only in the engine user's own transaction — RegisterEngine (Manifest, ValidateParams(""), Render and Traits of the sample), CreateCollection (ValidateParams, TraitTypes) and Launch (CheckLaunch). Core never hands an engine its cur.

type Input

struct
 1type Input struct {
 2	Seed           string // 64-hex final seed (sample seeds in Studio)
 3	Params         string // collection params, in the engine's own format
 4	CollectionID   string
 5	TokenID        string
 6	MintHeight     int64
 7	LastMoveHeight int64 // patina: holding time = Height - LastMoveHeight
 8	Moves          int64 // transfers so far
 9	Height         int64 // height of the read (fixed by Verify)
10	// Salt is the collection's final salt (64 hex; Seed = safe.Seed(cid,
11	// tid, Salt)), so a collection-level engine needs no read-back of core.
12	Salt string
13	// FirstOwner is the address the token was minted to (a sale mint or a
14	// creator reserve); it never changes, whoever holds the token now.
15	FirstOwner address
16}
source

Input is everything an engine may depend on. The first eight fields are v1's; Salt and FirstOwner were added in the core-final round (2026-11-12). Core fills them only on a token read (TokenURI, TokenCard, TokenTraits, …) of a Final collection; RenderWith, RenderWithInput and the registration sample leave them "" (so no fingerprint moves).

type LaunchGate

interface
1type LaunchGate interface {
2	GateLaunch(c Collection) error
3}
source

LaunchGate is the launch-time check with the launch mode: core.Launch calls GateLaunch right after CheckLaunch passed, for both modes; an error aborts the launch ("launch refused by engine: …").

type Manifest

struct
 1type Manifest struct {
 2	Name, Version, Description, License string
 3	Author                              address // proven by core.ClaimEngine
 4	ParamsSchema                        string  // JSON Schema subset; Studio builds its form from it
 5	// TraitTypes is the engine's default trait list. A collection uses
 6	// TraitTypes(params), stored by core at CreateCollection when it
 7	// differs; static engines return this list there.
 8	TraitTypes  []string
 9	Living      bool  // Render depends on LastMoveHeight/Moves/Height
10	MaxSVGBytes int64 // <= MaxSVGBytes; for a media engine the card's cap
11	// FeeBps is the author's fee on every primary and secondary sale of a
12	// collection that uses this engine, 0..MaxFeeBps. It is fixed at
13	// registration; core snapshots it per collection at Launch, caps it by
14	// the platform's engine-fee cap and waives it when the collection's
15	// creator is the author.
16	FeeBps int64
17	// Kind is KindSVG or KindMedia (required).
18	Kind string
19	// MaxMediaBytes caps Media.Data of a media engine: 1..MaxMediaBytes.
20	// 0 for an SVG engine.
21	MaxMediaBytes int64
22}
source

type Media

struct
1type Media struct {
2	Mime   string // MimePNG | MimeWebP | MimeJPEG | MimeSVG
3	Data   string // on-chain bytes, or ""
4	URI    string // "ipfs://<CIDv1>" when Data is ""
5	Sha256 string // lower-case hex of sha256(file); required with Data, optional with URI
6}
source

Media is a media engine's art for one token. Exactly one of Data and URI is set. Data is the raw file (not base64) as a Go string: strings are immutable, so core can check and encode it without copying and without the engine being able to change it afterwards.

Methods on Media

func IsZero

method on Media
1func (m Media) IsZero() bool
source

IsZero reports an empty Media (what an SVG engine returns).

type Trait

struct
1type Trait struct {
2	Type, Value string
3}
source

Dependencies

Source Files 3