Skip to content

Instantly share code, notes, and snippets.

@nxt3d
Created March 29, 2023 01:36
Show Gist options
  • Save nxt3d/2204a119ff35404edc34e25b245f5672 to your computer and use it in GitHub Desktop.
Save nxt3d/2204a119ff35404edc34e25b245f5672 to your computer and use it in GitHub Desktop.
Generate a function selector. (can be cut and pasted into Remix)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract FunctionSelector {
/*
"transfer(address,uint256)"
0xa9059cbb
"transferFrom(address,address,uint256)"
0x23b872dd
*/
function getSelector(string calldata _func) external pure returns (bytes4) {
return bytes4(keccak256(bytes(_func)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment