Jack Allan Kasbeer.

← All posts

Painting with the Weather: Engineering Kim Rose's Ocean Series

· updated · solidity, ethereum, python, nft, generative-art

Kim Rose paints with wet ink, and anyone who has watched her work knows the best part happens before the paint dries: the ink drifts, blooms and folds into itself. For her first NFT she wanted to keep that motion, and she wanted it tied to a real place. That place isn’t a theme Kim picked: the collector chose it. Sydney follows the weather in Watsons Bay on Sydney Harbour. On a clear afternoon the piece is bright and still; on a stormy night it turns dark and restless.

That’s not how NFT art usually works. Almost every art NFT is a single, frozen file: the token points at a JSON document on IPFS, that JSON points at an image, and nothing ever changes. “Dynamic NFTs” exist, but mostly in games, sports collectibles and oracle tutorials. Live data has started reaching fine art (Refik Anadol’s Living Architecture: Casa Batlló, which responds to Barcelona’s weather, sold at Christie’s in May), but so far as museum-scale productions. We wanted the same idea for an independent artist’s 1-of-1, running on a small Python service and two Solidity files instead of an oracle network.

I was the engineer: I wrote the smart contract and the service that decides what the piece looks like at any moment. The part I’m proudest of is what it costs Kim to keep it alive: one small server and an IPFS pinning account, both of which can carry every piece she makes after this one. This post covers how it works and why we built it this way.

Sydney, Calm Day state. Kim filmed wet ink in motion and layered it into a seamless loop.

Four states

Two questions decide what Sydney looks like: is the sun up in Watsons Bay, and is it storming? That gives four states, each a separate loop Kim produced from her ink footage. The loops are fixed, content-addressed videos on IPFS, so the art itself never changes. Only the choice of which one to show does.

Calm Day
Stormy Day
Calm Night
Stormy Night

Each state has its own metadata document. They share a title and description and differ in name and animation_url:

{
  "name": "Stormy Night",
  "description": "… on a sunny day, “Sydney” appears bright and scenic. On a stormy night, however, “Sydney” appears dark and brooding. …",
  "image": "ipfs://QmT2gL4T6V7Ga1gndy9T22NKWFaGi1GsYpZVEeVQ61M7Wp",
  "animation_url": "https://ipfs.io/ipfs/QmXMd3KY9Ub4MVrgZh5GaPd3Ao9wbnzqVRzrFxVdsa31wa"
}

Architecture

The key move is small: the contract’s tokenURI doesn’t point at a file. It points at an API.

Flow: a wallet, marketplace or display calls tokenURI on the Sydney contract, which returns an API URL; the API checks the weather if its cache is stale and returns the current state's metadata; the viewer then plays that state's video from IPFS.
Every viewer resolves the token the normal ERC-721 way, and gets back whatever state matches the weather right now.

Wallets and marketplaces don’t need to know anything special. They follow the standard ERC-721 flow, call tokenURI, fetch the JSON at that URL and render its animation_url. The only difference is that the JSON they get back depends on the weather. And because nothing is written on-chain when the weather changes, updates cost no gas: the piece can change as often as it needs to, for free.

The smart contract

Sydney is a 1-of-1, so the contract is deliberately small. It’s an ERC721A token on Ethereum mainnet, built on a shared base contract (Satoshigoat) that I wrote to be reused for future pieces in the series.

The whole dynamic mechanism on-chain is this override:

constructor()
    Satoshigoat("Sydney", "", "http://<metadata-host>/watsonsbay?tid=")
{
    // contract-level metadata (name, royalties) lives on IPFS
    _contractURI = "ipfs://QmZNn55yUE1F3eRjvH53zTX6AiJEnRhCNdSBLgh3Hzaxez";
    // ... owner, payout address and price
}

//@dev One token, one live state: every lookup resolves to "0"
function tokenURI(uint256 tid) public view virtual override
    returns (string memory)
{
    if (!_exists(tid))
        revert URIQueryForNonexistentToken();
    return string(abi.encodePacked(_baseURI(), "0"));
}

The base contract handles the sale and the guardrails:

contract Satoshigoat is ERC721A, SquadOwnable, ReentrancyGuard {
    uint256 constant public royaltyFeeBps = 1000; // 10%

    modifier purchaseArgsOK(address to, uint256 amount) {
        if (amount < purchasePrice)
            revert DataError("insufficient funds");
        if (_isContract(to))
            revert DataError("silly rabbit :P");
        _;
    }

    //@dev If the metadata service moves, the token can follow it
    function setBaseTokenURI(string calldata newBaseURI)
        external isSquad notEqual(_baseTokenURI, newBaseURI)
    {
        _baseTokenURI = newBaseURI;
    }
    // ...
}

A few choices worth calling out:

  • ERC721A keeps minting cheap and leaves room to reuse the base for small editions.
  • SquadOwnable extends OpenZeppelin’s Ownable with a list of admin wallets (Kim and me), so admin work doesn’t depend on a single key.
  • setBaseTokenURI is the escape hatch. A token that depends on a server needs a way to follow that server if it moves, without redeploying.
  • Mint and purchase refuse contract recipients, and everything that moves value runs behind a reentrancy guard.
  • Backup functions (burn, plus a guarded safe_kill that only works if the owner holds every token) exist for recovering from a bad deploy, not for normal operation.

The weather service

The metadata service is a small Flask-RESTful app with one endpoint per piece. On each request it decides whether its cached answer is still good, and if not, asks Visual Crossing for current conditions in Watsons Bay.

Decision flow: if the weather was checked in the last four hours, return the cached metadata; otherwise fetch current conditions, decide day or night from sunrise and sunset, decide calm or stormy, pick one of four states, update the cache and return it.
The state machine behind GET /watsonsbay?tid=0.

