智能合约源文件的基本要素
2017-08-28 13:06
190 查看
合约类似面向对象语言中的类。
合约支持继承
智能合约的基本要素:状态变量(State Variables)、函数(Functions)、函数修饰符(Function Modifiers)、事件(Events)、结构类型(Structs Types)、枚举类型(Enum Types)。
1、状态变量(State Variables)
变量值会永久存储在合约的存储空间
2、函数(Functions)
智能合约中的一个可执行单元
3、函数修饰符(Function Modifiers)
函数修饰符用于增强语义
4、事件(Events)
事件是以太坊虚拟机(EVM)日志基础设施提供的一个便利接口,用于获取当前发生的事件。
自定义的将几个变量组合在一起形成的类型
特殊的自定义类型,类型的所有值可枚举的情况
这些就是智能合约的基本要素,写的粗略了些,以后研究了这些基本要素之后,会再补充的。
合约支持继承
智能合约的基本要素:状态变量(State Variables)、函数(Functions)、函数修饰符(Function Modifiers)、事件(Events)、结构类型(Structs Types)、枚举类型(Enum Types)。
1、状态变量(State Variables)
变量值会永久存储在合约的存储空间
pragma solidity ^0.4.0; // simple store example contract simpleStorage{ uint valueStore; //state variable }
2、函数(Functions)
智能合约中的一个可执行单元
pragma solidity ^0.4.0; contract simpleMath{ //Simple add function,try a divide action? function add(uint x, uint y) returns (uint z){ z = x + y; } }上述示例展示了一个简单的加法函数
3、函数修饰符(Function Modifiers)
函数修饰符用于增强语义
4、事件(Events)
事件是以太坊虚拟机(EVM)日志基础设施提供的一个便利接口,用于获取当前发生的事件。
pragma solidity ^0.4.0; contract SimpleAuction { event aNewHigherBid(address bidder, uint amount); function bid(uint bidValue) external { aNewHigherBid(msg.sender, msg.value); } }5、结构类型(Structs Types)
自定义的将几个变量组合在一起形成的类型
pragma solidity ^0.4.0; contract Company { //user defined `Employee` struct type //group with serveral variables struct employee{ string name; uint age; uint salary; } //User defined `manager` struct type //group with serveral variables struct manager{ employee employ; string title; } }6、枚举类型(Enum Types)
特殊的自定义类型,类型的所有值可枚举的情况
pragma solidity ^0.4.0; contract Home { enum Switch{On,Off} }
这些就是智能合约的基本要素,写的粗略了些,以后研究了这些基本要素之后,会再补充的。
相关文章推荐
- 区块链-4:区块链的基本类型和智能合约
- 智能应用的基本要素
- 智能应用的基本要素
- 智能应用的基本要素
- Hyperledger Fabric 链码(智能合约)基本操作
- PL/SQL基本语法要素
- linux下用vim编写C/C++工程(多个源文件)的基本方法
- Android App基本要素(一)
- 代码优化的基本要素
- Truffle 4.0、Geth 1.7.2、TestRPC在私有链上搭建智能合约
- 以太坊预言机与智能合约开发
- 谈谈项目管理中必须注意的基本要素
- 智能合约调用另一合约中的payable方法
- 软件测试管理的基本要素
- 【区块链】Truffle 部署 编译 测试 智能合约 的 完整实践操作
- 敏捷开发基本要素
- NEO智能合约开发(二)再续不可能的任务
- 响应式WEB设计 - 基本技术要素
- 防火墙配置十大任务之四,有NAT要素的两个接口的基本配置
- 区块链2.0(三):智能合约应用案列及相关法律问题