IERC1155.sol 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../../utils/introspection/IERC165.sol";
  4. /**
  5. * @dev Required interface of an ERC1155 compliant contract, as defined in the
  6. * https://eips.ethereum.org/EIPS/eip-1155[EIP].
  7. *
  8. * _Available since v3.1._
  9. */
  10. interface IERC1155 is IERC165 {
  11. /**
  12. * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
  13. */
  14. event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
  15. /**
  16. * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
  17. * transfers.
  18. */
  19. event TransferBatch(
  20. address indexed operator,
  21. address indexed from,
  22. address indexed to,
  23. uint256[] ids,
  24. uint256[] values
  25. );
  26. /**
  27. * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
  28. * `approved`.
  29. */
  30. event ApprovalForAll(address indexed account, address indexed operator, bool approved);
  31. /**
  32. * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
  33. *
  34. * If an {URI} event was emitted for `id`, the standard
  35. * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
  36. * returned by {IERC1155MetadataURI-uri}.
  37. */
  38. event URI(string value, uint256 indexed id);
  39. /**
  40. * @dev Returns the amount of tokens of token type `id` owned by `account`.
  41. *
  42. * Requirements:
  43. *
  44. * - `account` cannot be the zero address.
  45. */
  46. function balanceOf(address account, uint256 id) external view returns (uint256);
  47. /**
  48. * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
  49. *
  50. * Requirements:
  51. *
  52. * - `accounts` and `ids` must have the same length.
  53. */
  54. function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
  55. external
  56. view
  57. returns (uint256[] memory);
  58. /**
  59. * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
  60. *
  61. * Emits an {ApprovalForAll} event.
  62. *
  63. * Requirements:
  64. *
  65. * - `operator` cannot be the caller.
  66. */
  67. function setApprovalForAll(address operator, bool approved) external;
  68. /**
  69. * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
  70. *
  71. * See {setApprovalForAll}.
  72. */
  73. function isApprovedForAll(address account, address operator) external view returns (bool);
  74. /**
  75. * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
  76. *
  77. * Emits a {TransferSingle} event.
  78. *
  79. * Requirements:
  80. *
  81. * - `to` cannot be the zero address.
  82. * - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}.
  83. * - `from` must have a balance of tokens of type `id` of at least `amount`.
  84. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
  85. * acceptance magic value.
  86. */
  87. function safeTransferFrom(
  88. address from,
  89. address to,
  90. uint256 id,
  91. uint256 amount,
  92. bytes calldata data
  93. ) external;
  94. /**
  95. * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
  96. *
  97. * Emits a {TransferBatch} event.
  98. *
  99. * Requirements:
  100. *
  101. * - `ids` and `amounts` must have the same length.
  102. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
  103. * acceptance magic value.
  104. */
  105. function safeBatchTransferFrom(
  106. address from,
  107. address to,
  108. uint256[] calldata ids,
  109. uint256[] calldata amounts,
  110. bytes calldata data
  111. ) external;
  112. }