GuideTools2 min read
Chain data: let the work respond
Turn a supported contract value into a named variable before your artwork draws its first frame.
Select an underlined word to see what it means.
In this guide
// Prepared data snapshot
// KEEL.data contains:
// { supply: 8 }
// Your drawing reads it
rings = KEEL.data.supplyIn a real prepared layer, the values are frozen and include the source chain and block.
Give a number a creative role.
Imagine a character whose glow comes from its health, or a drawing whose rings come from a collection’s supply. Pick the contract read, name the value, and decide what it means in your work.
The example above uses local sample values. A real build reads the selected contract and records the chain and block alongside the result.
The value arrives before the drawing starts.
The SDK prepares a small data script that runs before the runtime and artwork. Your code can read a named value such as KEEL.data.supply. The sandbox can show which variables the prepared work contains.
Example: use a prepared value in your artwork
// The prepared data module runs before this artwork.
const supply = Number(KEEL.data.supply);
const rings = Math.min(24, Math.max(1, supply));
// Use rings in your drawing function.A snapshot captures one moment.
The prepared layer carries the chain and block it was read from. Reopening that build uses the prepared values. To follow later changes, design a refresh or a new revision explicitly.
Choose whether the piece should preserve a moment or keep changing. That choice is part of the artwork, and collectors should be able to understand it.
Use code or ask an agent.
The SDK and MCP expose the same preparation path. An agent can prepare the data fragment, add it to the project, and inspect the sandbox report. It should show you the selected source and values before the release review.
Technical reference: supported reads and build order
SDK: readOnchainData, buildOnchainDataFragment, assertOnchainDataRoundTrip. MCP: keel-onchain-data-prepare. The generated classic script runs in the data phase at weight -32768, before runtime and render. Supported return values are static bool, address, bytes32, and integer types; dynamic strings, bytes, and arrays are refused. Wide integers are preserved as decimal text. The prepared pack records chainId and blockNumber. It is read-only preparation, not a signed or published update.

