erc6909.adoc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. = ERC-6909
  2. ERC-6909 is a draft EIP that draws on ERC-1155 learnings since it was published in 2018. The main goals of ERC-6909 is to decrease gas costs and complexity--this is mainly accomplished by removing batching and callbacks.
  3. TIP: To understand the inspiration for a multi token standard, see the xref:erc1155.adoc#multi-token-standard[multi token standard] section within the EIP-1155 docs.
  4. == Changes from ERC-1155
  5. There are three main changes from ERC-1155 which are as follows:
  6. . The removal of batch operations.
  7. . The removal of transfer callbacks.
  8. . Granularization in approvals--approvals can be set globally (as operators) or as amounts per token (inspired by ERC20).
  9. == Constructing an ERC-6909 Token Contract
  10. We'll use ERC-6909 to track multiple items in a game, each having their own unique attributes. All item types will by minted to the deployer of the contract, which we can later transfer to players. We'll also use the xref:api:token/ERC6909.adoc#ERC6909Metadata[`ERC6909Metadata`] extension to add decimals to our fungible items (the vanilla ERC-6909 implementation does not have decimals).
  11. For simplicity, we will mint all items in the constructor--however, minting functionality could be added to the contract to mint on demand to players.
  12. TIP: For an overview of minting mechanisms, check out xref:erc20-supply.adoc[Creating ERC-20 Supply].
  13. Here's what a contract for tokenized items might look like:
  14. [source,solidity]
  15. ----
  16. include::api:example$token/ERC6909/ERC6909GameItems.sol[]
  17. ----
  18. Note that there is no content URI functionality in the base implementation, but the xref:api:token/ERC6909.adoc#ERC6909ContentURI[`ERC6909ContentURI`] extension adds it. Additionally, the base implementation does not track total supplies, but the xref:api:token/ERC6909.adoc#ERC6909TokenSupply[`ERC6909TokenSupply`] extension tracks the total supply of each token id.
  19. Once the contract is deployed, we will be able to query the deployer’s balance:
  20. [source,javascript]
  21. ----
  22. > gameItems.balanceOf(deployerAddress, 3)
  23. 1000000000
  24. ----
  25. We can transfer items to player accounts:
  26. [source,javascript]
  27. ----
  28. > gameItems.transfer(playerAddress, 2, 1)
  29. > gameItems.balanceOf(playerAddress, 2)
  30. 1
  31. > gameItems.balanceOf(deployerAddress, 2)
  32. 0
  33. ----