Address ERC1155 changes (#2267)
* Make holder fns public * Add context, remove msg.sender from check * Fix location of Holder arguments * Add beforeTransfer hook * Minor test improvements * Add ERC1155Burnable and tests * Add ERC1155Pausable * Add ERC1155PresetMinterPauser.sol * Add uri constructors * Improved revert reasons * Initial docs improvements * Add missing docs * Improve acceptance checks revert reasons * Apply suggestions from code review Co-authored-by: Francisco Giordano <frangio.1@gmail.com> * Remove note about 1155 preset uri in mint * Add rquirements to balanceOfBatch * Add note about URI and uri * Fix list in docs * Fix lint errors * Use natural sorting for API titles * Fix doc references * Escape {id} references to remove docgen warnings * Added intro docs, fixed links * Apply suggestions from code review Co-authored-by: Francisco Giordano <frangio.1@gmail.com> * Add changelog entry Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
*** xref:erc20-supply.adoc[Creating Supply]
|
||||
** xref:erc721.adoc[ERC721]
|
||||
** xref:erc777.adoc[ERC777]
|
||||
** xref:erc1155.adoc[ERC1155]
|
||||
|
||||
* xref:gsn.adoc[Gas Station Network]
|
||||
** xref:gsn-strategies.adoc[Strategies]
|
||||
|
||||
21
docs/modules/ROOT/pages/erc1155.adoc
Normal file
21
docs/modules/ROOT/pages/erc1155.adoc
Normal file
@ -0,0 +1,21 @@
|
||||
= ERC1155
|
||||
|
||||
ERC1155 is a novel token standard that aims to take the best from previous standards to create a xref:tokens.adoc#different-kinds-of-tokens[*fungibility-agnostic*] and *gas-efficient* xref:tokens.adoc#but_first_coffee_a_primer_on_token_contracts[token contract].
|
||||
|
||||
TIP: ERC1155 draws ideas from all of xref:erc20.adoc[ERC20], xref:721.adoc[ERC721], and xref:erc777.adoc[ERC777]. If you're unfamiliar with those standards, head to their guides before moving on.
|
||||
|
||||
[[multi-token-standard]]
|
||||
== Multi Token Standard
|
||||
|
||||
The distinctive feature of ERC1155 is that it uses a single smart contract to represent multiple tokens at once. This is why its xref:api:token/ERC1155.adoc#IERC1155-balanceOf-address-uint256-[`balanceOf`] function differs from ERC20's and ERC777's: it has an additional `id` argument for the identifier of the token that you want to query the balance of.
|
||||
|
||||
This is similar to how ERC721 does things, but in that standard a token `id` has no concept of balance: each token is non-fungible and exists or doesn't. The xref:api:token/ERC721.adoc#IERC721-balanceOf-address-[`balanceOf`] function refers to _how many different tokens_ an account has, not how many of each. On the other hand, in ERC1155 accounts have a distinct balance for each token `id`, and non-fungible tokens are implemented by simply minting a single one of them.
|
||||
|
||||
This approach leads to massive gas savings for projects that require multiple tokens. Instead of deploying a new contract for each token type, a single ERC1155 token contract can hold the entire system state, reducing deployment costs and complexity.
|
||||
|
||||
[[batch-operations]]
|
||||
== Batch Operations
|
||||
|
||||
Because all state is held in a single contract, it is possible to operate over multiple tokens in a single transaction very efficiently. The standard provides two functions, xref:api:token/ERC1155.adoc#IERC1155-balanceOfBatch-address---uint256---[`balanceOfBatch`] and xref:api:token/ERC1155.adoc#IERC1155-safeBatchTransferFrom-address-address-uint256---uint256---bytes-[`safeBatchTransferFrom`], that make querying multiple balances and transferring multiple tokens simpler and less gas-intensive.
|
||||
|
||||
In the spirit of the standard, we've also included batch operations in the non-standard functions, such as xref:api:token/ERC1155.adoc#ERC1155-_mintBatch-address-uint256---uint256---bytes-[`_mintBatch`].
|
||||
@ -4,6 +4,7 @@ Ah, the "token": blockchain's most powerful and most misunderstood tool.
|
||||
|
||||
A token is a _representation of something in the blockchain_. This something can be money, time, services, shares in a company, a virtual pet, anything. By representing things as tokens, we can allow smart contracts to interact with them, exchange them, create or destroy them.
|
||||
|
||||
[[but_first_coffee_a_primer_on_token_contracts]]
|
||||
== But First, [strikethrough]#Coffee# a Primer on Token Contracts
|
||||
|
||||
Much of the confusion surrounding tokens comes from two concepts getting mixed up: _token contracts_ and the actual _tokens_.
|
||||
@ -28,3 +29,4 @@ You've probably heard of the ERC20 or ERC721 token standards, and that's why you
|
||||
* xref:erc20.adoc[ERC20]: the most widespread token standard for fungible assets, albeit somewhat limited by its simplicity.
|
||||
* xref:erc721.adoc[ERC721]: the de-facto solution for non-fungible tokens, often used for collectibles and games.
|
||||
* xref:erc777.adoc[ERC777]: a richer standard for fungible tokens, enabling new use cases and building on past learnings. Backwards compatible with ERC20.
|
||||
* xref:erc1155.adoc[ERC1155]: a novel standard for multi-tokens, allowing for a single contract to represent multiple fungible and non-fungible tokens, along with batched operations for increased gas efficiency.
|
||||
|
||||
Reference in New Issue
Block a user