ERC-4883 Composable SVG NFTs (Composable SVG NFT)

Draft · NFTs & multi-token · created 2022-03-08

A standard that lets NFTs whose artwork is stored as SVG strings splice their artwork together with each other to form a single new composed image. It defines one common function that returns another NFT's artwork as a string.

Why it is needed

An on-chain SVG NFT does not keep its image file on an external server; instead it builds a vector image (SVG) as a string that does not degrade when zoomed in, and returns it inside a data URI from the tokenUri function. However, to combine multiple NFTs' artwork, such as placing glasses or a hat NFT on a profile picture NFT, or putting a fish NFT into a fish tank NFT, each NFT needs a shared convention for which function exposes the body of its own artwork. Without such a common convention, each project ends up exposing its artwork in its own different way, making it hard for other contracts to fetch and compose that artwork. This standard defines one function that takes a token ID and returns the SVG body as a string, letting NFTs that know nothing about each other splice their artwork together and compose it.

What to implement

In depth

The renderTokenById specification

The interface IERC4883 defines only one function. renderTokenById(uint256 id) must return the SVG body for the given token id, and the return value must be either an empty string or valid SVG element(s). It is an external view function, so it only reads state and does not change it. This standard requires ERC-721.

String concatenation and drawing order

SVG elements can be composed into a single SVG simply by concatenating them as strings. SVG is drawn using the 'painters model.' According to section 3.3, Rendering Order, of the SVG 1.1 specification, within a document fragment, elements that appear earlier are painted first, and elements that appear later are painted over them. In other words, this is not a concept like z-index; the order of concatenation is the drawing order. This standard does not enforce an order for composition, so an imported SVG NFT can be used as either a foreground or a background as needed.

Why concatenation was chosen over linking

SVG has a link tag, so complex SVGs could also be composed by linking. However, doing so would require creating a new URI format and getting the ecosystem to adopt it. Since string concatenation of SVGs is already supported, the simpler concatenation approach was chosen.

Sizing is each NFT's own responsibility

This standard places no requirements on the size of the returned SVG. If scaling based on size is needed, the SVG NFT itself must handle it.

Origin of the function name and compatibility

The render function was named renderTokenById because Loogies was the first to use this name, which means existing NFTs already deployed can also be compatible with this standard. The original text states there are no backwards compatibility issues.

Proposal status

The status of this document is Draft. Since it is an unfinalized draft, the content may change.

Things to watch out for

Original ERC · ← ERCs