ERC-2569 On-chain storage of SVG images (Saving and Displaying Image Onchain for Universal Tokens)

Stagnant · Names & metadata · created 2020-03-28

An interface standard that lets a smart contract store a token's icon on-chain in SVG form and look up that image by token ID.

Why it is needed

The code of NFTs like ERC-721 remains permanently on Ethereum, but the image file linked to the token is mostly stored on a centralized server. An app reads the token information from the blockchain and then uses that information to find and display the image from the central server. In this case, if the server goes down or the data is deleted or tampered with, the image can be corrupted or lost, creating a problem where the token's code is permanent but the image that serves as the token's face is not. This standard aims to make the image itself as permanent and tamper-resistant as the token's code by storing the image on-chain using the small-sized SVG (vector image) format.

What to implement

In depth

Two core functions

This standard defines two functions that a compliant contract must have. getTokenImageSvg(uint256) view returns (string memory) is a lookup function that returns the stored SVG image string, and setTokenImageSvg(uint256 tokenId, string memory imagesvg) internal is an internal function that links and stores an SVG image string to a token. Calling these two functions ultimately gives the user access to the SVG image string.

Tokens with a tokenId and tokens without one

When there is an 'ID' member distinguishing token type or individual tokens, as in ERC-721 or ERC-1155, the SVG image string is stored paired with that ID number, and lookups are also done using the same ID. On the other hand, for tokens with no concept of ID, like ERC-20, the image is stored as is in a single string member variable of the contract, without an ID.

Attributes to include in the SVG string

The specification body states that the SVG image stored in the imageSvg string must include at least the two attributes 'name' and 'desc' (description). However, the reference implementation description mentions three attributes, 'name', 'description', and 'issuer', which differs somewhat from the body.

The procedure for storing an image

The procedure begins by defining a string variable or string array to hold the SVG image (or array of images), and creating a function that puts the image file contents into that variable. For a token with an ID, the image stored paired with that ID is looked up by passing the ID to the get interface, while for a token without an ID, it is looked up by calling the get interface without an ID.

Why SVG

Bitmap images have large file sizes, so storing them on-chain easily exceeds a block's gas limit. SVG, created by the W3C in 1999, is vector-based, so its quality is preserved even when resized, and its file size is small. This characteristic is explained as resolving the gas problem of on-chain storage.

Scope of application and backward compatibility

This approach is explained as applicable not only to ERC-20, ERC-721, and ERC-1155 but also to future token standards, and since it is an addition rather than a change to existing standards, it is stated that there are no backward compatibility issues.

Reference implementation

It proposes adding three .sol files for each of ERC-721, ERC-1155, and ERC-20. These consist of an interface file, an implementation file that stores and looks up the image via a mapping, and a file that stores the image together at mint time. The ERC-721 and ERC-1155 implementations register interface ID 0x87d2f48c via ERC165 to signal support for getTokenImageSvg(uint256).

Proposal status

This ERC is in Stagnant status, a proposal that is no longer actively discussed and has stalled. Note that the specification is unlikely to change or be adopted.

Original ERC · ← ERCs