Selector
A Selector is a 32-bit unsigned integer (uint32) that identifies an underlying asset of an object. It is calculated from the function signatures of asset functions within a kind contract.
uint32::MIN (0) and uint32::MAX (2^32 - 1) are not considered valid selectors.
Calculation
The calculation process follows the same method used in Ethereum:
bytes4(keccak256(sig))
In this context, the function signatures (sig
) are determined differently: since asset functions do not have arguments, the signature is simply the function name without parentheses.
For example, given the following kind
contract:
@kind
class Hat {
// ...
meta(): Json {
// ...
}
picture(): Image {
// ...
}
}
The selectors are calculated as follows:
bytes4 selMeta = bytes4(keccak256("meta")); // 0x0144b03a
bytes4 selPicture = bytes4(keccak256("picture")); // 0xeb0568a6