当前位置:网站首页>Solid basic basic grammar and definition function
Solid basic basic grammar and definition function
2022-07-01 14:49:00 【new life1937】
Basic grammar
contract
Solidity The code is wrapped in the contract . A contract is the basic module of etheric Application , All variables and functions belong to a contract , It's the starting point for all your apps .
State variables and integers
State variables are permanently stored in the contract . In other words, they are written into the etheric blockchain . Imagine writing to a database .
uint The unsigned data type , Means that its value cannot be negative ,
int For data types where signed integers exist .
string String is used to hold any length of UTF-8 Encoding data
Mathematical operations
stay Solidity in , The mathematical operation is very intuitive , Same as other programming languages :
Add : x + y
Subtraction : x - y,
Multiplication : x * y
division : x / y
modulus / Seeking remainder : x % y ( for example , 13 % 5 more than 3, because 13 Divide 5, more than 3)
Solidity And support Power operation ( Such as :x Of y Power ) // for example : 5 ** 2 = 25
Structure - More complex data types , There are multiple attributes
struct Structs allow you to generate a more complex data type , It has multiple attributes .
struct Person {
uint age;
string name;
}
Array
Build a collection , It can be used Array _ This type of data . Solidity Two arrays are supported : static state Array and _ dynamic Array :
// The fixed length is 2 Static array of :
uint[2] fixedArray;
// The fixed length is 5 Of string Static array of type :
string[5] stringArray;
// The dynamic array , Length is not fixed , You can add elements dynamically :
uint[] dynamicArray;
An array of struct types , The state variables are permanently stored in the blockchain .
Person[] people; // This is a dynamic array , We can keep adding elements
Public array
You can define public Array , Solidity Automatically created getter Method . The grammar is as follows :
Person[] public people;
Other contracts can read data from this array ( But you can't write data ), So it's a useful model for holding public data in contracts .
Defined function
stay Solidity The syntax of the function definition in is as follows :
function eatHamburgers(string _name, uint _amount) {
}
This one is called eatHamburgers Function of , It takes two arguments : One string Type of and One uint Type of . Now the function is still empty .
Our function is defined as follows :
eatHamburgers("evelyn", 100);
边栏推荐
- 241. Design priorities for operational expressions
- Leetcode (69) -- square root of X
- 数字化转型:数据可视化赋能销售管理
- 从零开发小程序和公众号【第三期】
- MongoDB第二話 -- MongoDB高可用集群實現
- 生成随机数(4位、6位)
- Basic operation of database
- Summary of leetcode's dynamic programming 5
- Research Report on the development trend and competitive strategy of the global axis measurement system industry
- Pat 1065 a+b and C (64bit) (20 points) (16 points)
猜你喜欢

一波三折,终于找到src漏洞挖掘的方法了【建议收藏】

手把手带你入门 API 开发

【15. 区间合并】

对于编程思想和能力有重大提升的书有哪些?
![[14. Interval sum (discretization)]](/img/e5/8b29aca7068a6385e8ce90c2742c37.png)
[14. Interval sum (discretization)]

Semiconductor foundation of binary realization principle

JVM performance tuning and practical basic theory part II

如何看待国企纷纷卸载微软Office改用金山WPS?

Vnctf2022 open web gocalc0

MIT团队使用图神经网络,加速无定形聚合物电解质筛选,促进下一代锂电池技术开发
随机推荐
643. Maximum average number of subarrays I
tensorflow2-savedmodel convert to pb(frozen_graph)
Websocket (simple experience version)
Blog recommendation | in depth study of message segmentation in pulsar
C 语言基础
博文推荐 | 深入研究 Pulsar 中的消息分块
It's suitable for people who don't have eloquence. The benefits of joining the China Video partner program are really delicious. One video gets 3 benefits
Mongodb second talk - - mongodb High available Cluster Implementation
ArrayList 扩容详解,扩容原理[通俗易懂]
官宣:Apache Doris 顺利毕业,成为 ASF 顶级项目!
Research Report on development trend and competitive strategy of global vibration polishing machine industry
三十之前一定要明白的职场潜规则
111. Minimum depth of binary tree
Today, with the popularity of micro services, how does service mesh exist?
【14. 区间和(离散化)】
[零基础学IoT Pwn] 复现Netgear WNAP320 RCE
Research Report on the development trend and competitive strategy of the global indexable milling cutter industry
Basic operation of database
MIT team used graph neural network to accelerate the screening of amorphous polymer electrolytes and promote the development of next-generation lithium battery technology
Redis安装及Ubuntu 14.04下搭建ssdb主从环境