Simple Smart Contract with Owner Restriction

A foundational Solidity contract demonstrating access control via the `onlyOwner` modifier, allowing only the deployer to modify a stored variable.

Thumbnail proyek Simple Smart Contract with Owner Restriction

Project Summary

This project serves as an essential exercise in Solidity, focusing on core concepts. It initializes a contract owner upon deployment and uses a custom `onlyOwner` modifier to secure the `setAngka` function, ensuring that sensitive state modifications are restricted. It also includes a basic `pure` function (`addNum`) for calculation practice.

My Role

Solidity Learner & Implementer: Focused on writing clean, secure code demonstrating mastery of modifiers and basic state management in Solidity.

Challenges

The core challenge was securely implementing the access restriction logic to protect the `angka` state variable, ensuring only the original deployer could execute the critical `setAngka` function.

Solution & Implementation

Implemented the `onlyOwner` modifier which utilizes `require(msg.sender == owner, ...)` to revert transactions from unauthorized addresses, standardizing access control, and improving code readability.

Main Features

  • Owner-Controlled State Variable
  • Custom `onlyOwner` Modifier
  • Basic Pure Function (`addNum`)
  • Secure Access Restriction

Technology

SoliditySmart ContractAccess ControlEVMRemix

Gallery