bytes4 is a commonly needed data type in Solidity, due to its use in
msg.sig and, more broadly speaking, in function selectors (e.g.
How can one convert
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
abi.encodeWithSelector can be used for this:
bytes memory a = abi.encodeWithSelector(msg.sig); bytes memory b = abi.encodeWithSelector(Contract.func.selector);