温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

solidity智能合约[24]-global

发布时间:2020-04-10 01:53:02 来源:网络 阅读:190 作者:jonson_jackson 栏目:开发技术

solidity中的全局属性

block.blockhash(uint blockNumber) returns (bytes32):返回给定区块号的哈
希值,只支持最近256个区块,且不包含当前区块。在版本0.4.22中弃用并被替换为。blockhash(uint blockNumber)
block.coinbase (address): 当前块矿工的地址。
block.difficulty (uint):当前块的难度。
block.gaslimit (uint):当前块的gaslimit。
block.number (uint):当前区块的块号。
block.timestamp (uint): 当前块的Unix时间戳(从1970/1/1 00:00:00 UTC开始所经过的秒数)
msg.data (bytes): 完整的调用数据(calldata)。
msg.sender (address): 当前调用发起人的地址。
msg.sig (bytes4):调用数据(calldata)的前四个字节(例如为:函数标识符)。
msg.value (uint): 这个消息所附带的以太币,单位为wei。
now (uint): 当前块的时间戳(block.timestamp的别名)
tx.gasprice (uint) : 交易的gas价格。
tx.origin (address): 交易的发送者(全调用链)

案例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
pragma solidity ^0.4.23;

contract global{
   function  getGlobal1() public view returns(address){
       return msg.sender ;
   }

      function  getGlobal2() public view returns(uint){
       return block.difficulty;
   }
    function  getGlobal3() public view returns(uint){
       return block.number;
   }

    function  getGlobal4() public view returns(address){
       return block.coinbase;
   }

    function  getGlobal5() public pure returns(bytes){
       return msg.data;
   }

    function  getGlobal6() public payable returns(uint ){
       return msg.value ;
   }

     function  getGlobal7() public view  returns(address ){
       return tx.origin;
   }

    function  getGlobal8() public view returns(uint ){
       return now;
   }

     function  getGlobal9() public view returns(bytes32 ){
       return blockhash(block.number-1);
   }
}

参考资料:
https://solidity.readthedocs.io/en/develop/units-and-global-variables.html

  • 本文链接: https://dreamerjonson.com/2018/11/20/solidity-24-global/

  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY 4.0 CN协议 许可协议。转载请注明出处!

solidity智能合约[24]-global

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI