{"action":"created","issue":{"url":"https://api.github.com/repos/ethereum/EIPs/issues/1155","repository_url":"https://api.github.com/repos/ethereum/EIPs","labels_url":"https://api.github.com/repos/ethereum/EIPs/issues/1155/labels{/name}","comments_url":"https://api.github.com/repos/ethereum/EIPs/issues/1155/comments","events_url":"https://api.github.com/repos/ethereum/EIPs/issues/1155/events","html_url":"https://github.com/ethereum/EIPs/issues/1155","id":333091780,"node_id":"MDU6SXNzdWUzMzMwOTE3ODA=","number":1155,"title":"ERC: Crypto Items Token Standard","user":{"login":"coinfork","id":2774008,"node_id":"MDQ6VXNlcjI3NzQwMDg=","avatar_url":"https://avatars1.githubusercontent.com/u/2774008?v=4","gravatar_id":"","url":"https://api.github.com/users/coinfork","html_url":"https://github.com/coinfork","followers_url":"https://api.github.com/users/coinfork/followers","following_url":"https://api.github.com/users/coinfork/following{/other_user}","gists_url":"https://api.github.com/users/coinfork/gists{/gist_id}","starred_url":"https://api.github.com/users/coinfork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coinfork/subscriptions","organizations_url":"https://api.github.com/users/coinfork/orgs","repos_url":"https://api.github.com/users/coinfork/repos","events_url":"https://api.github.com/users/coinfork/events{/privacy}","received_events_url":"https://api.github.com/users/coinfork/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":161,"created_at":"2018-06-17T20:48:30Z","updated_at":"2018-09-20T04:40:36Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"## Preamble\r\n```\r\n---\r\neip: 1155\r\ntitle: Crypto Item Standard\r\nauthor: Witek Radomski <witek@enjin.com>, Andrew Cooke <andrew@enjin.com>\r\ntype: Standards Track\r\ncategory: ERC\r\nstatus: Draft\r\ncreated: 2018-06-17\r\ndiscussions-to: https://github.com/ethereum/EIPs/issues/1155\r\n---\r\n```\r\n\r\n## Simple Summary\r\n\r\nA standard interface for multiple item/token definitions in a single deployed contract.\r\n\r\n## Abstract\r\n\r\nThis standard outlines a smart contract interface where one can represent any number of Fungible and Non-Fungible assets in a single contract. Existing standards such as ERC-20 require deployment of separate contracts per token. 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. Instead, the ERC-1155 Crypto Item Standard allows for each Item ID to represent a new configurable token type, which may have its own totalSupply value and other such attributes.\r\n\r\nThe `_id` parameter is contained in each function's parameters and indicates a specific item or item type in a transaction.\r\n\r\n## Motivation\r\n\r\nTokens standards like ERC-20 and ERC-721 require a separate contract to be deployed for each fungible or NFT token/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 crypto games and platforms like [Enjin Coin](https://enjincoin.io/), game developers may be creating tens of thousands of items, and a new type of token standard is needed to support this.\r\n\r\nNew functionality is possible with this design, such as transferring or approving 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 tokens separately. It is also easy to describe and mix multiple fungible or non-fungible tokens in a single contract.\r\n\r\n### Multicast Transfers\r\n\r\nThe `multicastTransferFrom` function allows for batch transfers to and from multiple addresses. It's also possible to create a simple atomic swap by obtaining approvals from the source and destination parties, and executing this function.\r\n\r\n### Backwards Compatibility\r\n\r\nThis standard is compatible with ERC-721 non-fungible tokens. Both interfaces can be inherited without conflict:\r\n\r\n```solidity\r\ncontract GameItems is ERC1155, ERC721 {\r\n\t...\r\n}\r\n```\r\n\r\n# Specification\r\n\r\n```solidity\r\npragma solidity ^0.4.24;\r\n\r\n/**\r\n    @title ERC-1155 Crypto Items Standard\r\n    @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md\r\n    Note: the ERC-165 identifier for this interface is 0xf23a6e61.\r\n */\r\ninterface ERC1155 {\r\n    /**\r\n        @dev MUST trigger on any successful call to approve(address _spender, uint256 _value)\r\n    */\r\n    event Approval(address indexed _owner, address indexed _spender, uint256 indexed _id, uint256 _oldValue, uint256 _value);\r\n    \r\n    /**\r\n        @dev MUST trigger when tokens are transferred, including zero value transfers\r\n        This emits when ownership of any NFT changes by any mechanism.\r\n        This event emits when NFTs are created (`from` == 0) and destroyed\r\n        (`to` == 0). Exception: during contract creation, any number of NFTs\r\n        may be created and assigned without emitting Transfer. At the time of\r\n        any transfer, the approved address for that NFT (if any) is reset to none.\r\n    */\r\n    event Transfer(address _spender, address indexed _from, address indexed _to, uint256 indexed _id, uint256 _value);\r\n    \r\n    /**\r\n        @dev Transfers value amount of an _id from the _from address to the _to addresses specified. Each parameter array should be the same length, with each index correlating.\r\n        Caller must have a sufficient allowance by _from for the _id/_value pair\r\n        Throws if `_to` is the zero address.\r\n        Throws if `_id` is not a valid NFT.\r\n        When transfer is complete, this function checks if `_to` is a smart contract (code size > 0). If so, it calls `onERC1155Received` on `_to` and throws if the return value is not `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))`.\r\n        @param _from    source addresses\r\n        @param _to      target addresses\r\n        @param _id      ID of the CryptoItem\r\n        @param _value   transfer amounts\r\n        @param _data    Additional data with no specified format, sent in call to `_to`\r\n    */\r\n    function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes _data) external;\r\n    \r\n    /**\r\n        @dev Send multiple types of CryptoItems from a 3rd party in one transfer (with safety call)\r\n        For the purpose of transfer fees, each id/value pair is counted as a transfer\r\n        Caller must have a sufficient allowance by _from for each of the _id/_value pairs\r\n        Throws on any error rather than return a false flag to minimize user errors\r\n        @param _from    Source address\r\n        @param _to      Target address\r\n        @param _ids     Types of CryptoItems\r\n        @param _values  Transfer amounts per item type\r\n        @param _data    Additional data with no specified format, sent in call to `_to`\r\n    */\r\n    function safeBatchTransferFrom(address _from, address _to, uint256[] _ids, uint256[] _values, bytes _data) external;\r\n    \r\n    /**\r\n        @dev Allow other accounts/contracts to spend tokens on behalf of msg.sender\r\n        Also, to minimize the risk of the approve/transferFrom attack vector\r\n        (see https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/), this function will throw if the current approved allowance does not equal the expected _currentValue, unless _value is 0\r\n        @param _spender      Address to approve\r\n        @param _id           ID of the CryptoItem\r\n        @param _currentValue Expected current value of approved allowance.\r\n        @param _value        Allowance amount\r\n    */\r\n    function approve(address _spender, uint256 _id, uint256 _currentValue, uint256 _value) external;\r\n    \r\n    /**\r\n        @dev Get the balance of an account's CryptoItems\r\n        @param _id     ID of the CryptoItem\r\n        @param _owner  The address of the token holder\r\n        @return        The _owner's balance of the CryptoItem type requested\r\n     */\r\n    function balanceOf(uint256 _id, address _owner) external view returns (uint256);\r\n    \r\n    /**\r\n        @dev Queries the spending limit approved for an account\r\n        @param _id       ID of the CryptoItem\r\n        @param _owner    The owner allowing the spending\r\n        @param _spender  The address allowed to spend.\r\n        @return          The _spender's allowed spending balance of the CryptoItem requested\r\n     */\r\n    function allowance(uint256 _id, address _owner, address _spender) external view returns (uint256);\r\n}\r\n```\r\n</details>\r\n\r\n<details>\r\n<summary>\r\nBatch Transfers</summary>\r\n\r\n```solidity\r\ninterface ERC1155Batch {\r\n    /**\r\n        @dev Allow other accounts/contracts to spend tokens on behalf of msg.sender\r\n        Also, to minimize the risk of the approve/transferFrom attack vector\r\n        (see https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/), this function will throw if the current approved allowance does not equal the expected _currentValue, unless _value is 0\r\n        @param _spender        Address to approve\r\n        @param _ids            IDs of the CryptoItems\r\n        @param _currentValues  Expected current values of allowances per item type\r\n        @param _values         Allowance amounts per item type\r\n    */\r\n    function batchApprove(address _spender, uint256[] _ids,  uint256[] _currentValues, uint256[] _values) external;\r\n    \r\n    /**\r\n        @dev Send multiple types of CryptoItems in one transfer from multiple sources\r\n        For the purpose of transfer fees, each id/value pair is counted as a transfer.\r\n        @param _from\tSource addresses\r\n        @param _to\t\tTransfer destination addresses\r\n        @param _ids  \tTypes of CryptoItems\r\n        @param _values\tTransfer amounts\r\n    */\r\n    function multicastTransferFrom(address[] _from, address[] _to, uint256[] _ids, uint256[] _values) external;\r\n}\r\n```\r\n\r\n</details>\r\n\r\n<details>\r\n<summary>\r\nExtended Approvals</summary>\r\n\r\n```solidity\r\ninterface ERC1155Operators {\r\n    event OperatorApproval(address indexed _owner, address indexed _operator, uint256 indexed _id, bool _approved);\r\n    event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);\r\n\r\n    /**\r\n        @notice Enable or disable approval for a third party (\"operator\") to manage\r\n        all of `msg.sender`'s assets for a particular CryptoItem types.\r\n        @dev Emits the OperatorApproval event\r\n        @param _operator  Address to add to the set of authorized operators\r\n        @param _ids       The IDs of the CryptoItems\r\n        @param _approved  True if the operators is approved, false to revoke approval\r\n    */\r\n    function setApproval(address _operator, uint256[] _ids, bool _approved) external;\r\n    \r\n    /**\r\n        @dev Queries the approval status of an operator for a given CryptoItem and owner\r\n        @param _owner     The owner of the CryptoItems\r\n        @param _operator  Address of authorized operator\r\n        @param _id        ID of the CryptoItem\r\n        @return           True if the operator is approved, false if not\r\n    */\r\n    function isApproved(address _owner, address _operator, uint256 _id)  external view returns (bool);\r\n    \r\n    /**\r\n        @notice Enable or disable approval for a third party (\"operator\") to manage\r\n        all of `msg.sender`'s assets.\r\n        @dev Emits the OperatorApproval event\r\n        @param _operator  Address to add to the set of authorized operators\r\n        @param _approved  True if the operator is approved, false to revoke approval\r\n    */\r\n    function setApprovalForAll(address _operator, bool _approved) external;\r\n    \r\n    /** \r\n        @dev Queries the approval status of an operator for a given CryptoItem and owner\r\n        @param _owner     The owner of the CryptoItems\r\n        @param _operator  Address of authorized operator\r\n        @return           True if the operator is approved, false if not\r\n    */\r\n    function isApprovedForAll(address _owner, address _operator) external view returns (bool isOperator);\r\n}\r\n```\r\n\r\n</details>\r\n\r\n<details>\r\n<summary>\r\nViews</summary>\r\n\r\n```solidity\r\ninterface ERC1155Metadata {\r\n    /**\r\n        @notice A distinct Uniform Resource Identifier (URI) for a given asset\r\n        @dev URIs are defined in RFC 3986\r\n        @return  URI string\r\n    */\r\n    function uri(uint256 _id) external view returns (string);\r\n\r\n    /**\r\n        @dev Returns a human readable string that identifies a CryptoItem, similar to ERC20\r\n        @param _id  ID of the CryptoItem\r\n        @return     The name of the CryptoItem type\r\n     */\r\n    function name(uint256 _id) external view returns (string);\r\n}\r\n```\r\n\r\n</details>\r\n\r\n## ERC-1155 Token Receiver\r\n\r\nSmart contracts **MUST** implement this interface to accept safe transfers.\r\n\r\n```solidity\r\ninterface ERC1155TokenReceiver {\r\n    /**\r\n        @notice Handle the receipt of an ERC1155 type\r\n        @dev The smart contract calls this function on the recipient\r\n        after a `safeTransfer`. This function MAY throw to revert and reject the\r\n        transfer. Return of other than the magic value MUST result in the\r\n        transaction being reverted\r\n        Note: the contract address is always the message sender\r\n        @param _operator  The address which called `safeTransferFrom` function\r\n        @param _from      The address which previously owned the token\r\n        @param _id        The identifier of the item being transferred\r\n        @param _value     The amount of the item being transferred\r\n        @param _data      Additional data with no specified format\r\n        @return           `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))`\r\n    */\r\n    function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes _data) external returns(bytes4);\r\n}\r\n```\r\n\r\n## Non-Fungible Items\r\n\r\nAn example strategy to mix Fungible and Non-Fungible Items together in the same contract would 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.\r\n\r\nNon-Fungible Items can be 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>`.\r\n\r\nInside 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.\r\n\r\n### Interface\r\n\r\n<details>\r\n<summary>\r\nOptional Non Fungible Interface</summary>\r\n\r\n```solidity\r\ninterface ERC1155NonFungible {\r\n    /**\r\n        @notice Find the owner of an NFT\r\n        @dev NFTs assigned to zero address are considered invalid, and queries about them do throw\r\n        @param _id  The identifier for an NFT\r\n        @return     The address of the owner of the NFT\r\n    */\r\n    function ownerOf(uint256 _id) external view returns (address);\r\n    \r\n    /**\r\n        @notice Enumerate valid NFs\r\n        @dev Throws if `_index` >= `totalSupply()`.\r\n        @param _index  A counter less than `totalSupply()`\r\n        @return        The token identifier for the `_index`th NFT (sort order not specified)\r\n    */\r\n    function nonFungibleByIndex(uint256 _id, uint128 _index) external view returns (uint256);\r\n    \r\n    /**\r\n        @notice Enumerate NFTs assigned to an owner\r\n        @dev Throws if `_index` >= `balanceOf(_owner)` or if\r\n        `_owner` is the zero address, representing invalid NFTs\r\n        @param _owner  An address where we are interested in NFTs owned by them\r\n        @param _index  A counter less than `balanceOf(_owner)`\r\n        @return        The token identifier for the `_index`th NFT assigned to `_owner` (sort order not specified)\r\n    */\r\n    function nonFungibleOfOwnerByIndex(uint256 _id, address _owner, uint128 _index) external view returns (uint256);\r\n    \r\n    /**\r\n        @notice Is this token non fungible?\r\n        @dev If this returns true, the token is non-fungible.\r\n        @param _id  The identifier for a potential non-fungible.\r\n        @return     True if the token is non-fungible\r\n    */\r\n    function isNonFungible(uint256 _id) external view returns (bool);\r\n}\r\n```\r\n\r\n</details>\r\n\r\n### Example of split ID bits\r\n\r\n```solidity\r\nuint256 baseToken = 12345 << 128;\r\nuint128 index = 50;\r\n\r\nbalanceOf(baseToken, msg.sender); // Get balance of the base token\r\nbalanceOf(baseToken + index, msg.sender); // Get balance of the Non-Fungible token index\r\n```\r\n\r\n## Implementation\r\n\r\n- [ERC-1155 Reference Implementation](https://github.com/enjin/erc-1155)\r\n- [Enjin Coin](https://enjincoin.io) ([github](https://github.com/enjin))\r\n\r\n## Copyright\r\nCopyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).\r\n"},"comment":{"url":"https://api.github.com/repos/ethereum/EIPs/issues/comments/423037931","html_url":"https://github.com/ethereum/EIPs/issues/1155#issuecomment-423037931","issue_url":"https://api.github.com/repos/ethereum/EIPs/issues/1155","id":423037931,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzAzNzkzMQ==","user":{"login":"PhABC","id":9306422,"node_id":"MDQ6VXNlcjkzMDY0MjI=","avatar_url":"https://avatars2.githubusercontent.com/u/9306422?v=4","gravatar_id":"","url":"https://api.github.com/users/PhABC","html_url":"https://github.com/PhABC","followers_url":"https://api.github.com/users/PhABC/followers","following_url":"https://api.github.com/users/PhABC/following{/other_user}","gists_url":"https://api.github.com/users/PhABC/gists{/gist_id}","starred_url":"https://api.github.com/users/PhABC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PhABC/subscriptions","organizations_url":"https://api.github.com/users/PhABC/orgs","repos_url":"https://api.github.com/users/PhABC/repos","events_url":"https://api.github.com/users/PhABC/events{/privacy}","received_events_url":"https://api.github.com/users/PhABC/received_events","type":"User","site_admin":false},"created_at":"2018-09-20T04:40:36Z","updated_at":"2018-09-20T04:40:36Z","author_association":"CONTRIBUTOR","body":"Yes I agree. I think the community will settle on a name overtime, while using ERC-1155 or their favorite term until then. I don't really care about the standard name as it does not influence the implementation and am ok leaving it as is."}}
{"actor":{"display_login":"PhABC"}}