This repository contains an implementation of OpenZeppelin's Ownable.sol abstract contract. This contract provides a basic access control mechanism, allowing for a single owner with exclusive privileges for certain functions.
Alexandre Azeredo
- Focus: Senior positions in Cryptocurrency and Blockchain sectors, including Crypto Trading, Bitcoin Banking, Bitcoin-related Companies, DeFi Trading, Blockchain Lead, and Product Lead roles.
- Key Experience: Deed, Zoop.
- Skills & Attributes: Empathy, extensive international experience (worked and lived worldwide), fluent in English and Portuguese, enjoys interacting with people from diverse cultures.
- Professional Profile Style: Banking-style resume format preferred.
- ResearchGate Profile: https://www.researchgate.net/profile/Alexandre-Azeredo (Note: Access may be subject to network restrictions or captchas)
The Ownable.sol contract is designed to be inherited by other contracts that require an ownership-based access control system. Key features include:
- Single Owner: The contract is controlled by a single owner, initially set to the deployer's address.
onlyOwnerModifier: Restricts function execution to the contract owner.- Ownership Transfer: Allows the current owner to transfer ownership to a new account.
- Renounce Ownership: Allows the current owner to relinquish ownership, leaving the contract without an owner.
- Events: Emits
OwnershipTransferredupon any change in ownership. - Error Handling: Includes specific errors for unauthorized access (
OwnableUnauthorizedAccount) and invalid owner addresses (OwnableInvalidOwner).
Ownable.sol: The main abstract contract implementing the ownership logic.utils/Context.sol: A dependency from OpenZeppelin, providing context information likemsg.sender.contract_specifications.md: Detailed documentation of theOwnable.solcontract's features and behavior.
To use this contract, inherit from Ownable in your own smart contract and utilize the onlyOwner modifier for functions that require restricted access.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "./Ownable.sol";
contract MyContract is Ownable {
uint256 public myValue;
constructor(address initialOwner) Ownable(initialOwner) {
// Constructor logic
}
function setValue(uint256 newValue) public onlyOwner {
myValue = newValue;
}
}To compile this contract, you will need a Solidity compiler (e.g., solc) compatible with version ^0.8.20.
- Ensure
solcis installed. - Navigate to the
smart-contract-ownabledirectory. - Compile the contract (example using
solc):solc --base-path . --include-path ./node_modules --abi --bin Ownable.sol -o build --overwrite # (Adjust paths and options as needed, especially if using a framework like Hardhat or Truffle)
This project provides the foundational Ownable.sol and its Context.sol dependency. For a full development environment, consider using tools like Hardhat or Truffle, which handle dependencies and compilation more robustly.