当前位置:网站首页>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 aviation leasing service industry
- Guess lantern riddles, not programmers still can't understand?
- Research Report on development trend and competitive strategy of global vibration polishing machine industry
- Provincial election + noi Part 10 probability statistics and polynomials
- JVM第一话 -- JVM入门详解以及运行时数据区分析
- En utilisant le paquet npoi de net Core 6 c #, lisez Excel.. Image dans la cellule xlsx et stockée sur le serveur spécifié
- 互联网医院系统源码 医院小程序源码 智慧医院源码 在线问诊系统源码
- tensorflow2-savedmodel convert to pb(frozen_graph)
- Pat 1121 damn single (25 points) set
- solidty-基础篇-基础语法和定义函数
猜你喜欢
JVM第一话 -- JVM入门详解以及运行时数据区分析
Websocket (simple experience version)
One of the first steps to redis
[14. Interval sum (discretization)]
[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
一波三折,终于找到src漏洞挖掘的方法了【建议收藏】
sqlilabs less-11~12
Microservice development steps (Nacos)
sqlilabs less9
Salesforce、约翰霍普金斯、哥大 | ProGen2: 探索蛋白语言模型的边界
随机推荐
Problem note - Oracle 11g uninstall
Research Report on the development trend and competitive strategy of the global navigation simulator industry
MongoDB第二話 -- MongoDB高可用集群實現
【15. 区间合并】
生成随机数(4位、6位)
适合没口才的人做,加入中视频伙伴计划收益是真香,一个视频拿3份收益
What are the requirements for NPDP product manager international certification registration?
数据湖系列之一 | 你一定爱读的极简数据平台史,从数据仓库、数据湖到湖仓一体
[leetcode 324] 摆动排序 II 思维+排序
[getting started with Django] 13 page Association MySQL "multi" field table (check)
En utilisant le paquet npoi de net Core 6 c #, lisez Excel.. Image dans la cellule xlsx et stockée sur le serveur spécifié
tensorflow2-savedmodel convert to tflite
What problems should be considered for outdoor LED display?
Summary of leetcode's dynamic programming 5
首届技术播客月开播在即
Provincial election + noi Part IX game theory
Research Report on the development trend and competitive strategy of the global pipeline robot inspection camera industry
Minimum spanning tree and bipartite graph in graph theory (acwing template)
博文推荐 | 深入研究 Pulsar 中的消息分块
Internet hospital system source code hospital applet source code smart hospital source code online consultation system source code