I'm trying to pass bytes4 type to mapping but all I have got is an error saying:
**ParserError: Expected identifier but got '='**
bytes4 example = 0x11030330;
mapping(bytes4 => address) facets;
facets[example] = 0xaE036c65C649172b43ef7156b009c6221B596B8b;

1 Answer 1


This is an example how to do it:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Bytes4InMapping {
    mapping(bytes4 => address) public facets;

    function addValueInsideMapping(bytes4 _key) public {
        facets[_key] = msg.sender;
  • Thank you very much!
    – obsessed
    Jan 14 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.