Lesson 3 Chapter3 onlyOwner 関数修飾子
onlyOwner関数修飾子 定義
require(msg.sender == owner);
_;
}
onlyOwner関数修飾子使用方法
contract MyContract is Ownable {
event LaughManiacally(string laughter);
//`onlyOwner`の使い方
LaughManiacally("Muahahahaha");
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
prev
-
クリプトゾンビ Lesson 3 Chapter2 OpenZeppelinの Ownable コントラクト
OpenZeppelinの Ownable コントラクト OpenZeppelinは、分散型アプリケーションを構築、自動化、および運用するためのセキュリティ製品。 (出典 :https://openz ...
next
-
クリプトゾンビ Lesson 3 Chapter4-1 Ethereum ガス(燃料)
Lesson 3 Chapter4 Ethereum ガス(燃料) Ethereum network上でトランザクションやプログラムを実行するのに必要な手数料のこと。 該当トランザクションを処理する ...