Making your Smart Contracts Ownable

A good practice during Dapp development is to make your contracts ownable. This will allow you to add modifiers to prevent certain functions form being used. Be careful though, because this can remove the ‘decentralized’ aspects of the contract.

pragma solidity ^0.4.23;

contract Ownable {
  address public owner;

  constructor() public {
    owner = msg.sender;

  modifier onlyOwner() {
    require(msg.sender == owner);

contract Example is Ownable {
  function exampleFunction() public view onlyOwner {
    // code here

Now you only the account whoe deployed this contract can call exampleFunction. To see a better example and many more examples, check out OpenZepplin.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s