ERC1155Holder.sol 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v5.1.0) (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 ERC-1155 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. /// @inheritdoc IERC165
  14. function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
  15. return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
  16. }
  17. function onERC1155Received(
  18. address,
  19. address,
  20. uint256,
  21. uint256,
  22. bytes memory
  23. ) public virtual override returns (bytes4) {
  24. return this.onERC1155Received.selector;
  25. }
  26. function onERC1155BatchReceived(
  27. address,
  28. address,
  29. uint256[] memory,
  30. uint256[] memory,
  31. bytes memory
  32. ) public virtual override returns (bytes4) {
  33. return this.onERC1155BatchReceived.selector;
  34. }
  35. }