IERC1155.sol 4.6 KB

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