The core of it, condensed from the production code:

class WatsonsBay(Resource):
    lastUpdateTime = 0
    currentMetadata = {}

    def get(self):
        if request.args.get("tid") != "0":
            return {"message": "non-existent token id"}, 404

        now = time.time()
        stale = now - self.lastUpdateTime >= 4 * 60 * 60
        if stale or self.lastUpdateTime == 0:
            # Visual Crossing timeline API
            weather = fetch_conditions("Watsons Bay, Sydney")
            today   = weather["days"][0]
            current = weather["currentConditions"]

            # Day vs. night: compare epoch seconds,
            # so no time-zone math is needed
            daytime = (today["sunriseEpoch"]
                       <= current["datetimeEpoch"]
                       <= today["sunsetEpoch"])

            # Calm vs. storm
            storming = (current["conditions"] == "Rain, Partially cloudy"
                        and current["icon"] == "rain")

            state = {
                (True,  False): calm_day,   (True,  True): storm_day,
                (False, False): calm_night, (False, True): storm_night,
            }[(daytime, storming)]

            self.currentMetadata = state
            self.lastUpdateTime = now

        return self.currentMetadata, 200

Three details that mattered:

  1. Epochs, not clock times. Visual Crossing returns sunrise, sunset and the current observation as Unix epochs. Comparing those directly means the server’s own time zone never matters, even though the art lives on the other side of the world.
  2. A four-hour cache. Weather doesn’t change minute to minute, and marketplaces and displays can hit the endpoint often. Caching caps the weather API at six calls a day per piece no matter how much traffic the token gets, which keeps it inside Visual Crossing’s free daily allowance, and keeps responses fast.
  3. A storm is a judgment call. I chose the storm rule by studying real Visual Crossing responses for Watsons Bay. It’s the part of the system I expect to keep refining.

Getting it on the wall

A piece like this belongs on a wall, not just in a wallet. But marketplaces cache metadata and re-fetch it on their own schedule, so I couldn’t rely on them to show the current state. The collector’s display gets its own route instead. /view resolves the token’s current metadata and serves a full-screen loop of the right video, and the page reloads itself every hour:

Sequence: every hour the gallery display requests /view, which calls the metadata API, receives the current metadata, and returns a page with a looping video; the display then streams that video from IPFS.
The display path skips marketplace caching entirely.
<html>
  <meta http-equiv="refresh" content="3600"/>
  <body>
    <video src="{{ animation_url }}" controls autoplay muted loop playsinline preload="metadata"></video>
  </body>
</html>

It’s about as simple as a web page can be, and that’s the point. The display only has to load a URL; everything that matters happens on the server.

What it costs to run

This was the constraint I designed around from the start. A living artwork that bills its owner every time the weather changes is a liability for an independent artist, so Sydney had to be close to free to keep running, indefinitely, without me.

Here’s the full list of moving parts and what each one costs Kim:

Part What it does Ongoing cost
Smart contract Ownership, sale, royalties; points tokenURI at the API One-time deploy gas. Weather changes cost no gas.
A small VPS Runs the Flask metadata service and the display page One low-tier server, shared by every piece
Pinata (IPFS) Pins the four loops and their metadata One account, shared by every piece
Visual Crossing Current conditions, sunrise and sunset Free: at most six calls a day per piece

That’s the whole bill: one VPS and one Pinata account. Two properties make it hold up:

  • It doesn’t grow with traffic. Each request returns a few hundred bytes of JSON, and the four-hour cache means a thousand viewers trigger the same six weather calls a day as one viewer. The heavy part, the video, streams from IPFS, not from Kim’s server.
  • It doesn’t grow with the collection. A new piece is a new endpoint on the same server and a few more files in the same Pinata account. The marginal cost of the next artwork is close to zero.

The usual alternatives cost far more. Pushing weather on-chain through an oracle means a paid transaction for every update, several times a day, forever. Giving each artwork its own hosting or a paid data plan multiplies the bill with every sale. Keeping the dynamic part to a thin, cached API in front of static IPFS files is what makes a live piece affordable for one artist.

Trade-offs

Being honest about what this design gives up:

  • The live state depends on a server. If the service goes down, wallets can’t fetch the current state. The art itself is safe on IPFS, and setBaseTokenURI lets the token follow the service if it moves, but this is a trust trade-off, and it’s the deliberate price of keeping the piece nearly free to run. A Chainlink-style oracle would put the state on-chain, at the cost of gas for every update.
  • The cache lives in process memory. It’s fine for one worker, but a restart (or a second worker) means a fresh weather call. A small shared store would fix that.
  • The base URI should be HTTPS on a proper domain. That’s first on my list of follow-ups.

None of these get in the way of the experience. The piece changes with the weather, and the collector sees it happen.

Update, December 2023: Zürich

In November 2023 the series grew. A second collector chose Zürich, and Kim made a new set of four loops for it. The engineering held up: Zurich.sol reuses the same Satoshigoat base contract, and the metadata service gained a /zurich endpoint that runs the same state machine against Zürich’s weather. The only contract change is that Zürich is a 1-of-2, so its tokenURI appends the real token ID instead of hard-coding 0.

Zürich, Calm Day
Zürich: Calm Day
Zürich, Stormy Day
Zürich: Stormy Day
Zürich, Calm Night
Zürich: Calm Night
Zürich, Stormy Night
Zürich: Stormy Night

Adding a city took a new set of loops, four metadata files, one endpoint and one deploy, and it added nothing to Kim’s running costs: Zürich lives on the same VPS and in the same Pinata account as Sydney. That was the goal of the original design: every new collector’s place is a configuration change, not a rewrite. Kim now presents the series as The Place You Feel Most Alive.

Contracts

Artwork © Kim Rose. See more at kimroseart.com.