IERC1155.sol 3.7 KB

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