-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ERC: Multi Token Standard #1155
Comments
Suggestion: Add in some detail of how to encode extra information into the _itemId to facilitate the mixing of different item/token standards. An example strategy to mix Fungible and Non-Fungible items together in the same contract for example may be to pass the base item ID in the top 128 bits of the uint256 _itemID parameter and then use the bottom 128 bits for any extra data you wish to pass to the contract. In the ERC-721 case individual NFTs are interacted with using an index based accessor into the contract/item data set. Therefore to access a particular item set within a mixed data contract and particular NFT within that set, _itemID could be passed as "<uint128: base item id><uint128: index of NFT>". Inside the contract code the two pieces of data needed to access the individual NFT can be extracted with uint128(~0) and the same mask shifted by 128. |
Added the split bits strategy to the description, thanks :) |
Transfer made using this standard, 2 FTs (10k + 500) and 100 NFTs (100): https://ropsten.etherscan.io/tx/0xfc924192fb068a6326bc28a2f5762be3a4b1fb6a1ef801bf6bf02c06af929d53 FT "ENJ" ID: 0x54e8b965cee12ac713ee58508b0d07300000000000000000000000000000000 10000, 500 and 100*1 sent in one transaction costing 5480196 gas (~$2.42 at time of tx). Note, this was done in an advanced solution with a lot more features than a basic impl. Basic/ref impl and gas as compared to current standards in basic form will be added soon. |
Hyperbridge is interested in potentially supporting this standard in our upcoming marketplace. We'd like to see where other organizations stand on this as it's an obvious problem, and if the proposed solution works for you. @coinfork I don't see source code, so I'm going to take to take it that it's currently proprietary. Is there any examples in the wild as of yet? |
Hey @ericmuyser thanks for your interest! We currently have a deployed contract on Ropsten (please see AC0DEM0NK3Y's post above) that is specifically tailored to our gaming use-case. We'll consider adding a reference implementation to the standard. |
I hope you didn't announce this like "Biggest innovation in the manking". 5480196 gas is unacceptably high. |
"I hope you didn't announce this like "Biggest innovation in the manking". 5480196 gas is unacceptably high." I think you need to look at the gas cost relative to the alternatives and how this differs from them. If you average this down (even without the fungible transfers that went with it) the above transfer cost ~55K per NFT sent, which compared to many other ERC721 implementations for eg. (seeing numbers 250K+ each) this offers significant savings. A simple ETH transfer costs 21K and ERC20 tokens look to cost anywhere from 35k to 130k each tx after some quick explorer checks in the top 100. So I would say the above cost is quite reasonable. On top of that there is also the reduction of number of contracts necessary to be deployed to the network, the transaction numbers being reduced (in this case 102 : 1) and also the possible features this would bring that wouldn't be possible with separate contracts and incompatible NFT & FT standards. |
I don't have strong opinions yet, but did y'all explore the option of composing ERC721 and 20/721 to get similar functionality? As in, creating a Anyway, it might be a little roundabout, but it does avoid the creation of a new standard by extending and composing existing ones, which is neat. |
Hi @shrugs while not getting too far into the implementation details of a system that uses this standard, in the above example where two different fungible types and one non-fungible set were operated on what a user/creator could do is call a "deployERCAdapter" function on the particular type if they so wish which will deploy an adapter contract that is either fully ERC721 or ERC20 compatible depending on the base type. This means the individual set is now backwards compatible with those standards and can therefore be used in any current system that supports them. Extending ERC721 rather than making a new standard that can mix different fungibility (and then supporting ERC721 with backwards compatibility) wouldn't have quite worked as ERC721 mandatory standard has certain functions that only make it suitable for a single data set in a single contract such as "balanceOf(address _owner)" and "isApprovedForAll(address _owner, address _operator)" for example. |
@AC0DEM0NK3Y the ERC adaptor is interesting, yeah. The fungible/non-fungible tokens would not be tracked in a single 721; their contract addresses would be.
so each individual contract still fulfills 721 and 20 to the best of their ability, and you add additional features like multi-send and factory methods to the |
That is a way to track perhaps, but is much less user/network friendly. If I want to send you an NFT A and and NFT B and do that through your tracking contract I'd have to call approve on contract A and B separately to give the tracking contract the allowance, then call the tracking contract to do the transfer. By allowing things to be mixed together and stored in a single contract I can transfer A and B to you in a single tx. A and B contract also have to be deployed. It's more data on the chain than is needed and that is not sustainable and/or limiting imho. |
I mentioned that above as well, perhaps I wasn't clear enough; you can implement multi-send functionality by making the I agree that composability does come with gas costs, and these should be measured. You can also separate logic and data using proxy patterns and cut down on duplicate logic deployments. (and before someone references the parity wallet, this is very much the same approach that 1155 uses by consolidating the logic and data into a single contract; it's still a single point of failure if there is a show-stopping bug). |
It sounds like it could work, but it doesn't fix the wastage/management issue. Deploying a contract for every NFT is not future proof imho. Your pattern seems like it would work with 1155 though. The register function that you are proposing could be something someone implements and then this returns an ID to match the contract address when calling the function. The call to transfer A and B in that case would might be to call: uint aID = 1155.register(ContractOfA); This now needs an extension to ERC721 to append "makeSuperUser" function. |
superuser would need to be added, yes. you could also get away with operator functionality that already exists; simply default to setting the approved operator of every token to the The data/logic separation via proxy is a well-known pattern and does indeed work. The only unknown is the gas implications, which could be measured. Having your sub-items be compatible with 20/721 by default is a very powerful effect. We've only just started the whole NFT thing, and fracturing into another standard instead of leveraging existing ones isn't really a strong move, imo. Existing indexers (Toshi, Trust Wallet, etc) would need to have extra logic to monitor this standard as well. And deploying ERC adaptors for every token just gets you back to the point I'm making; it should just be compatible with the existing standard by default. Anyway, give it a think and see if it solves the problem you're interested in solving. I'm very familiar with the space and the problems you're facing, specifically around gaming, and have thought about this at length as well. A next step would be profiling the gas costs of a composable approach, which I may mind time to do within the next week or two, but can't guarantee. |
I would call that backwards compatible but hey :)
Yes, we do this or sorts in our implementation. Storage contract holds all the data, then the rest is an API over the top of it. Many reasons to do this. Thanks for the discussion @shrugs looking forward to more. |
Hello! Happy to see other people working on something like this. I personally recommend the following changes ;
When it comes to |
Thanks for putting this together! A few folks (@petejkim (Cipher/Toshi), @lsankar4033 (PepeDapp), @pkieltyka (Horizon Games), and myself (Rare Bits/Fan Bits)) were actually bouncing around a Semi Fungible Token standard that may make sense to combine efforts on given the similarities. I've put it below for posterity. That being said, a couple ideological things that may be worth considering:
pragma solidity ^0.4.20;
/// The goal of this spec is to handle a now-common case of having different
/// token types with fungibility within each type.
/// Many DApps are either using ERC721 with multiple-tokens of the same type or deploying
/// multiple ERC20 contracts to create fungible tokens within a set non-fungible token types.
/// An example would be a trading card game with different types but where
/// each card of a given type is indistinguishable from the other. Or an art
/// token where each print of an art piece is indistinguishable from any other print.
/// This is a *VERY* draft spec that is modified from the (near) final
/// ERC721-spec. We should evolve it as necessary from here.
/// @title ERC->>>TBD<<< Semi-Fungible Token Standard
/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-TBD.md
/// Note: the ERC-165 identifier for this interface is >>>TBD<<<
interface ERCTBD /* is ERC165 */ {
/// @dev This emits when ownership of any SFT changes by any mechanism.
/// This event emits when SFTs are created (from == 0) and destroyed
/// (to == 0). Exception: during contract creation, any number of SFTs
/// may be created and assigned without emitting Transfer. At the time of
/// any transfer, the approved address for that SFT (if any) is reset to none.
event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenType, uint256 indexed _value);
/// @dev This emits when the approved address for an SFT is changed or
/// reaffirmed. The zero address indicates there is no approved address.
/// When a Transfer event emits, this also indicates that the approved
/// address for that SFT (if any) is reset to none.
event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenType, uint256 indexed _value);
/// @dev This emits when an operator is enabled or disabled for an owner.
/// The operator can manage all SFTs of the owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @notice Returns the total token supply.
/// @dev Throws if '_tokenType' is not a valid SFT
/// @param _tokenType The type of SFT to get the totalSupply of. Must be less than the return value of totalTokenTypes
/// @return The total supply of the given SFT
function totalSupply(uint256 _tokenType) external view returns (uint256 totalSupply);
/// @notice Count all SFTs of a given type owned by _owner
/// @dev Throws if '_tokenType' is not a valid SFT or if _owner is set to the zero-address
/// @param _owner An address for whom to query the balance
/// @param _tokenType The type of SFT to get the balance of. Must be less than the return value of totalTokenTypes
function balanceOf(address _owner, uint256 _tokenType) external view returns (uint256 balance);
/// @notice Return all token types for a given _owner
/// @param _owner An address for whom to return token types for
function tokenTypesOf(address _owner) external view returns (uint256[] tokenTypes);
/// @notice Returns the total number of token types for this contract
/// @dev Can possibly be zero
/// @return The total number of token types
function totalTokenTypes() external view returns (uint256 totalTokenTypes);
/// @notice Returns the total number of distinct owners who own _tokenType
/// @dev Can possibly be zero
/// @return The total number of distinct owners owning _tokenType
function totalOwners(uint256 _tokenType) external view returns (uint256 totalOwners);
/// @notice Returns the owner of _tokenType specified by _ownerIndex
/// @param _ownerIndex Unique identifier of an owner of _tokenType
/// @return The address of the ownner of _tokenType specified by _ownerIndex
function ownerOf(uint256 _tokenType, uint256 _ownerIndex) external view returns (address owner);
/// @notice Transfers the ownership of some SFTs from one address to another address
/// @dev Throws unless 'msg.sender' is the current owner, an authorized
/// operator, or the approved address for the SFTs. Throws if '_from' is
/// not the current owner. Throws if '_to' is the zero address. Throws if
/// '_tokenType' is not a valid SFT type. When transfer is complete, this function
/// checks if '_to' is a smart contract (code size > 0). If so, it calls
/// 'onERCTBDReceived' on '_to' and throws if the return value is not
/// 'bytes4(keccak256("onERCTBDReceived(address,address,uint256,bytes)"))'.
/// @param _from The current owner of the SFTs
/// @param _to The new owner
/// @param _tokenType The SFT type to transfer. Must be less than the return value of totalTokenTypes
/// @param _value Amount of SFT to transfer
/// @param data Additional data with no specified format, sent in call to '_to'
function safeTransferFrom(address _from, address _to, uint256 _tokenType, uint256 _value, bytes data) external payable;
/// @notice Transfers the ownership of some SFTs from one address to another address
/// @dev This works identically to the other function with an extra data parameter,
/// except this function just sets data to "".
/// @param _from The current owner of the SFTs
/// @param _to The new owner
/// @param _tokenType The SFT type to transfer. Must be less than the return value of totalTokenTypes
/// @param _value Amount of SFT to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenType, uint256 _value) external payable;
/// @notice Transfer ownership of some SFT -- THE CALLER IS RESPONSIBLE
/// TO CONFIRM THAT '_to' IS CAPABLE OF RECEIVING SFTS OR ELSE
/// THEY MAY BE PERMANENTLY LOST
/// @dev Throws unless 'msg.sender' is the current owner, an authorized
/// operator, or the approved address for this SFT. Throws if '_from' is
/// not the current owner. Throws if '_to' is the zero address. Throws if
/// '_tokenType' is not a valid SFT.
/// @param _from The current owner of the SFT
/// @param _to The new owner
/// @param _tokenType The SFT type to transfer. Must be less than the return value of totalTokenTypes
function transferFrom(address _from, address _to, uint256 _tokenType, uint256 _value) external payable;
/// @notice Change or reaffirm the approved address for some SFTs
/// @dev The zero address indicates there is no approved address.
/// Throws unless 'msg.sender' is the current owner of the SFTs, or an authorized
/// operator of the current owner.
/// @param _approved The new approved SFT controller
/// @param _tokenType The SFT type to approve. Must be less than the return value of totalTokenTypes
/// @param _value The amount of SFT able to be withdrawn
function approve(address _approved, uint256 _tokenType, uint256 _value) external payable;
/// @notice Enable or disable approval for a third party ("operator") to manage
/// all of msg.sender's assets
/// @dev Emits the ApprovalForAll event. The contract MUST allow
/// multiple operators per owner.
/// @param _operator Address to add to the set of authorized operators
/// @param _approved True if the operator is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved) external;
/// @notice Get the amount of allowance a spender has for a given owner and SFT type
/// @param _owner The address that owns the SFTs
/// @param _spender The address that is operating on behalf of the owner
/// @param _tokenType The type of SFT to find the approved address for. Must be less than the return value of totalTokenTypes
/// @return The amount able to be spent by the spender for a given owner and type
function allowance(address _owner, address _spender, uint256 _tokenType) external view returns (uint256);
/// @notice Query if an address is an authorized operator for another address
/// @param _owner The address that owns the SFTs
/// @param _operator The address that acts on behalf of the owner
/// @return True if '_operator' is an approved operator for '_owner', false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool);
/// @notice A descriptive name for a collection of SFTs in this contract
function name() external view returns (string _name);
/// @notice An abbreviated name for SFTs of a given type
function symbol(uint256 _tokenType) external view returns (string _symbol);
/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
/// @dev Throws if '_tokenType' is not a valid SFT. URIs are defined in RFC
/// 3986. The URI may point to a JSON file that conforms to the "ERC721
/// Metadata JSON Schema".
function tokenURI(uint256 _tokenType) external view returns (string);
}
interface ERC165 {
/// @notice Query if a contract implements an interface
/// @param interfaceID The interface identifier, as specified in ERC-165
/// @dev Interface identification is specified in ERC-165. This function
/// uses less than 30,000 gas.
/// @return 'true' if the contract implements 'interfaceID' and
/// 'interfaceID' is not 0xffffffff, 'false' otherwise
function supportsInterface(bytes4 interfaceID) external view returns (bool);
} |
@amittmahajan Could you explain what |
@PhABC |
Thanks for adding that @amittmahajan and we'll discuss it internally. What first springs to mind however is that your proposal standard does not allow for approving/transferring etc. on multiple things in one shot as they do not take array arguments. Also the functions such as @PhABC is talking about like totalOwners sound immediately to me like they would need more storage and so gas costs to maintain. I would advocate for as little as possible on chain storage and this sort of "metadata" instead recorded off-chain. |
@amittmahajan Ah I see. How do you keep track of all the owners? I can understand iterating over all token types an user owns if the totsl number of token types is somewhat low, but I can't really see a way to iterate over the owners unless you keep a big array of owners for each token types. Any insights? |
Good to see this proposal. Our use case is for ERC-20 tokens. We want to 'color' tokens by community while allowing them to be fungible on exchanges as a 'clear' token. Within communities transfer of colored tokens will be allowed in the community color only, but outside of communities the rest of the world will see the tokens as a single ERC-20 type token. This looks like a similar solution I came up with to solve this. A standard will encourage the creation of tools and potentially wallets will that can deal with this paradigm. My question: is this EIP just for NFTs or is it intended to be used for ERC-20 tokens as well? |
@PhABC @AC0DEM0NK3Y re: re: multiple token transfer, i think it's a good idea and has a lot of use cases. That being said, I wouldn't be surprised if that function is mostly called with a single type. Perhaps it makes sense to implement that as a new function ( |
@amittmahajan batch transfer is critical for these types of tokens, imo, it's really what makes such an interface interesting. I personally vote for I personally would not include |
We originally had a transfer (single) and multiTransfer (array) in the standard but after testing gas differences and usability we decided it better to just use the array version and name it transfer for simplicity. If you pass in MEW for eg. as well as other methods, the difference in array vs non-array method is almost identical (it is identical in MEW) and the gas difference is negligible and the power of the feature is huge for gas savings and for functionaility. |
With my implementation, it costs around 400k gas to send 100 token types, but single transfer is about 2k gas more expensive using the |
@AC0DEM0NK3Y one downside of a single I think the simplicity cost of having two methods is worth the integration win of cleaner unification with existing standards. |
@lsankar4033 We'll talk/test about that internally and come back on it. My first thought is that transfer has to change even in singular form to include the token/item type:
so if it has to change signature anyway, why not go for the most powerful version if it is just as easy to call, almost as cheap and provides the opportunity for much more functionality? |
Do I really HAVE to emit the URI event for every single token if the URI changes? Wouldn't that mean that if I change some metadata and re-pin on IPFS resulting in a different IPFS hash, that I'll have to emit an event for every token - prohibitively expensive gas if I have thousands of NFTs already minted from a contract? |
@playmint-jbr Yes as far as I know. It would've been nice to have batch uri update function in the standard. |
Agreed, an event which takes a range of token ids or some such would do. I would say this is a significant problem with this standard. |
I've been implementing this EIP and a few issues have come up:
|
How does one take a snapshot of Each Holder wallet and the corresponding tokens in that wallet under 1155 contract? And can the snapshot be taken on regular basis say daily at specific time? |
In this standard i see api to query metadata(uri) and the event to change it. |
The standard doesn't impose an API on how to set the URIs. Some contracts have static URIs that will never change. If your tokens have mutable URIs, then create any necessary methods to update them. It could be Make sure to secure those. |
this contract should have decimals on it |
Up to now (05/22/2022), is there any exchange, swap, dex, wallet to support EIP-1155 including its Fungible Token and Non-Fungible Token? |
Closing this for housekeeping purposes. Feel free to continue using this issue for discussion about EIP-1155 though. |
--- eip: 1155 title: ERC-1155 Multi Token Standard author: Witek Radomski <[email protected]>, Andrew Cooke <[email protected]>, Philippe Castonguay <[email protected]>, James Therien <[email protected]>, Eric Binet <[email protected]>, Ronan Sandford <[email protected]> type: Standards Track category: ERC status: Final created: 2018-06-17 discussions-to: ethereum/EIPs#1155 requires: 165 ---
Simple Summary
A standard interface for contracts that manage multiple token types. A single deployed contract may include any combination of fungible tokens, non-fungible tokens or other configurations (e.g. semi-fungible tokens).
Abstract
This standard outlines a smart contract interface that can represent any number of fungible and non-fungible token types. Existing standards such as ERC-20 require deployment of separate contracts per token type. The ERC-721 standard's token ID is a single non-fungible index and the group of these non-fungibles is deployed as a single contract with settings for the entire collection. In contrast, the ERC-1155 Multi Token Standard allows for each token ID to represent a new configurable token type, which may have its own metadata, supply and other attributes.
The
_id
argument contained in each function's argument set indicates a specific token or token type in a transaction.Motivation
Tokens standards like ERC-20 and ERC-721 require a separate contract to be deployed for each token type or collection. This places a lot of redundant bytecode on the Ethereum blockchain and limits certain functionality by the nature of separating each token contract into its own permissioned address. With the rise of blockchain games and platforms like Enjin Coin, game developers may be creating thousands of token types, and a new type of token standard is needed to support them. However, ERC-1155 is not specific to games and many other applications can benefit from this flexibility.
New functionality is possible with this design such as transferring multiple token types at once, saving on transaction costs. Trading (escrow / atomic swaps) of multiple tokens can be built on top of this standard and it removes the need to "approve" individual token contracts separately. It is also easy to describe and mix multiple fungible or non-fungible token types in a single contract.
Specification
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
Smart contracts implementing the ERC-1155 standard MUST implement all of the functions in the
ERC1155
interface.Smart contracts implementing the ERC-1155 standard MUST implement the ERC-165
supportsInterface
function and MUST return the constant valuetrue
if0xd9b67a26
is passed through theinterfaceID
argument.ERC-1155 Token Receiver
Smart contracts MUST implement all of the functions in the
ERC1155TokenReceiver
interface to accept transfers. See "Safe Transfer Rules" for further detail.Smart contracts MUST implement the ERC-165
supportsInterface
function and signify support for theERC1155TokenReceiver
interface to accept transfers. See "ERC1155TokenReceiver ERC-165 rules" for further detail.Safe Transfer Rules
To be more explicit about how the standard
safeTransferFrom
andsafeBatchTransferFrom
functions MUST operate with respect to theERC1155TokenReceiver
hook functions, a list of scenarios and rules follows.Scenarios
Scenario#1 : The recipient is not a contract.
onERC1155Received
andonERC1155BatchReceived
MUST NOT be called on an EOA (Externally Owned Account).Scenario#2 : The transaction is not a mint/transfer of a token.
onERC1155Received
andonERC1155BatchReceived
MUST NOT be called outside of a mint or transfer process.Scenario#3 : The receiver does not implement the necessary
ERC1155TokenReceiver
interface function(s).Scenario#4 : The receiver implements the necessary
ERC1155TokenReceiver
interface function(s) but returns an unknown value.Scenario#5 : The receiver implements the necessary
ERC1155TokenReceiver
interface function(s) but throws an error.Scenario#6 : The receiver implements the
ERC1155TokenReceiver
interface and is the recipient of one and only one balance change (e.g.safeTransferFrom
called).ERC1155TokenReceiver
hook is called on a recipient contract.ERC1155TokenReceiver
hook is called on the recipient contract.onERC1155Received
oronERC1155BatchReceived
MUST be called on the recipient contract.onERC1155Received
hook SHOULD be called on the recipient contract and its rules followed.onERC1155BatchReceived
hook MAY be called on the recipient contract and its rules followed.Scenario#7 : The receiver implements the
ERC1155TokenReceiver
interface and is the recipient of more than one balance change (e.g.safeBatchTransferFrom
called).ERC1155TokenReceiver
hook MUST be updated before theERC1155TokenReceiver
hook is called on the recipient contract.ERC1155TokenReceiver
hook is called on the recipient contract.onERC1155Received
oronERC1155BatchReceived
MUST be called on the recipient as many times as necessary such that every balance change for the recipient in the scenario is accounted for.onERC1155BatchReceived
hook SHOULD be called on the recipient contract and its rules followed.onERC1155Received
hook MAY be called on the recipient contract and its rules followed.Scenario#8 : You are the creator of a contract that implements the
ERC1155TokenReceiver
interface and you forward the token(s) onto another address in one or both ofonERC1155Received
andonERC1155BatchReceived
.safeTransferFrom
orsafeBatchTransferFrom
in a new context._data
argument MAY be re-purposed for the new context.Scenario#9 : You are transferring tokens via a non-standard API call i.e. an implementation specific API and NOT
safeTransferFrom
orsafeBatchTransferFrom
.TransferSingle
andTransferBatch
events alone.ERC1155TokenReceiver
hooks still need to be called on it and the return values respected the same as if a standard transfer function had been called.safeTransferFrom
orsafeBatchTransferFrom
functions MUST revert if a receiving contract does not implement theERC1155TokenReceiver
interface, a non-standard function MAY proceed with the transfer.Rules
safeTransferFrom rules:
_from
account (see "Approval" section)._to
is the zero address._id
is lower than the_value
sent to the recipient.TransferSingle
event to reflect the balance change (see "TransferSingle and TransferBatch event rules" section)._to
is a smart contract (e.g. code size > 0). If so, it MUST callonERC1155Received
on_to
and act appropriately (see "onERC1155Received rules" section)._data
argument provided by the sender for the transfer MUST be passed with its contents unaltered to theonERC1155Received
hook function via its_data
argument.safeBatchTransferFrom rules:
_from
account (see "Approval" section)._to
is the zero address._ids
is not the same as length of_values
._ids
is lower than the respective amount(s) in_values
sent to the recipient.TransferSingle
orTransferBatch
event(s) such that all the balance changes are reflected (see "TransferSingle and TransferBatch event rules" section)._to
is a smart contract (e.g. code size > 0). If so, it MUST callonERC1155Received
oronERC1155BatchReceived
on_to
and act appropriately (see "onERC1155Received and onERC1155BatchReceived rules" section)._data
argument provided by the sender for the transfer MUST be passed with its contents unaltered to theERC1155TokenReceiver
hook function(s) via their_data
argument.TransferSingle and TransferBatch event rules:
TransferSingle
SHOULD be used to indicate a single balance transfer has occurred between a_from
and_to
pair.TransferBatch
is designed for this to reduce gas consumption._operator
argument MUST be the address of an account/contract that is approved to make the transfer (SHOULD be msg.sender)._from
argument MUST be the address of the holder whose balance is decreased._to
argument MUST be the address of the recipient whose balance is increased._id
argument MUST be the token type being transferred._value
argument MUST be the number of tokens the holder balance is decreased by and match what the recipient balance is increased by._from
argument MUST be set to0x0
(i.e. zero address). See "Minting/creating and burning/destroying rules"._to
argument MUST be set to0x0
(i.e. zero address). See "Minting/creating and burning/destroying rules".TransferBatch
SHOULD be used to indicate multiple balance transfers have occurred between a_from
and_to
pair.TransferSingle
is designed for this to reduce gas consumption._operator
argument MUST be the address of an account/contract that is approved to make the transfer (SHOULD be msg.sender)._from
argument MUST be the address of the holder whose balance is decreased for each entry pair in_ids
and_values
._to
argument MUST be the address of the recipient whose balance is increased for each entry pair in_ids
and_values
._ids
array argument MUST contain the ids of the tokens being transferred._values
array argument MUST contain the number of token to be transferred for each corresponding entry in_ids
._ids
and_values
MUST have the same length._from
argument MUST be set to0x0
(i.e. zero address). See "Minting/creating and burning/destroying rules"._to
argument MUST be set to0x0
(i.e. zero address). See "Minting/creating and burning/destroying rules".0x0
minus the total value transferred to0x0
observed via theTransferSingle
andTransferBatch
events MAY be used by clients and exchanges to determine the "circulating supply" for a given token ID.TransferSingle
event from0x0
to0x0
, with the token creator as_operator
, and a_value
of 0.TransferSingle
andTransferBatch
events MUST be emitted to reflect all the balance changes that have occurred before any call(s) toonERC1155Received
oronERC1155BatchReceived
.onERC1155Received rules:
_operator
argument MUST be the address of an account/contract that is approved to make the transfer (SHOULD be msg.sender)._from
argument MUST be the address of the holder whose balance is decreased._from
MUST be 0x0 for a mint._id
argument MUST be the token type being transferred._value
argument MUST be the number of tokens the holder balance is decreased by and match what the recipient balance is increased by._data
argument MUST contain the information provided by the sender for the transfer with its contents unaltered._data
argument sent via thesafeTransferFrom
orsafeBatchTransferFrom
call for this transfer.bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))
bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))
the transfer MUST be completed or MUST revert if any other conditions are not met for success.bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))
the transaction MUST be reverted.onERC1155Received
(and/oronERC1155BatchReceived
) MAY be called multiple times in a single transaction and the following requirements must be met:onERC1155Received
andonERC1155BatchReceived
describes all balance changes that occurred during the transaction in the order submitted.onERC1155Received
hook function if the transfer operation is transferring the token to itself.onERC1155BatchReceived rules:
_operator
argument MUST be the address of an account/contract that is approved to make the transfer (SHOULD be msg.sender)._from
argument MUST be the address of the holder whose balance is decreased._from
MUST be 0x0 for a mint._ids
argument MUST be the list of tokens being transferred._values
argument MUST be the list of number of tokens (matching the list and order of tokens specified in_ids
) the holder balance is decreased by and match what the recipient balance is increased by._data
argument MUST contain the information provided by the sender for the transfer with its contents unaltered._data
argument sent via thesafeBatchTransferFrom
call for this transfer.bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))
bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))
the transfer MUST be completed or MUST revert if any other conditions are not met for success.bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))
the transaction MUST be reverted.onERC1155BatchReceived
(and/oronERC1155Received
) MAY be called multiple times in a single transaction and the following requirements must be met:onERC1155Received
andonERC1155BatchReceived
describes all balance changes that occurred during the transaction in the order submitted.onERC1155BatchReceived
hook function if the transfer operation is transferring the token(s) to itself.ERC1155TokenReceiver ERC-165 rules:
supportsInterface
function SHOULD be as follows:true
if0x01ffc9a7
is passed through theinterfaceID
argument. This signifies ERC-165 support.true
if0x4e2312e0
is passed through theinterfaceID
argument. This signifies ERC-1155ERC1155TokenReceiver
support.Implementation specific transfer API rules:
safeTransferFrom
orsafeBatchTransferFrom
(as appropriate) rules MUST still be followed if the receiver implements theERC1155TokenReceiver
interface. If it does not the non-standard implementation SHOULD revert but MAY proceed.function myTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _values);
.myTransferFrom
updates the balances for_from
and_to
addresses for all_ids
and_values
.myTransferFrom
emitsTransferBatch
with the details of what was transferred from address_from
to address_to
.myTransferFrom
checks if_to
is a contract address and determines that it is so (if not, then the transfer can be considered successful).myTransferFrom
callsonERC1155BatchReceived
on_to
and it reverts or returns an unknown value (if it had returnedbytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))
the transfer can be considered successful).myTransferFrom
SHOULD revert the transaction immediately as receipt of the token(s) was not explicitly accepted by theonERC1155BatchReceived
function.myTransferFrom
wishes to continue it MUST callsupportsInterface(0x4e2312e0)
on_to
and if it returns the constant valuetrue
the transaction MUST be reverted, as it is now known to be a valid receiver and the previous acceptance step failed.supportsInterface(0x4e2312e0)
at a previous step if you wanted to gather and act upon that information earlier, such as in a hybrid standards scenario.supportsInterface(0x4e2312e0)
on_to
reverts or returns a value other than the constant valuetrue
themyTransferFrom
function MAY consider this transfer successful.safeTransferFrom
andsafeBatchTransferFrom
):ERC1155TokenReceiver
hook function(s) have to be called on it.ERC1155TokenReceiver
hook MUST be updated (and emitted) before theERC1155TokenReceiver
hook is called.ERC1155TokenReceiver
hook functions that are called MUST be respected if they are implemented.ERC1155TokenReceiver
hook functions.safeTransferFrom
andsafeBatchTransferFrom
MUST revert in that case (unless it is a hybrid standards implementation see "Compatibility with other standards").Minting/creating and burning/destroying rules:
TransferSingle
event from0x0
to0x0
, with the token creator as_operator
, and a_value
of 0._from
argument MUST be set to0x0
(i.e. zero address) to flag the transfer as a mint to contract observers._to
argument MUST be set to0x0
(i.e. zero address) to flag the transfer as a burn to contract observers.0x0
(that is impl specific), only the_to
argument in the event MUST be set to0x0
as above.0x0
minus the total value transferred to0x0
observed via theTransferSingle
andTransferBatch
events MAY be used by clients and exchanges to determine the "circulating supply" for a given token ID.safeTransferFrom
orsafeBatchTransferFrom
. If so the "Implementation specific transfer API rules" section would be appropriate.ERC1155TokenReceiver
hook function(s) if the mint operation is transferring the token(s) to itself. In all other cases theERC1155TokenReceiver
rules MUST be followed as appropriate for the implementation (i.e. safe, custom and/or hybrid).A solidity example of the keccak256 generated constants for the various magic values (these MAY be used by implementation):
Compatibility with other standards
There have been requirements during the design discussions to have this standard be compatible with existing standards when sending to contract addresses, specifically ERC-721 at time of writing.
To cater for this scenario, there is some leeway with the revert logic should a contract not implement the
ERC1155TokenReceiver
as per "Safe Transfer Rules" section above, specifically "Scenario#3 : The receiver does not implement the necessaryERC1155TokenReceiver
interface function(s)".Hence in a hybrid ERC-1155 contract implementation an extra call MUST be made on the recipient contract and checked before any hook calls to
onERC1155Received
oronERC1155BatchReceived
are made.Order of operation MUST therefore be:
supportsInterface(0x4e2312e0)
on the recipient contract, providing at least 10,000 gas.true
the implementation proceeds as a regular ERC-1155 implementation, with the call(s) to theonERC1155Received
oronERC1155BatchReceived
hooks and rules associated.true
the implementation can assume the recipient contract is not anERC1155TokenReceiver
and follow its other standard's rules for transfers.Note that a pure implementation of a single standard is recommended rather than a hybrid solution, but an example of a hybrid ERC-1155/ERC-721 contract is linked in the references section under implementations.
An important consideration is that even if the tokens are sent with another standard's rules the ERC-1155 transfer events MUST still be emitted. This is so the balances can still be determined via events alone as per ERC-1155 standard rules.
Metadata
The URI value allows for ID substitution by clients. If the string
{id}
exists in any URI, clients MUST replace this with the actual token ID in hexadecimal form. This allows for a large number of tokens to use the same on-chain string by defining a URI once, for that large number of tokens.[0-9a-f]
with no 0x prefix.Example of such a URI:
https://token-cdn-domain/{id}.json
would be replaced withhttps://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json
if the client is referring to token ID 314592/0x4CCE0.Metadata Extensions
The optional
ERC1155Metadata_URI
extension can be identified with the (ERC-165 Standard Interface Detection)[https://eips.ethereum.org/EIPS/eip-165].If the optional
ERC1155Metadata_URI
extension is included:supportsInterface
function MUST return the constant valuetrue
if0x0e89341c
is passed through theinterfaceID
argument.URI
event if the change can be expressed with an event (i.e. it isn't dynamic/programmatic).URI
event during a mint operation but it is NOT mandatory. An observer MAY fetch the metadata uri at mint time from theuri
function if it was not emitted.uri
function SHOULD be used to retrieve values if no event was emitted.uri
function MUST return the same value as the latest event for an_id
if it was emitted.uri
function MUST NOT be used to check for the existence of a token as it is possible for an implementation to return a valid string even if the token does not exist.ERC-1155 Metadata URI JSON Schema
This JSON schema is loosely based on the "ERC721 Metadata JSON Schema", but includes optional formatting to allow for ID substitution by clients. If the string
{id}
exists in any JSON value, it MUST be replaced with the actual token ID, by all client software that follows this standard.[0-9a-f]
with no 0x prefix.An example of an ERC-1155 Metadata JSON file follows. The properties array proposes some SUGGESTED formatting for token-specific display properties and metadata.
Localization
Metadata localization should be standardized to increase presentation uniformity across all languages. As such, a simple overlay method is proposed to enable localization. If the metadata JSON file contains a
localization
attribute, its content MAY be used to provide localized values for fields that need it. Thelocalization
attribute should be a sub-object with three attributes:uri
,default
andlocales
. If the string{locale}
exists in any URI, it MUST be replaced with the chosen locale by all client software.JSON Schema
Localized Sample
Base URI:
es.json:
fr.json:
Approval
The function
setApprovalForAll
allows an operator to manage one's entire set of tokens on behalf of the approver. To permit approval of a subset of token IDs, an interface such as ERC-1761 Scoped Approval Interface is suggested.The counterpart
isApprovedForAll
provides introspection into any status set bysetApprovalForAll
.An owner SHOULD be assumed to always be able to operate on their own tokens regardless of approval status, so should SHOULD NOT have to call
setApprovalForAll
to approve themselves as an operator before they can operate on them.Rationale
Metadata Choices
The
symbol
function (found in the ERC-20 and ERC-721 standards) was not included as we do not believe this is a globally useful piece of data to identify a generic virtual item / asset and are also prone to collisions. Short-hand symbols are used in tickers and currency trading, but they aren't as useful outside of that space.The
name
function (for human-readable asset names, on-chain) was removed from the standard to allow the Metadata JSON to be the definitive asset name and reduce duplication of data. This also allows localization for names, which would otherwise be prohibitively expensive if each language string was stored on-chain, not to mention bloating the standard interface. While this decision may add a small burden on implementers to host a JSON file containing metadata, we believe any serious implementation of ERC-1155 will already utilize JSON Metadata.Upgrades
The requirement to emit
TransferSingle
orTransferBatch
on balance change implies that a valid implementation of ERC-1155 redeploying to a new contract address MUST emit events from the new contract address to replicate the deprecated contract final state. It is valid to only emit a minimal number of events to reflect only the final balance and omit all the transactions that led to that state. The event emit requirement is to ensure that the current state of the contract can always be traced only through events. To alleviate the need to emit events when changing contract address, consider using the proxy pattern, such as described in ERC-1538. This will also have the added benefit of providing a stable contract address for users.Design decision: Supporting non-batch
The standard supports
safeTransferFrom
andonERC1155Received
functions because they are significantly cheaper for single token-type transfers, which is arguably a common use case.Design decision: Safe transfers only
The standard only supports safe-style transfers, making it possible for receiver contracts to depend on
onERC1155Received
oronERC1155BatchReceived
function to be always called at the end of a transfer.Guaranteed log trace
As the Ethereum ecosystem continues to grow, many dapps are relying on traditional databases and explorer API services to retrieve and categorize data. The ERC-1155 standard guarantees that event logs emitted by the smart contract will provide enough data to create an accurate record of all current token balances. A database or explorer may listen to events and be able to provide indexed and categorized searches of every ERC-1155 token in the contract.
Approval
The function
setApprovalForAll
allows an operator to manage one's entire set of tokens on behalf of the approver. It enables frictionless interaction with exchange and trade contracts.Restricting approval to a certain set of token IDs, quantities or other rules MAY be done with an additional interface or an external contract. The rationale is to keep the ERC-1155 standard as generic as possible for all use-cases without imposing a specific approval scheme on implementations that may not need it. Standard token approval interfaces can be used, such as the suggested ERC-1761 Scoped Approval Interface which is compatible with ERC-1155.
Usage
This standard can be used to represent multiple token types for an entire domain. Both fungible and non-fungible tokens can be stored in the same smart-contract.
Batch Transfers
The
safeBatchTransferFrom
function allows for batch transfers of multiple token IDs and values. The design of ERC-1155 makes batch transfers possible without the need for a wrapper contract, as with existing token standards. This reduces gas costs when more than one token type is included in a batch transfer, as compared to single transfers with multiple transactions.Another advantage of standardized batch transfers is the ability for a smart contract to respond to the batch transfer in a single operation using
onERC1155BatchReceived
.It is RECOMMENDED that clients and wallets sort the token IDs and associated values (in ascending order) when posting a batch transfer, as some ERC-1155 implementations offer significant gas cost savings when IDs are sorted. See Horizon Games - Multi-Token Standard "packed balance" implementation for an example of this.
Batch Balance
The
balanceOfBatch
function allows clients to retrieve balances of multiple owners and token IDs with a single call.Enumerating from events
In order to keep storage requirements light for contracts implementing ERC-1155, enumeration (discovering the IDs and values of tokens) must be done using event logs. It is RECOMMENDED that clients such as exchanges and blockchain explorers maintain a local database containing the token ID, Supply, and URI at the minimum. This can be built from each TransferSingle, TransferBatch, and URI event, starting from the block the smart contract was deployed until the latest block.
ERC-1155 contracts must therefore carefully emit
TransferSingle
orTransferBatch
events in any instance where tokens are created, minted, transferred or destroyed.Non-Fungible Tokens
The following strategies are examples of how you MAY mix fungible and non-fungible tokens together in the same contract. The standard does NOT mandate how an implementation must do this.
Split ID bits
The top 128 bits of the uint256
_id
parameter in any ERC-1155 function MAY represent the base token ID, while the bottom 128 bits MAY represent the index of the non-fungible to make it unique.Non-fungible tokens can be interacted with using an index based accessor into the contract/token data set. Therefore to access a particular token set within a mixed data contract and a particular non-fungible within that set,
_id
could be passed as<uint128: base token id><uint128: index of non-fungible>
.To identify a non-fungible set/category as a whole (or a fungible) you COULD just pass in the base id via the
_id
argument as<uint128: base token id><uint128: zero>
. If your implementation uses this technique this naturally means the index of a non-fungible SHOULD be 1-based.Inside the contract code the two pieces of data needed to access the individual non-fungible can be extracted with uint128(~0) and the same mask shifted by 128.
Note that 128 is an arbitrary number, an implementation MAY choose how they would like this split to occur as suitable for their use case. An observer of the contract would simply see events showing balance transfers and mints happening and MAY track the balances using that information alone.
For an observer to be able to determine type (non-fungible or fungible) from an ID alone they would have to know the split ID bits format on a implementation by implementation basis.
The ERC-1155 Reference Implementation is an example of the split ID bits strategy.
Natural Non-Fungible tokens
Another simple way to represent non-fungibles is to allow a maximum value of 1 for each non-fungible token. This would naturally mirror the real world, where unique items have a quantity of 1 and fungible items have a quantity greater than 1.
References
Standards
Implementations
Articles & Discussions
Copyright
Copyright and related rights waived via CC0.
The text was updated successfully, but these errors were encountered: