From 4dd8b0fefa011792230777ec4c8b6b1fb63648a2 Mon Sep 17 00:00:00 2001 From: qyx <565485304@qq.com> Date: Wed, 5 Jul 2023 19:48:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=80=E4=BA=9B=E5=AD=A6?= =?UTF-8?q?=E4=B9=A0=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 34 ++++++++++++++++++++++++-- demo/solidity1.sol | 47 ++++++++++++++++++++++++++++++++++++ demo/solidity_for_import.sol | 8 ++++++ 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 demo/solidity1.sol create mode 100644 demo/solidity_for_import.sol diff --git a/README.md b/README.md index 39b1865..8bfcf5a 100644 --- a/README.md +++ b/README.md @@ -204,8 +204,38 @@ personal.listAccounts - 谜恋猫: https://www.cryptokitties.co/ - 百度莱茨, 网易招财猫, 小米加密兔 - - +## 5. 智能合约编程语言-solidity + +- 合约文件的结构 + - 版本声明 + - import + - 合约 + - 状态变量 + - 函数 + - 结构类型 + - 事件 + - 函数修改器 + - 代码注释 + +- Solidity 语言的类型 + - 值类型(Value Type) + - 引用类型(Reference Types) + - https://docs.soliditylang.org/en/v0.4.23/types.html + + +- 常用值类型 + - 布尔类型(Booleans) + - 取值 true/false + - 运算符 ! && || == != + - 整型(Integers) + - int/uint + - 关键字 unit8 到 uint256(以8步进) + - 位运算符 & | ^ `` + - 算术运算 + - * / % ** << >> + - 右移 等价于 除法去除以2的几次方 + - + - 字符串常量(String literals) + - 地址类型(Address) diff --git a/demo/solidity1.sol b/demo/solidity1.sol new file mode 100644 index 0000000..1678c25 --- /dev/null +++ b/demo/solidity1.sol @@ -0,0 +1,47 @@ +pragma solidity ^0.4.0; + +import "solidity_for_import.sol"; + +// this is a test Contract + +contract Test{ + // 状态变量定义 + uint a; + bool boola = true; + bool boolb = false; + + + + // 函数定义 + function setA(uint x) public { + a = x; + // 触发事件 -> 可以监听这个事件, 获取到对应的值 + emit Set_A(x); + } + + // 定义事件 + event Set_A(uint a); + + // 定义结构类型 + struct Position{ + int lat; + int lng; + } + + address public ownerAddr; + + // 函数修改器 - 类似于 python 的装饰器, 可以修改函数的行为 + modifier owner(){ + // 在调用 mine 之前先进行校验 + require(msg.sender == ownerAddr); + // mine 的代码会插入到这个位置 + _; + } + + // 只有 owner 才能调用这个函数 + function mine() public owner { + + } + + +} \ No newline at end of file diff --git a/demo/solidity_for_import.sol b/demo/solidity_for_import.sol new file mode 100644 index 0000000..db642cc --- /dev/null +++ b/demo/solidity_for_import.sol @@ -0,0 +1,8 @@ +pragma solidity ^0.4.0; + + +// this is a ForImport Contract + +contract ForImport{ + +} \ No newline at end of file