Anchor for EVM Developers
  • Anchor for EVM Developers
  • Program Address
  • Functions
  • Token
  • Validation
  • Mutation
  • Calling Other Contract
  • Wrap Native Token
  • Transfer Native Token
  • Transfer Fungible Token
  • Deploy A Fungible Token
  • Access Control
  • Address Mining
  • Events
  • Forking Mainnet
  • Function Selector
  • Feature Flags
  • Feature Dependencies
  • Migration / Scripts
  • Upgrade Programs
  • Block timestamp
Powered by GitBook
On this page

Access Control

EVM

contract Contract is AccessControl {
  bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
  
  function doSomething() onlyRole(OPERATOR_ROLE) {
  }
}

Solana

#[account]
pub struct AccessControl {
    #[max_len(100)]
    pub operators: Vec<Pubkey>,
}

#[error_code]
pub enum ErrorCode {
    #[msg("Unauthorized")]
    Unauthorized,
}

#[derive(Accounts)]
pub struct DoSomething<'info> {
    #[account(mut, constraint = access_control.operators.contains(&operator.key()) @ ErrorCode::Unauthorized)]
    pub operator: Signer<'info>,
    
    pub access_control: Account<'info, AccessControl>,
}

pub fn do_something(ctx: Context<DoSomething>) -> Result<()> {
  Ok(())
}

PreviousDeploy A Fungible TokenNextAddress Mining

Last updated 2 months ago