ERC-1178 Multi-class token standard

Stagnant · NFTs & multi-token · created 2018-06-22

A standard that allows multiple classes of fungible tokens, like preferred and common shares, to be issued together within a single contract, with ownership tracked, transferred, and exchanged.

Why it is needed

An ERC-20 contract can issue only one type of token, and ERC-721 only supports "classes" distinguished by an individual token_id per token, requiring tokens to be created one by one. So to handle multiple classes of fungible assets within a single contract, like a company's preferred, common, and restricted shares, the only option is to mimic ERC-721's token struct attributes. However, the original author's own testing found that even with the maximum gas sendable from MetaMask, only about 46 tokens could be created, making individual token creation impractical due to excessive gas costs. In this situation, a developer trying to handle multi-class assets has no choice but to use an inefficient data structure or deploy a separate contract for each class.

What to implement

In depth

ERC-20 compatible metadata functions

name, className, and symbol are all OPTIONAL and exist for readability in wallets and exchanges; other contracts or interfaces MUST NOT depend on these functions existing. name() returns the name of the entire collection of MCFTs managed by the contract (e.g. "My Company Tokens"), className(classId) returns the name of an individual class (e.g. "My Company Preferred Shares Token"), and symbol() returns a short symbol representing the whole (e.g. "MUL"). symbol SHOULD be 3 to 8 uppercase letters with no spaces or line breaks.

Supply lookup

totalSupply() returns the total count of all MCFTs tracked by this contract. individualSupply(_classId) returns only the total count of MCFTs belonging to a single specified class.

Ownership lookup and classesOwned

Unlike ERC-20's balanceOf, balanceOf(_owner, _classId) takes an additional class (classId) argument to look up holdings for a specific class only. classesOwned(_owner) returns an array of all classIds held by the owner; the original text notes that returning this array is supported via pragma experimental ABIEncoderV2.

State transition rules for approve

approve(_to, _classId, quantity) MUST throw if msg.sender's balance for that classId is less than quantity, if the classId is not registered with this contract, or if msg.sender==_to. Only one address can hold an approval for a given owner-classId pair at a time, so a new approve call overwrites the previous approval. Calling with _to as 0 revokes the approval. Setting, changing, reconfirming (calling approve again with the same address), or revoking an approval MUST all emit an Approval event, except when attempting to revoke an approval that does not already exist.

transfer allows only full transfers

transfer(_to, _classId, quantity) MUST succeed only when quantity exactly equals msg.sender's balance for that classId (quantity == balanceOf(msg.sender, _classId)), and MUST throw otherwise. In other words, partial transfers are not possible. A Transfer event is emitted on success. A "no-op transfer" to msg.sender itself is also allowed as a valid action that reconfirms ownership, and in this case too a Transfer event with the same from and to MUST be emitted.

Advanced exchange functions: approveForToken, exchange, transferFrom

approveForToken(classIdHeld, quantityHeld, classIdWanted, quantityWanted) is a function, equivalent to placing a buy order on a marketplace, that approves a third party (or the contract itself) to exchange your held tokens for another class of tokens at a specified ratio. exchange(to, classIdPosted, quantityPosted, classIdWanted, quantityWanted) is the function that settles that order; in the original sample implementation it is designed to succeed only when the counterparty has already approved the token transfer to the contract, but it also notes that an implementation could handle both approval and transfer in a single call. transferFrom(from, to, classId) is the function by which an approved third party performs the transfer on someone's behalf.

Events and minting/burning rules

The Transfer event MUST be emitted whenever ownership changes by any mechanism, including transfer and transferFrom. When minting new MCFTs, a Transfer event with _from set to 0 MUST be emitted for each token, and when burning, a Transfer event with _to set to 0 MUST be emitted. A Transfer event where _from and _to are the same is also valid for the no-op transfer case described in the transfer() documentation.

Compatibility limits with ERC-721, and the standard's status

This standard tries to follow ERC-721's semantics as closely as possible, but it is not fully compatible. Because of the fundamental difference between multi-class fungible tokens and non-fungible tokens, ERC-721's ownerOf, takeOwnership, and tokenOfOwnerByIndex cannot be implemented under this standard, and the function argument composition of balanceOf, approve, and transfer also differs. This proposal is currently Stagnant, with no further discussion ongoing, so the specification may change or may never be adopted.

Original ERC · ← ERCs