Jack Allan Kasbeer.

← All posts

Pacman Gobbles, We Go Up

· nft, dynamic metadata, flask, api, transient labs

ETH up: running Pacman eats ETH.
ETH down: Pacman falls into a blissful bed of clouds.

Bidding opens today at noon ET on CoinDesk’s Most Influential 2023 NFTs. One of the ten honorees is Tieshun Roquerre, better known as Pacman, co-founder of Blur. LOGIK made his portrait, and I engineered it. It’s a 1/1 called PWNING N00BS, and it has two moods.

What does it do?

It shows a different piece depending on whether ether is up or down over the last 24 hours. If ETH is green, Pacman is running and eating ETH. If it’s red, he falls asleep on a cloud. One token, two videos, and the market picks which one you see.

Why tie a portrait to the price?

Because of who it’s a portrait of. Blur launched in October 2022 as a marketplace built for pro traders: fast, dense, with token rewards for activity. By February it had passed OpenSea in monthly volume, and that made Pacman a hero to traders and a villain to plenty of artists, who felt trading had pushed out everything else. LOGIK’s take in the token’s description: “Keep doing your thing, Pacman!” A portrait of the person who turned NFTs into a trading screen should probably react to the chart.

How does the token know the price?

It doesn’t. The contract stores one URL, and the server behind it does the rest:

Sequence: a marketplace calls tokenURI on the contract and gets a URL; it requests that URL from the Flask metadata server; the server asks CoinMarketCap for ETH's 24-hour percent change and returns green.json if it's zero or above, red.json if below; the marketplace then loads the video from IPFS.
The same pattern as the Ocean Series, with a different data source.

If that looks familiar, it should. It’s the architecture from Kim Rose’s Ocean Series, where tokenURI points at an API instead of a file, with the weather service swapped for a price feed. The whole route, condensed:

@app.route('/pacman', methods=['GET'])
def getPacman():
    green = pd.read_json('meta/pacman/green.json', orient='index').to_dict()
    red = pd.read_json('meta/pacman/red.json', orient='index').to_dict()

    quote = json.loads(urllib.request.urlopen(CMC_QUOTE_URL).read())
    change = quote['data']['1027']['quote']['USD']['percent_change_24h']  # 1027 = ETH

    return (red if change < 0 else green)[0], 200

Both JSON files point their animation_url at the same IPFS folder (up.mp4 and down.mp4). The two states don’t even share a shape: up is a 4:5 portrait and down is a 16:9 landscape, so the piece changes its frame along with its mood.

Why not do it fully on-chain?

It could be done. Chainlink’s ETH/USD feed is readable from any contract, and a tokenURI could compare the latest round to one from roughly 24 hours earlier. But finding that earlier round means walking back through the feed’s history, the videos still live on IPFS either way, and the server version was a pattern I’d already proven on a live piece. With about a week between the first commit and the auction, I chose the boring, proven option.

So where’s the contract you wrote?

In my repo. I wrote Pacman.sol: an ERC721A contract with a supply of one, a team-only mint and a tokenURI that ignores the token ID and always returns the server URL:

function tokenURI(uint256 tid) public view virtual override returns (string memory) {
    if (!_exists(tid)) revert URIQueryForNonexistentToken();
    return string(abi.encodePacked(_baseURI(), "0"));  // http://…/pacman?tid=0
}

The Most Influential auction, though, runs on Transient Labs. So on December 1 the piece was minted through a Transient Labs creator contract instead: their ERC721TL implementation behind a proxy, deployed from LOGIK’s wallet with LOGIK as the creator. Its token #1 holds the same URL my contract would have returned.

Nothing about the piece had to change, and I think that’s the most useful lesson here. All of the dynamic behavior lives in the URI. Any contract that lets the creator set a token’s URI to an HTTP endpoint can carry this piece, which made switching platforms a deployment detail instead of a rewrite.

What are the trade-offs?

  • Marketplaces cache metadata. OpenSea and most others store a token’s JSON and only fetch it again when someone hits refresh metadata. The mood is always correct at the source, but a marketplace page can be a day behind. Wallets and viewers that call tokenURI themselves see the current state.
  • The server is a single point of failure. If it goes down, the token has no metadata at all. Here, the URL is a bare IP over plain HTTP. A domain with HTTPS would be easier to move and harder to break, and it’s the first thing I’d change.
  • Zero is green. change < 0 is red and everything else is green, so a perfectly flat day counts as a win for Pacman. Fitting, honestly: even on a flat day, the traders are still eating.

Contract

Artwork © LOGIK.