IERC1155.sol 3.9 KB

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