当前位置:网站首页>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);
边栏推荐
- Research Report on the development trend and competitive strategy of the global axis measurement system industry
- [dynamic programming] p1004 grid access (four-dimensional DP template question)
- Research Report on the development trend and competitive strategy of the global CCTV robot industry
- 户外LED显示屏应该考虑哪些问题?
- 音乐播放器开发实例(可毕设)
- Today, with the popularity of micro services, how does service mesh exist?
- 如何看待国企纷纷卸载微软Office改用金山WPS?
- What are the books that have greatly improved the thinking and ability of programming?
- [Verilog quick start of Niuke series] ~ multi function data processor, calculate the difference between two numbers, use generate... For statement to simplify the code, and use sub modules to realize
- MongoDB第二话 -- MongoDB高可用集群实现
猜你喜欢
随机推荐
sqlilabs less13
写在Doris毕业后的第一天
DirectX修复工具V4.1公测![通俗易懂]
MIT team used graph neural network to accelerate the screening of amorphous polymer electrolytes and promote the development of next-generation lithium battery technology
Mongodb second talk - - mongodb High available Cluster Implementation
One of the data Lake series | you must love to read the history of minimalist data platforms, from data warehouse, data lake to Lake warehouse
【牛客网刷题系列 之 Verilog快速入门】~ 使用函数实现数据大小端转换
Research Report on development trend and competitive strategy of global consumer glassware industry
Music player development example (can be set up)
[15. Interval consolidation]
Salesforce、约翰霍普金斯、哥大 | ProGen2: 探索蛋白语言模型的边界
职场太老实,总被欺负怎么办?
C learning notes (5) class and inheritance
[zero basic IOT pwn] reproduce Netgear wnap320 rce
Research Report on the development trend and competitive strategy of the global CCTV robot industry
【14. 区间和(离散化)】
Sqlachemy common operations
[leetcode 324] swing sorting II thinking + sorting
2022-2-15 learning the imitation Niuke project - Section 3 post details
Problem note - Oracle 11g uninstall









