EIPs Explained

ERC-2569 · Stagnant · ERC · 2020-03-28

ERC-2569: Saving and Displaying Image Onchain for Universal Tokens

Proposed a getter and setter for storing a token's SVG image directly in contract storage, so token artwork and icons live on-chain instead of on a server that can disappear.

What problem does it solve?

Most ERC-721 collections keep only a pointer on-chain. The image itself sits on a web server, so if that server changes or goes offline, the token's picture can be altered or lost, even though the token lives forever. Fungible ERC-20 tokens often have no standard place for an icon at all.

EIP-2569 proposes storing the image in the contract as SVG text. SVG is a vector format and usually compact, which the authors argue makes on-chain storage affordable enough to be practical for icons and simple artwork.

How it works

The proposal defines two functions:

  • getTokenImageSvg(uint256 tokenId) external view returns (string) returns the SVG markup for a token.
  • setTokenImageSvg(uint256 tokenId, string imagesvg) internal stores it. Being internal, it is called from the contract's own logic, typically at mint time.

How the ID is used depends on the token type:

  • ERC-721 / ERC-1155: one SVG per token ID (or per token type for 1155).
  • ERC-20 and others without IDs: a single SVG for the whole contract.

The SVG should carry descriptive attributes; the spec asks for at least name and desc, and the reference section mentions name, description and issuer.

The reference implementation extends OpenZeppelin's ERC-721 with a mapping(uint256 => string) of images, a mintWithTokenImageSvg helper, and an ERC-165 interface registration for the getter. A similar extension is sketched for ERC-1155.

Sample code

A modern-Solidity version of the idea:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract SvgNFT is ERC721 {
    mapping(uint256 => string) private _svg;
    address public immutable minter;

    constructor() ERC721("SvgNFT", "SVG") { minter = msg.sender; }

    function getTokenImageSvg(uint256 tokenId) external view returns (string memory) {
        _requireOwned(tokenId);           // reverts for nonexistent tokens
        return _svg[tokenId];
    }

    function mintWithSvg(address to, uint256 tokenId, string calldata svg) external {
        require(msg.sender == minter, "not minter");
        _mint(to, tokenId);
        _setTokenImageSvg(tokenId, svg);
    }

    function _setTokenImageSvg(uint256 tokenId, string calldata svg) internal {
        _svg[tokenId] = svg;
    }
}

Example SVG payload:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
  <title>name: Coin</title><desc>A simple coin icon</desc>
  <circle cx="16" cy="16" r="14" fill="gold"/>
</svg>

Things to know

  • Status: Stagnant. It never became a widely used interface. Wallets and marketplaces read images from metadata (e.g. tokenURI for ERC-721), not from getTokenImageSvg, so a custom getter alone will not make your image show up.
  • On-chain artwork is commonly done today by returning a data: URI from tokenURI that embeds JSON metadata and an SVG. That keeps the "nothing off-chain" benefit while staying compatible with existing tools.
  • Storage is expensive: every 32 bytes of SVG costs a new storage slot. Keep images small and minified.
  • SVG can contain scripts and external references. Apps that render on-chain SVG should sanitize it or display it as an image, never inline it as trusted HTML.

#nft #token #svg #metadata #onchain

Details

Authors
Hua Zhang (@dgczhh), Yuefei Tan (@whtyfhas), Derek Zhou (@zhous), Ran Xing (@lemontreeran)
Status
Stagnant
Type
Standards Track / ERC
Created
2020-03-28

Machine-readable: Markdown · JSON