ethereum(以太坊)(九)--global(全局函数)
pragma solidity ^0.4.0;
contract modifierTest{
bytes32 public blockhash;
address public coinbase;
uint public difficulty;
uint public gaslimit;
uint public blockNum;
uint public timestamp;
bytes public calldata1;
uint public gas;
address public sender;
bytes4 public sig;
uint public msgValue;
uint public now1;
uint public gasPrice;
address public txOrigin;
function tt(){
//给定区块号的哈希值,只支持最近256个区块,且不包含当前区块
blockhash = block.blockhash(block.number -1);
coinbase = block.coinbase;//当前块矿工的地址
difficulty = block.difficulty;//当前块的难度
gaslimit = block.gaslimit;//当前块的gaslimit
blockNum = block.number; //当前区块的块号
timestamp = block.timestamp;//当前块的时间戳==now
calldata1 = msg.data;//完整的调用数据: 0x1e36169e
gas = msg.gas;//当前还剩下的gas
sender = msg.sender;//当前调用发起人的地址: 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c
sig = msg.sig;//调用数据的前4个字节(函数标识符): 0x1e36169e
msgValue = msg.value;//这个消息所携带的货币量,单位wei
now1 = now;
gasPrice = tx.gasprice;//交易的gas价格
txOrigin = tx.origin;//交易的发送者(完整的调用链): 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c
}
}
直接调用,后面无需()
abi.encode(...) returns (bytes):对给定的参数进行ABI编码。abi.encodePacked(...) returns (bytes): Performes packed encoding of the given argumentsabi.encodeWithSelector(bytes4 selector, ...) returns (bytes)::对给定的参数进行ABI编码——从第二个预置给定的四字节选择器开始abi.encodeWithSignature(string signature, ...) returns (bytes):相当于abi.encodeWithSelector(bytes4(keccak256(signature), ...)block.blockhash(uint blockNumber) returns (bytes32): 给定的块的hash值, 只有最近工作的256个块的hash值—— 在 0.4.22 后请使用blockhash(uint blockNumber).block.coinbase(address): 当前块的矿工的地址block.difficulty(uint): 当前块的难度block.gaslimit(uint): 当前块的gaslimitblock.number(uint):当前块的数量block.timestamp(uint):当前块的时间戳gasleft() returns (uint256): 剩余 gasmsg.data(bytes): 完整的calldatamsg.gas(uint): 剩余 gas - 0.4.21后请使用gasleft()msg.sender(address): 消息的发送者(当前调用)msg.value(uint): 和消息一起发送的wei的数量now(uint): 当前块的时间戳(block.timestamp的别名)tx.gasprice(uint):交易的gas价格tx.origin(address):交易的发送者(全调用链)assert(bool condition): abort execution and revert state changes if condition isfalse(用于内部错误)require(bool condition): abort execution and revert state changes if condition isfalse(用于输入错误或外部组件的错误)require(bool condition, string message): abort execution and revert state changes if condition isfalse(用于输入错误或外部组件的错误). 并提供错误信息.revert(): 中止执行并还原状态更改revert(string message):中止执行并还原状态更改,提供解释字符串blockhash(uint blockNumber) returns (bytes32): : 给定的块的hash值, 只有最近工作的256个块的hash值keccak256(...) returns (bytes32):计算(紧凑排列的)参数的 Ethereum-SHA3 hash值sha3(...) returns (bytes32): an alias tokeccak256sha256(...) returns (bytes32): 计算(紧凑排列的)参数的SHA256 hash值ripemd160(...) returns (bytes20):计算 256个(紧凑排列的)参数的RIPEMDecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address): 椭圆曲线签名公钥恢复,错误时返回0addmod(uint x, uint y, uint k) returns (uint): compute(x + y) % kwhere the addition is performed with arbitrary precision and does not wrap around at2**256. Assert thatk != 0starting from version 0.5.0.mulmod(uint x, uint y, uint k) returns (uint): compute(x * y) % kwhere the multiplication is performed with arbitrary precision and does not wrap around at2**256. Assert thatk != 0starting from version 0.5.0.this(current contract’s type): 当前合约,在地址上显式转换super: 在层次关系上一层的合约selfdestruct(address recipient): 销毁当前的合约,将其资金发送到指定addresssuicide(address recipient): a deprecated alias toselfdestruct<address>.balance(uint256): address地址中的账户余额(以wei为单位)<address>.send(uint256 amount) returns (bool): 将一定量wei发送给address地址,若失败返回false。<address>.transfer(uint256 amount): 将一定量wei发送给address地址,若失败抛出异常。
ethereum(以太坊)(九)--global(全局函数)的更多相关文章
- ethereum(以太坊)(一)
从这周开始,开始学习以太坊开发--solidity,开始决定往区块链方向发展,毕竟区块链技术应用广泛.一开始接触solidity开发语言不太习惯,毕竟一直在学习python语法,有很多都不能接受.有难 ...
- ethereum(以太坊)(十)--函数修饰符
pragma solidity ^0.4.0; contract modifierTest{ uint public v1; uint constant v2 =10; //uint constant ...
- ethereum(以太坊)(实例)--"安全的远程购买"
pragma solidity ^0.4.10; contract Safebuy{ uint public price; address public seller; address public ...
- ethereum(以太坊)(十一)--字节数组(二)
pragma solidity ^0.4.0; contract test { uint [5] T =[1,2,3,4,5] ;//固定长度的数组:可修改数组内值大小,不支持push,不可更改长度 ...
- ethereum(以太坊)(实例)--"简单的公开竞拍"
说真的,刚开始接触这个竞拍案例--“简单的公开竞拍”,我就抱着简单的心态去查看这个实例,但是自我感觉并不简单.应该是我实力不到家的原因吧!!!233333...不过经过大半天的努力,自己理解完之后,觉 ...
- ethereum(以太坊)(基础)--容易忽略的坑(一)
pragma solidity ^0.4.0; contract base{ address public _owner=msg.sender; uint _a; string internal _b ...
- ethereum(以太坊)(七)--枚举/映射/构造函数/修改器
pragma solidity ^0.4.10; //枚举类型 contract enumTest{ enum ActionChoices{Left,Right,Straight,Still} // ...
- ethereum(以太坊)(四)--值传递与引用传递
contract Person { string public _name; function Person() { _name = "liyuechun"; } function ...
- ethereum(以太坊)(三)--合约单继承与多继承
pragma solidity ^0.4.0; // priveta public internal contract Test{ //defualt internal uint8 internal ...
随机推荐
- jquery validation yyyy-MM-dd格式日期在ie中无法验证通过
自己开发的公众号,可以领取淘宝内部优惠券 问题 首先在ie6.7.8下面打开这个页面http://jqueryvalidation.org/date-method/,输入的日期格式为:yyyy-MM- ...
- 二维码项目实例为二维码添加logo
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Tiled 地图编辑器使用教程-官方demo
一.Tiled Map Editer 下载地址 http://www.mapeditor.org/download.html 二.官方教程查看 下载安装后,不管windows还是Mac系统都包含官方例 ...
- 利用自定义特性实现List的多属性排序
知道linq有order by的功能,但是还是动手研究了一下,算是多实践实践反射.这篇算是笔记,直接上代码: using System; using System.Collections.Concur ...
- Android GreenDao清空数据库的方法
最近在做项目的时候,为了方便测试人员测试,在应用中加入正式库和测试库切换的功能.为了防止正式库和测试库切换带来的数据冲突,切换的时候必须把当前的数据库清空.代码如下: package com.exam ...
- VirtualBox中linux虚拟机和主机间的共享文件设置
设置共享文件路径 点击虚拟机 设置-->选择 共享文件夹 (图1 设置共享文件夹) 设置共享文件夹路径 1 选择路径 2 填写自定义的共享名称(在后面需要与挂载路径相对应) 3 设置自动挂载/固 ...
- 如何在windows下安装配置pyspark notebook
第一步:安装anaconda anaconda自带一系列科学计算包 下载链接:http://pan.baidu.com/s/1b4jWlg 密码:fqq3 接着配置环境变量:如我安装在D盘下 试一 ...
- 笨办法学Python(二十)
习题 20: 函数和文件 回忆一下函数的要点,然后一边做这节练习,一边注意一下函数和文件是如何在一起协作发挥作用的. from sys import argv script, input_file = ...
- 关于定义顺序和内存分配的关系--记一道不严谨的C语言题
include<stdio.h> #include<iostream> int main() { char a[] = "123"; char b[] = ...
- JS回调函数(理解篇)
概述: 回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用来调用其所指向的函数时,我们就说这是回调函数.回调函数不是由该函数的实现方直接调用,而 ...