ERC1155Holder.sol 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v5.0.0-rc.1) (token/ERC1155/utils/ERC1155Holder.sol)
  3. pragma solidity ^0.8.20;
  4. import {IERC165, ERC165} from "../../../utils/introspection/ERC165.sol";
  5. import {IERC1155Receiver} from "../IERC1155Receiver.sol";
  6. /**
  7. * @dev Simple implementation of `IERC1155Receiver` that will allow a contract to hold ERC1155 tokens.
  8. *
  9. * IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be
  10. * stuck.
  11. */
  12. abstract contract ERC1155Holder is ERC165, IERC1155Receiver {
  13. /**
  14. * @dev See {IERC165-supportsInterface}.
  15. */
  16. function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
  17. return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
  18. }
  19. function onERC1155Received(
  20. address,
  21. address,
  22. uint256,
  23. uint256,
  24. bytes memory
  25. ) public virtual override returns (bytes4) {
  26. return this.onERC1155Received.selector;
  27. }
  28. function onERC1155BatchReceived(
  29. address,
  30. address,
  31. uint256[] memory,
  32. uint256[] memory,
  33. bytes memory
  34. ) public virtual override returns (bytes4) {
  35. return this.onERC1155BatchReceived.selector;
  36. }
  37. }