Injection convention

How a generative work's code receives its token context, onchain and off. The parity requirement of the collection system: a work's onchain generative renderer, the studio previewer, the mint surface, and the artist-site embed must inject the identical object, so a preview renders identically to the token.

The context object

Injected as a plain script before the artist's code. The historical v1 Scripty template emits dependency tags first; those libraries must not read tokenData:

js
window.tokenData = {
  hash: "0x…",        // 32-byte tokenSeed as 0x-prefixed hex (64 chars)
  tokenId: "123",      // decimal string
  collection: "0x…",    // checksum-agnostic lowercase hex address
  chainId: 1,
  version: 1,             // == the work's injection version
  context: "token"        // why this document is being rendered; see below
};

hash and tokenId match Art Blocks' tokenData shape, so existing AB-style sketches run unmodified. Everything else is additive. Code SHOULD read only documented fields and tolerate additions.

Execution context

context tells the work's code why the document was rendered:

  • "token": the canonical render of a real token (tokenURI, and any offchain parity render of a minted token). The determinism rules below apply in full; a missing or unknown context MUST be treated as "token".
  • "preview": a render from a caller-supplied seed with no token existing (previewURI onchain, test seeds in the studio, a mint page's pre-mint explore). Composition MUST be exactly what the same seed would produce as a token, but presentation MAY adapt (e.g. skip a long intro).
  • "capture": an offchain headless render for a static image (thumbnail, OG). Code MAY jump straight to the canonical still (skip animation), and MUST settle on it deterministically.

Previews are also an onchain capability: renderers that can render faithfully from (tokenId, seed) alone implement the OPTIONAL IPreviewRenderer extension (a bespoke IRenderer can implement it when its art is a pure function of the seed). A renderer whose output depends on state a seed cannot supply (sibling tokens, companion contracts, mint-time data recorded by a mint hook) does not implement it; detection is a try/catch eth_call. A preview document MUST inject context: "preview", and preview metadata carries no provenance attributes.

Determinism rules for pure works

  1. All randomness derives from tokenData.hash through a seeded PRNG. Never Math.random() unseeded, never crypto.getRandomValues.
  2. No time: no Date, no performance.now() affecting output. Animation MAY use frame counters; the canonical still is frame-defined.
  3. No network: no fetch, no XHR, no websockets, no external assets. Everything renders from the injected context plus bundled dependencies.
  4. Resolution independence: identical composition at any canvas size or pixel density.
  5. Interaction MAY exist for exploration, but the parameter-free render is the canonical artwork.

Chain-live and external-live works

A work that reads changing state must declare which chain state, provider, or external data its output depends on. A faithful capture needs those inputs at the same block or time as the reference render; the seed alone is insufficient. Fixing renderer code does not freeze those inputs. Current v2 stores every seed in the token itself; works that need other data define those dependencies in their renderer or companion contracts.

Onchain assembly

The former v1 ScriptyRenderer template used the order below. Its source and reference have been retired, so this is an assembly convention for artists' own renderers, not a currently bundled renderer. V2 collection reads must use the current token ABI rather than the old ISurfaceView struct return.

Body tag order in the assembled HTML:

  1. dependencies (the work's dependency files, each per its code kind). Dependencies are libraries: they MUST NOT read tokenData.
  2. the context injection tag (inline tagContent, exactly the object above)
  3. the artist's code (the work's code files, each per its code kind)
  4. gunzip helper (plain script, from onchain storage), LAST, present only when any tag is gzipped. The helper decompresses at its own parse time by scanning the gzip tags that PRECEDE it and replacing each with an executing script tag in document order; placed earlier it would find nothing. Gzipped tags do not execute at parse time, so execution order remains: deps, then (already-parsed) context, then code, with libraries like p5 auto-starting off the late load.

A generative renderer typically emits the document with ScriptyBuilderV2 (getEncodedHTMLString) and returns it as data:text/html;base64,… in the metadata animation_url. See Write a renderer for how a collection's renderer slot points at a generative renderer and how such a renderer reads its collection and defines its own permanence rules.

Offchain parity implementations

The studio previewer, mint surface, and artist-page embed build the same document (or an equivalent iframe srcdoc) and MUST:

  • inject byte-identical window.tokenData (field order irrelevant, values identical; hash lowercase hex),
  • load the same dependency bytes (from chain, or verified against the onchain hashes),
  • never inject additional globals the onchain render lacks, except a provider for chain-live works.

Test seeds in the studio are ordinary tokenData objects with synthetic hash values and context: "preview"; nothing else may differ. Offchain renders of real minted tokens inject context: "token"; headless capture tooling injects context: "capture".

Versioning

A work's injection version pins which revision of this document it was authored against; the renderer echoes it as tokenData.version. Additive changes bump the minor conventions here without a version bump; breaking changes (renamed fields, changed ordering) require a new version and a new renderer, never a mutation of this one.

See Write a renderer for implementing or adopting a renderer against this convention.

Seed derivation (the protocol standard)

Renderers and offchain tools read tokenSeed(tokenId) from the collection. The injection object is unchanged between v1 and v2; its version identifies the work's injection convention, not the Surface contract generation.

V1 derives and stores:

solidity
seed = keccak256(abi.encode(block.prevrandao, collectionAddress, tokenId, mintIndex))

mintIndex distinguishes pooled re-mints of the same id. A burned pooled id's seed can be replaced when that id is minted as a new instance.

V2 is sequential only. Its default stored seed drops the redundant index:

solidity
seed = keccak256(abi.encode(block.prevrandao, collectionAddress, tokenId))

V2 has no supplied-seed mint entrypoint or external seed-source option. Every mint writes the formula above to the token's seed storage. See Seed and provenance and Surface v2.

The recipient is absent from both default formulas. Same-transaction callers can still inspect a minted seed and revert an unwanted result, so default entropy is not suitable for lotteries or financial randomness guarantees. A fixed renderer pointer does not freeze external artwork inputs. Archives should record the seed and any other changing inputs used by the artwork.