ERC1155Holder.sol 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. * @custom:stateless
  13. */
  14. abstract contract ERC1155Holder is ERC165, IERC1155Receiver {
  15. /**
  16. * @dev See {IERC165-supportsInterface}.
  17. */
  18. function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
  19. return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
  20. }
  21. function onERC1155Received(
  22. address,
  23. address,
  24. uint256,
  25. uint256,
  26. bytes memory
  27. ) public virtual override returns (bytes4) {
  28. return this.onERC1155Received.selector;
  29. }
  30. function onERC1155BatchReceived(
  31. address,
  32. address,
  33. uint256[] memory,
  34. uint256[] memory,
  35. bytes memory
  36. ) public virtual override returns (bytes4) {
  37. return this.onERC1155BatchReceived.selector;
  38. }
  39. }