0PricingLogin
Web3 & DApp Development Fundamentals · Lesson

Access Control

Ownable and Roles.

Why Access Control

Many contract functions should only be callable by certain accounts — minting tokens, pausing the system, withdrawing funds. Access control enforces who can do what.

OpenZeppelin offers two main patterns: Ownable and AccessControl.

The Ownable Pattern

Ownable gives a contract a single privileged owner. Import and inherit it:

import "@openzeppelin/contracts/access/Ownable.sol"; contract Vault is Ownable { constructor() Ownable(msg.sender) {} }

The deployer becomes the initial owner.

import "@openzeppelin/contracts/access/Ownable.sol";

contract Vault is Ownable {
    constructor() Ownable(msg.sender) {}
}

All lessons in this course

  1. Why OpenZeppelin
  2. Access Control
  3. Token Extensions
  4. Upgradeable Contracts
← Back to Web3 & DApp Development Fundamentals