solidityを勉強してると、実行を自分のオーナー(?)に限定にするためにこんな書き方をすることがあります。
require(msg.sender == owner)
このmsg.senderは自分で定義してるわけではないので、最初のうちは
どっからこれは来てるんだ???
と戸惑います。
調べてみるとわかりました。
グローバルネームスペースですでに定義されてるやつだったんですね。
同じような質問がstackoverflowにありました。
stackoverflow.com
solidityのドキュメントに書いてあります。ほかにもいろいろありますね。
Units and Globally Available Variables — Solidity 0.4.26 documentation
Block and Transaction Properties
- block.blockhash(uint blockNumber) returns (bytes32): hash of the given block - only works for 256 most recent, excluding current, blocks - deprecated in version 0.4.22 and replaced by blockhash(uint blockNumber).
- block.coinbase (address payable): current block miner’s address
- block.difficulty (uint): current block difficulty
- block.gaslimit (uint): current block gaslimit
- block.number (uint): current block number
- block.timestamp (uint): current block timestamp as seconds since unix epoch
- gasleft() returns (uint256): remaining gas
- msg.data (bytes): complete calldata
- msg.gas (uint): remaining gas - deprecated in version 0.4.21 and to be replaced by gasleft()
- msg.sender (address payable): sender of the message (current call)
- msg.sig (bytes4): first four bytes of the calldata (i.e. function identifier)
- msg.value (uint): number of wei sent with the message
- now (uint): current block timestamp (alias for block.timestamp)
- tx.gasprice (uint): gas price of the transaction
- tx.origin (address payable): sender of the transaction (full call chain)