当前位置:网站首页>Solidity: contract structure
Solidity: contract structure
2022-04-22 16:10:00 【XDP_ CS】
Solidity: Contract structure
Contracts are similar to classes in oriented programming languages . Each contract can contain state variables 、 function 、 Function modifiers 、 event 、 Declaration of structure type and enumeration type .
There are also some special contracts, such as : Libraries and interfaces
State variables
State variables are values that are permanently stored in the contract store
function
A function is an executable unit of code in a contract . Functions are usually defined inside contracts , But it can also be defined outside the contract
Function modifiers
Function modifiers can be used to improve function semantics declaratively
event
Events are convenient to call Ethereum virtual machine (EVM) Interface of log function
Structure
A structure is a custom type that can group several variables
Enumeration type
Enumeration types can be used to create a list of “ Constant values ” The custom types that make up the
Summary application code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Demo {
uint data; // State variables
event deal(address seller, uint amount);// event
struct People {// Structure type
uint height;
uint age;
uint weight;
}
enum State{alive, die} // Enumeration type
modifier onlyMe(address seller){
require(msg.sender == seller);
_;
}
function transfer() public payable onlyMe(msg.sender) {// Function and added modifiers
emit deal(msg.sender, msg.value);
}
}
function hello(){// External function
}
版权声明
本文为[XDP_ CS]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221607075390.html
边栏推荐
- 【经验分享】为什么视频画面解码失败之后显示的是绿幕?
- 【操作教程】国标GB28181平台EasyGBS如何开启语音对讲功能?
- 342-Leetcode 字符串中的第一个唯一字符
- 【鲲鹏训练营】重庆2022开发者大赛
- Suppose a binary tree is represented by a binary list (that is, the two pointers of the node indicate the left and right subtrees respectively). When the binary tree contains k nodes, there must be ()
- ICMP and IPv6 global unicast address dynamic allocation
- Immundiagnostik IDK TurbiPEL测定分析
- Introduce file path problem-$_ Server ['document_root'] represents the root directory of the website
- 引入文件路径问题-$_SERVER[‘DOCUMENT_ROOT‘]代表网站根目录
- 阿里云国际版设置电子邮件托管教程详解
猜你喜欢

It's too voluminous ~ (2022 version) large factory face experience + detailed notes to help you finish the interview

2022-4-21 【webrtc应用】yangrtc/metaRTC开源库源码分析(三)

Altium designer 生成PCB制作文件及打样流程(以嘉立创商城为例)

串口数据绘图SerialPlot的使用

想做自媒体运营却不会写作?4个珍藏的运营技巧

阿里云国际版设置电子邮件托管教程详解

Performance evaluation of rust asynchronous framework

自动化测试

Redis cache hit rate

Servlet基础
随机推荐
selenium之预期条件判断方法
【acwing】1135. 新年好***(dijkstra+堆优化)
Talk about data subcontracting and related tips
Typescripts Promise
zTree的使用
网站优化后如何降低阿里云国际版服务器成本
MySQL operator explanation and regular expression query
【无标题】下单及支付
7寸触摸屏屏幕校准参数设置
Redis simple storage folder
远程桌面失败解决办法
Hash table (II)
引用拷贝,深拷贝,浅拷贝
Reference copy, deep copy, shallow copy
2022-4-21 【webrtc应用】yangrtc/metaRTC开源库源码分析(三)
谈谈数据分包以及相关小技巧
使用EasyGBS后更换为EasyCVR,更改端口为10000,报错404是什么原因?
Small pit on the definition of two-dimensional or multi-dimensional array / slice in go language
这个API Hub厉害了,收录了钉钉企业微信等开放Api,还能直接调试 !
太卷了~(2022版)大厂面经 + 详细笔记帮你搞定面试