Skip to main content

compute_discriminator

Function compute_discriminator 

Source
pub fn compute_discriminator(namespace: &str, name: &str) -> [u8; 8]
Expand description

Compute an Anchor-compatible discriminator for a given namespace and name.

The discriminator is the first 8 bytes of SHA256(“namespace:name”). This is used to uniquely identify instructions and accounts in Anchor programs.

§Arguments

  • namespace - The namespace (e.g., “global” for instructions, “account” for accounts)
  • name - The name in snake_case for instructions or PascalCase for accounts

§Returns

An 8-byte array containing the discriminator