Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article examines ERC-2569, a proposal for storing token-associated images on-chain in SVG format.
The explanation below translates, summarizes, and expands on the original proposal.
I also cover a range of other EIPs.
Overview
ERC-2569 proposes interfaces that allow smart contracts to store SVG images on Ethereum and retrieve them later. The intended scope includes the following types of tokens.
- Fungible tokens, such as ERC-20.
- Non-fungible tokens, such as ERC-721.
- Other token standards introduced in the future.
The proposed specification consists of two interfaces.
- An interface for storing SVG images on Ethereum.
- An interface for retrieving SVG images from Ethereum.
Potential applications include storing and displaying:
- Icons for fungible tokens.
- Images or icons associated with NFTs.
- Logos for DAO reputation tokens.
Motivation
ERC-721 is widely used to represent NFTs on Ethereum. Applications include digital gifts, medals, and collectibles, with CryptoKitties being a prominent early example.
Although the token contract and ownership records reside on Ethereum, associated image data is often stored on centralized servers. Applications retrieve token information from Ethereum and use it to locate an image hosted elsewhere.
This arrangement makes image availability dependent on the server. If the server becomes unavailable, or if its content is corrupted or modified, the image associated with a token may no longer be accessible as intended. That can undermine the durability and tamper resistance users expect from blockchain-based assets.
The proposal defines interfaces for storing image data directly on Ethereum, thereby reducing reliance on external hosting. This approach can support more self-contained, decentralized NFT architectures, although immutability still depends on how the contract permits image updates.
Specification
ERC-2569 defines interfaces for storing SVG images on Ethereum and retrieving the images associated with tokens. The intended scope includes ERC-721, ERC-1155, future token standards, and fungible tokens such as ERC-20.
Methods
The proposed methods for storing and retrieving images are as follows.
getTokenImageSvg(uint256 tokenId) external view returns (string memory)setTokenImageSvg(uint256 tokenId, string memory imageSvg) internal
The getter exposes the stored SVG data, while the internal setter provides a way for the contract to record it.
getTokenImageSvg
Retrieves an SVG image. It takes a token identifier and returns the SVG content associated with that identifier.
For token standards with IDs, such as ERC-721 and ERC-1155, the getter retrieves the SVG string stored for the corresponding token. For fungible tokens such as ERC-20, no individual token ID is needed, and the image can be retrieved from a string variable representing the token as a whole.
Arguments
tokenId- The token identifier.
- For ERC-721 and ERC-1155 tokens, the ID identifies the associated image.
- Fungible-token variants do not require an individual token ID.
setTokenImageSvg
Sets the SVG image. This is an internal function that receives a token identifier and SVG data as a string.
For ERC-721 and ERC-1155, the implementation stores SVG content associated with the relevant token ID. For fungible tokens, the SVG can instead be stored in a contract-level string.
Arguments
tokenId- The ID of the token associated with the image.
- An NFT can have an image associated with its individual ID.
imageSvg- The SVG content supplied as a string.
- The original proposal discusses including name and description information in the SVG. Implementers should ensure the resulting document follows valid SVG markup, including the appropriate metadata elements or attributes.
Image storage procedure
- Define image storage variables
Use a
stringvariable for a single SVG image or a collection such asstring[]for multiple images. - Define an image setter Implement a function that stores the supplied SVG string in the relevant variable.
Image retrieval procedure
- Tokens with identifiers
For ERC-721 or ERC-1155 tokens, pass the token ID to
getTokenImageSvgto retrieve the associated image. - Tokens without identifiers For ERC-20 and similar fungible tokens, retrieve the contract-level SVG string without an individual token ID.
This design enables token images to be managed directly on Ethereum without relying on centralized image hosting.
Rationale
Since the introduction of blockchains, applications have embedded textual data in transactions to create durable, tamper-evident records. Storing images in a similarly accessible on-chain form has historically been more difficult.
One reason is that image files can be considerably larger than textual data. Direct storage can incur substantial gas costs and, for sufficiently large files, exceed transaction or block execution limits.
SVG (Scalable Vector Graphics), developed by the W3C beginning in 1999, provides a useful alternative for images that can be represented compactly using vector markup.
Advantages of SVG for on-chain images
SVG offers several advantages compared with raster formats such as JPEG and PNG.
- Potentially compact file sizes Raster images can require substantial data to represent individual pixels. SVG represents shapes and other graphical elements as vectors, allowing them to scale without losing vector detail. Simple illustrations can often be represented in relatively compact files.
Compactness addresses one of the principal challenges of storing graphics on Ethereum. SVG is therefore a useful format for representing certain token images in durable on-chain storage. Complex SVG files may still be large and costly to store.
Why tokens need images
DApps commonly display images for NFTs such as ERC-721 tokens. Fungible-token icons are often supplied by external metadata services rather than by the token contract itself.
Providing images for ERC-20 and other tokens may be useful for application interfaces and brand recognition. A standard retrieval method could allow applications to access token icons or logos more consistently.
Limitations of centralized storage and SVG as an alternative
Images hosted on centralized servers may become unavailable or be modified without the token holder's knowledge. This is at odds with applications that seek to minimize reliance on centralized infrastructure.
Storing suitable SVG content directly on Ethereum reduces dependence on external image hosting. The approach can be used with existing standards, including ERC-721, ERC-1155, and ERC-20, and may be adapted to future token standards.
On-chain SVG provides an option for durable token image management, subject to storage costs, contract update permissions, and safe rendering of SVG content.
Reference implementation
// ----- IERC721GetImageSvg.sol -------------------------
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional retrieving SVG image extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
contract IERC721GetImageSvg is IERC721 {
function getTokenImageSvg(uint256 tokenId) external view returns (string memory);
}
// ----- ERC721GetImageSvg.sol -------------------------
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/token/ERC721/./ERC721.sol";
import "@openzeppelin/contracts/introspection/ERC165.sol";
import "./IERC721GetImageSvg.sol";
contract ERC721GetImageSvg is Context, ERC165, ERC721, IERC721GetImageSvg {
// Mapping for token Images
mapping(uint256 => string) private _tokenImageSvgs;
/*
* bytes4(keccak256('getTokenImageSvg(uint256)')) == 0x87d2f48c
*
* => 0x87d2f48c == 0x87d2f48c
*/
bytes4 private constant _INTERFACE_ID_ERC721_GET_TOKEN_IMAGE_SVG = 0x87d2f48c;
/**
* @dev Constructor function
*/
constructor () public {
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_INTERFACE_ID_ERC721_GET_TOKEN_IMAGE_SVG);
}
/**
* @dev Returns an SVG Image for a given token ID.
* Throws if the token ID does not exist. May return an empty string.
* @param tokenId uint256 ID of the token to query
*/
function getTokenImageSvg(uint256 tokenId) external view returns (string memory) {
require(_exists(tokenId), "ERC721GetImageSvg: SVG Image query for nonexistent token");
return _tokenImageSvgs[tokenId];
}
/**
* @dev Internal function to set the token SVG image for a given token.
* Reverts if the token ID does not exist.
* @param tokenId uint256 ID of the token to set its SVG image
* @param imagesvg string SVG to assign
*/
function setTokenImageSvg(uint256 tokenId, string memory imagesvg) internal {
require(_exists(tokenId), "ERC721GetImageSvg: SVG image set of nonexistent token");
_tokenImageSvgs[tokenId] = imagesvg;
}
}
// ----- ERC721ImageSvgMintable.sol -------------------------
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/token/ERC721/ERC721Metadata.sol";
import "@openzeppelin/contracts/access/roles/MinterRole.sol";
import "./ERC721GetImageSvg.sol";
/**
* @title ERC721ImageSvgMintable
* @dev ERC721 minting logic with imagesvg.
*/
contract ERC721ImageSvgMintable is ERC721, ERC721Metadata, ERC721GetImageSvg, MinterRole {
/**
* @dev Function to mint tokens.
* @param to The address that will receive the minted tokens.
* @param tokenId The token id to mint.
* @param tokenImageSvg The token SVG image of the minted token.
* @return A boolean that indicates if the operation was successful.
*/
function mintWithTokenImageSvg(address to, uint256 tokenId, string memory tokenImageSvg) public onlyMinter returns (bool) {
_mint(to, tokenId);
setTokenImageSvg(tokenId, tokenImageSvg);
return true;
}
}
We propose to add three sol files in the existing ERC-1155 implementation.
Here are the details for the proposed sol files.
// ----- IERC1155GetImageSvg.sol -------------------------
pragma solidity ^0.5.0;
import "./IERC1155.sol";
/**
* @title ERC-1155 Multi Token Standard, retrieving SVG image for a token
* @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1155.md
*/
contract IERC1155GetImageSvg is IERC1155 {
function getTokenImageSvg(uint256 tokenId) external view returns (string memory);
}
// ----- ERC1155GetImageSvg.sol -------------------------
pragma solidity ^0.5.0;
import "./ERC1155.sol";
import "./IERC1155GetImageSvg.sol";
contract ERC1155GetImageSvg is ERC165, ERC1155, IERC1155GetImageSvg {
// Mapping for token Images
mapping(uint256 => string) private _tokenImageSvgs;
/*
* bytes4(keccak256('getTokenImageSvg(uint256)')) == 0x87d2f48c
*
* => 0x87d2f48c == 0x87d2f48c
*/
bytes4 private constant _INTERFACE_ID_ERC1155_GET_TOKEN_IMAGE_SVG = 0x87d2f48c;
/**
* @dev Constructor function
*/
constructor () public {
// register the supported interfaces to conform to ERC1155 via ERC165
_registerInterface(_INTERFACE_ID_ERC1155_GET_TOKEN_IMAGE_SVG);
}
/**
* @dev Returns an SVG Image for a given token ID.
* Throws if the token ID does not exist. May return an empty string.
* @param tokenId uint256 ID of the token to query
*/
function getTokenImageSvg(uint256 tokenId) external view returns (string memory) {
require(_exists(tokenId), "ERC1155GetImageSvg: SVG Image query for nonexistent token");
return _tokenImageSvgs[tokenId];
}
/**
* @dev Internal function to set the token SVG image for a given token.
* Reverts if the token ID does not exist.
* @param tokenId uint256 ID of the token to set its SVG image
* @param imagesvg string SVG to assign
*/
function setTokenImageSvg(uint256 tokenId, string memory imagesvg) internal {
require(_exists(tokenId), "ERC1155GetImageSvg: SVG image set of nonexistent token");
_tokenImageSvgs[tokenId] = imagesvg;
}
}
// ----- ERC1155MixedFungibleWithSvgMintable.sol -------------------------
pragma solidity ^0.5.0;
import "./ERC1155MixedFungibleMintable.sol";
import "./ERC1155GetImageSvg.sol";
/**
@dev Mintable form of ERC1155 with SVG images
Shows how easy it is to mint new items with SVG images
*/
contract ERC1155MixedFungibleWithSvgMintable is ERC1155, ERC1155MixedFungibleMintable, ERC1155GetImageSvg {
/**
* @dev Function to mint non-fungible tokens.
* @param _to The address that will receive the minted tokens.
* @param _type The token type to mint.
* @param tokenImageSvg The token SVG image of the minted token.
*/
function mintNonFungibleWithImageSvg(uint256 _type, address[] calldata _to, string memory tokenImageSvg) external creatorOnly(_type) {
mintNonFungible(_type, _to);
setTokenImageSvg(_type, tokenImageSvg);
}
/**
* @dev Function to mint fungible tokens.
* @param _to The address that will receive the minted tokens.
* @param _id The token type to mint.
* @param _quantities The number of tokens for a type to mint.
* @param tokenImageSvg The token SVG image of the minted token.
*/
function mintFungibleWithImageSvg(uint256 _id, address[] calldata _to, uint256[] calldata _quantities, string memory tokenImageSvg) external creatorOnly(_id) {
mintFungible(_id, _to, _quantities, tokenImageSvg) {
setTokenImageSvg(_id, tokenImageSvg);
}
}
We propose to add three sol files in the existing ERC-20 implementation.
Here are the details for the proposed sol files.
// ----- IERC20GetImageSvg.sol -------------------------
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @title ERC-20 Fungible Token Standard, retrieving SVG image for a token
* @dev See https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol
*/
contract IERC20GetImageSvg is IERC20 {
function getTokenImageSvg() external view returns (string memory);
}
// ----- ERC20GetImageSvg.sol -------------------------
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./IERC20GetImageSvg.sol";
contract ERC20GetImageSvg is ERC20, IERC20GetImageSvg {
string private _tokenImageSvg;
//将图片实现写在构造器中
constructor(string calldata svgCode) public {
_tokenImageSvg = svgCode
}
/**
* @dev Returns an SVG Image.
*/
function getTokenImageSvg() external view returns (string memory) {
return _tokenImageSvg;
}
}Citation
Hua Zhang (@dgczhh), Yuefei Tan (@whtyfhas), Derek Zhou (@zhous), Ran Xing (@lemontreeran), "ERC-2569: Saving and Displaying Image Onchain for Universal Tokens [DRAFT]," Ethereum Improvement Proposals, no. 2569, March 2020. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-2569.
Conclusion
This article covered ERC-2569, a proposed interface for storing and retrieving token-associated SVG images directly on Ethereum.
If you have questions, feel free to reach out via Twitter DM.
I also publish on the following platforms.



