Solidity的方方面面

Solidity的方方面面

未标题-3

img

什么是Soilidity?

Solidity是一种面向合约的高级编程语言,用于实现智能合约。Solidity已经被设计用于以太坊虚拟机。

Solidity===智能合约。

Solidity的代码封装在合约中。合约是以太坊应用程序的基本构建块——所有变量和函数都属于一个合约,这将是所有项目的起点。

pragma solidity >=0.5.0 <0.6.0;
contract HelloWorld {
}

在上面的代码中,我们提供了考虑到我们的代码与b/w 0.5到0.6的任何版本兼容的版本。我们还创建了一个名为“HelloWorld”的合约。

状态变量和整数

状态变量永久存储在合约存储中。这意味着它们被写入以太坊区块链。可以把它们想象成写入DB。

contract Example {
// This will be stored permanently in the blockchain
uint myUnsignedInteger = 100;
string name = “vivek”
}

Uint数据类型是一个无符号整数。它应该是非负的。

数据类型

值类型:

Boolean(true / false),Integers(int / uint), Address(以太坊地址的大小),String, enum

引用类型:

数组、结构、映射

数学运算

Addition: x + y
Subtraction: x — y,
Multiplication: x * y
Division: x / y
Modulus / remainder: x % y (for example, 13 % 5 is 3, because if you divide 5 into 13, 3 is the remainder)
Exponential Operation
uint x = 5 ** 2; // equal to 5² = 25

结构

类似于C语言中的struct。当我们需要创建具有多个属性的复杂数据类型时,我们使用结构体。

struct Person {
uint age;
string name;

数组

数据的集合称为数组。两种类型:固定数组和动态数组。

顾名思义,固定数组有预定义的大小,而动态数组没有大小。

// Array with a fixed length of 2 elements:
uint[2] fixedArray;
// another fixed Array, can contain 5 strings:
string[5] stringArray;
// a dynamic Array — has no fixed size, can keep growing:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值