Skip to main content

selector

Function selector 

Source
pub fn selector(calldata: &[u8]) -> Result<[u8; 4]>
Expand description

Extracts the 4-byte function selector from calldata.

The selector is expected to be the first 4 bytes of the calldata. Returns an error if calldata is shorter than 4 bytes.

§Arguments

  • calldata - Raw calldata bytes (selector + arguments)

§Returns

  • Ok([u8; 4]) - The extracted selector
  • Err(Error) - If calldata is too short

§Example

let calldata = context::calldata()?;
let selector = abi::selector(&calldata)?;

if selector == abi::selector_of("transfer") {
    // Handle transfer function
}