25 |
26 | ## 智能合约的优点
27 |
28 | - 自治
29 | 智能合约独立运行在遍布世界各地的计算机上,不依赖于任何中心化的系统。
30 | - 可信
31 | 智能合约可信的特点是基于分布式账本的,这些账本可以执行并验证合约。
32 | - 鲁棒性
33 | 智能合约存在于分布式的网络中,单点缺失或破坏并不会有影响。
34 | - 速度
35 | 智能合约的去中心化的处理过程可以在短时间内完成对业务逻辑的处理。
36 | - 经济
37 | 智能合约消除了对律师、见证人以及其他中间机构所构成的庞大的中介链的需求。
38 |
39 | ## NEO智能合约
40 |
41 | NEO 的智能合约包括以下特性: 确定性、高性能和可扩展性。合约类型包括: 验证合约、功能合约和应用合约。
42 |
43 | 从性能的角度来看,NEO使用轻量级NeoVM (NEO虚拟机)作为其智能合约的执行环境。它启动非常快,且只占用少量的资源,适用于执行时间短的智能合约。热点合约的静态编译和缓存可以通过JIT(实时编译器)技术得到显著增强。NEO虚拟机的指令集设置提供了一系列加密的指令,从而可以优化智能合约中加密算法的执行效率。此外,数据操作指令对数组和复杂的数据结构提供了直接支持。
44 |
45 | NEO智能合约通过使用高并发和动态分区技术,并通过其松耦合的设计,实现了可伸缩性。松耦合的合约在虚拟机(NEO虚拟机)中执行,并通过交互服务层与外部通信。因此,智能合约功能的绝大多数升级都可以直接通过交互服务层的API来实现。
46 |
47 | ### 使用任意语言编写智能合约
48 | 就语言层面来说,NEO智能合约与以太坊等其他区块链有着更为明显的区别: 与以太坊要求使用原有的Solidity语言不同,NEO智能合约几乎可以使用任何高级编程语言进行编写。NEO为这些语言提供了相应的编译器和插件,可以将这些高级语言编译成NEO虚拟机所支持的指令集。第一个编译器会是针对MSIL (微软中间语言)的,因此从理论上讲,任何.Net语言以及任何可以翻译成MSIL的语言都将即时得到支持。
49 |
50 | 目前支持的语言有:
51 |
52 | - C#
53 |
54 | - Java, Kotlin
55 |
56 | - Python
57 |
58 | - Golang
59 |
60 | - JavaScript (Typescript)
61 |
62 | 由于对语言多样性的支持,90%以上的开发人员就可以直接参与到NEO智能合约的开发,而不需要学习一门新的语言。甚至可以直接将现有的业务系统代码植到区块链中。我们预计未来这将大大促进区块链的全面普及。
63 |
64 | 此外,由于缺乏工具的支持和可使用的明确指令,传统的智能合约很难进行调试和测试。然而,NEO在NEO虚拟机级别提供了针对调试功能的大部分支持,允许您更轻松、更快速地开发NEO 智能合约。
65 |
66 | 开发一个智能合约非常简单。下面是一个使用C#编写的Hello world智能合约示例:
67 |
68 | ```c#
69 | public class HelloWorld : SmartContract
70 | {
71 | public static void Main()
72 | {
73 | Storage.Put(Storage.CurrentContext, "Hello", "World");
74 | }
75 | }
76 | ```
77 |
78 | 下面是一个使用Python编写的Hello world智能合约:
79 |
80 | ```python
81 | def Main():
82 | print("Hello World")
83 | ```
84 |
85 | 使用NEO提供的工具编译和测试之后,就可以在主网、测试网或者私有网络上调用智能合约了。
86 |
87 | 在这篇智能合约教程中,开发人员可以通过学习NEO区块链的技术细节了解智能合约背后的原理,并学习如何基于不同的编程语言和使用不同的工具开发智能合约。
88 |
89 | ## 下一步骤
90 |
91 | 现在,让我们开始学习智能合约的开发。首先要做的是[设置开发环境](Development_set_up.md)
92 |
--------------------------------------------------------------------------------
/cn/9-smartContract/cgas-cn/2_global_asset_and_nep5.md:
--------------------------------------------------------------------------------
1 | # 全局资产和 NEP-5 资产
2 |
3 | 在 NEO 中支持两种资产,分别是全局资产和 NEP-5 资产。
4 |
5 | 全局资产就是 NEO 底层支持的资产。有统一的模板,在 neo-gui 客户端中填写参数就可以很方便地进行注册、发行和转账。全局资产可以通过绑定数字证书进行发行者的身份认证,比如某个公司用 CA 机构颁发的数字证书就可以在 NEO 上发行实名认证的资产,比如股票、代金券、会员卡等。但代价就是高昂的成本,以 GAS 15元的价格为例,发行全局资产的一年的费用约为 5000 * 15 = 75000 元人民币。
6 |
7 | 简单来讲,全局资产的优点就是简单、安全、支持数字证书,成本高昂。
8 |
9 | NEP 全称 NEO Enhancement Proposals,NEP-5 指的是 NEO 的第 5 号改进提案,名称为 Token Standard(代币标准)。在这个标准中规定了智能合约中的资产规范。NEP-5 资产准确地来说叫符合 NEP-5 标准的合约资产。是在智能合约中,开发者规定的“资产”,在智能合约中注册发行和流转。该资产的发行量、名称、精度、以及所有的用户的余额都存储在该智能合约的存储区中。NEP-5 资产的安全性取决于合约的开发者,他可以开源自己的合约供社区审计,也可以不开源合约。这就意味着使用 NEP-5 资产要相信开发者不会做恶。
10 |
11 | 简单来讲,NEP-5 资产的优点就是自由度高,支持复杂的智能合约,不支持数字证书,安全性和发行成本比全局资产低。
12 |
13 | 关于 NEP-5 的介绍可以参考之前的教程,也可以参考 [GitHub](https://github.com/neo-project/proposals/blob/master/nep-5.mediawiki)。
14 |
15 | 下面对两种资产进行了系统的对比
16 |
17 | | | 全局资产 | NEP-5 资产 |
18 | | ------------------------ | ----------------------- | ------------------------ |
19 | | 开始支持时间 | 原生支持 | 2.0 之后才开始支持 |
20 | | 预计结束支持时间 | NEO 3.0 之后 | |
21 | | 代表资产 | NEO、GAS | CGAS、SDUSD、NNC、PHX 等 |
22 | | 注册费用 | 非原生资产 5000GAS / 年 | 500~1000 GAS |
23 | | 存储记录模型 | UTXO 模型 | 余额模型 |
24 | | 安全性 | 高 | 取决于合约开发者 |
25 | | 功能 | 简单 | 复杂 |
26 | | 数字证书的身份认证 | 支持 | 不支持 |
27 | | 在智能合约中进行转账操作 | 不能 | 能 |
28 | | | | |
29 | | | | |
30 |
31 |
--------------------------------------------------------------------------------
/cn/9-smartContract/cgas-cn/3_utxo_model.md:
--------------------------------------------------------------------------------
1 | # 在CGAS中使用UTXO
2 |
3 | 正如在[UTXO基础知识](https://github.com/neo-ngd/NEO-Tutorial/blob/master/9-smartContract/UTXO.md)中所解释的,NEO系统中使用的全局资产是基于模型UTXO的,NEO中使用的交易可以划分为交易输入和交易输出两种。
4 |
5 | 在CGAS中,UTXO以多种方式使用。第一种用法是`MintToken`方法,可以用来获取全局资产。
6 |
7 | 这里,我们首先获取当前交易的引用。
8 |
9 | ```csharp
10 | var references = tx.GetReferences();
11 | ```
12 |
13 | `tx.GetRenferences`方法实际上是用于获取其他交易的`输出`结果,用于构建当前交易的输入。因此,这里的每个引用都包含一个表示资产类型的AssetId以及一个ScriptHash,其中ScriptHash表示对应输出的接收者。
14 |
15 | 在mintToken方法中,`引用`用于跟踪用户地址以及发送到CGAS合约的资产类型。为了获得发送到当前CGAS合约的全局资产的数量,我们需要调用api的 txt.getoutput()方法来获取当前交易的`输出`。在当前交易的每个输出中,将scriptionHash与CGAS scriptHash和AssetId进行比较,然后对每个输出的值求和。
16 |
17 | ```csharp
18 | //兑换数量
19 | var outputs = tx.GetOutputs();
20 | ulong value = 0;
21 | foreach (var output in outputs)
22 | {
23 | if (output.ScriptHash == ExecutionEngine.ExecutingScriptHash &&
24 | output.AssetId.AsBigInteger() == AssetId.AsBigInteger())
25 | {
26 | alue += (ulong)output.Value;
27 | }
28 | }
29 | ```
30 |
31 | CGAS合约在退款操作中会使用另一个UTXO。这里我们只简单地提及了退款操作中使用到的UTXO的相关信息,退款操作的细则可以点击[此处](5_minttokens_and_refund.md)查看。在退款操作的验证触发器中,它将使用`输入`来检查标记的UTXO。在NEO的UTXO模型中,输入结构更像是一个指针,指向它前一个交易的输出。它有两个字段,`PrevHash`表示交易的散列值,`PrevIndex`表示相应输出的索引位置。
32 |
33 | ```csharp
34 | foreach (var input in inputs)
35 | {
36 | if (input.PrevIndex == 0)//如果UTXO n是0,表明这可能是一个标记UTXO
37 | {
38 | StorageMap refund = Storage.CurrentContext.CreateMap(nameof(refund));
39 | var refundMan = refund.Get(input.PrevHash); //0.1
40 | //如果输入标记为退款操作
41 | if (refundMan.Length > 0)
42 | {
43 | //退款中只能有一个输入和一个输出
44 | if (inputs.Length != 1 || outputs.Length != 1)
45 | return false;
46 | return outputs[0].ScriptHash.AsBigInteger() == refundMan.AsBigInteger();
47 | }
48 | }
49 | }
50 | ```
--------------------------------------------------------------------------------
/cn/9-smartContract/cgas-cn/6_signature_and_verification.md:
--------------------------------------------------------------------------------
1 | # 签名和验证
2 |
3 | CGAS 执行的过程大体上可以分两步,第一步是执行交易中的验证脚本,也就是 Verification 触发器,如果验证失败了,交易将不会确认。这步由所有收到该交易的节点执行,执行时间在生成区块之前。
4 |
5 | 第二步是执行智能合约,也就是 Application 触发器。这步由所有同步区块的节点,在同步区块后执行。
6 |
7 | 第一步相关的脚本叫 Witness,其中包含验证脚本(verification)和调用脚本(invocation)。NeoVM 执行的时候,验证脚本就是智能合约执行的代码,调用脚本包含验证脚本所需的参数,一般是签名。
8 |
9 | 在 Witness 中可以包含多组调用和验证脚本。具体可参考 [CGAS GitHub](https://github.com/neo-ngd/CGAS-Contract)。
10 |
11 | 下面以 refund 第一步的交易为示例进行分析。
12 |
13 | refund 第一步时的交易结构:
14 |
15 | > [说明]
16 | >
17 | > Type: InvocationTransaction
18 | >
19 | > Input: 来自 CGAS 合约地址
20 | >
21 | > Output: 转到 CGAS 合约地址 (与 input 相同)
22 | >
23 | > Script: 调用 refund 方法,设置参数为退回者的 Script Hash
24 | >
25 | > Scripts: 需要两个 witness: 1、CGAS 合约的 witness; 2、用户的 witness(附加见证人)
26 |
27 | ```c#
28 | {
29 | "jsonrpc": "2.0",
30 | "id": 1,
31 | "result": {
32 | "txid": "0x306daa4ab2b2ef73ff4fd8f9121fc926f5e21653080602b6841ad3f17f80777c",
33 | "size": 7205,
34 | "type": "InvocationTransaction",
35 | "version": 0,
36 | "attributes": [
37 | {
38 | "usage": "Script",
39 | "data": "e8e3ce08268d16d867101feaf8c0ea130a923aba"
40 | }
41 | ],
42 | "vin": [
43 | {
44 | "txid": "0x48bd784d0ed6000cba64d0e303117e4c10081e3268afcf3b07e8b353a7594772",
45 | "vout": 0
46 | }
47 | ],
48 | "vout": [
49 | {
50 | "n": 0,
51 | "asset": "0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7",
52 | "value": "5",
53 | "address": "AScKxyXmNtEnTLTvbVhNQyTJmgytxhwSnM"
54 | },
55 | {
56 | "n": 1,
57 | "asset": "0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7",
58 | "value": "5",
59 | "address": "AScKxyXmNtEnTLTvbVhNQyTJmgytxhwSnM"
60 | }
61 | ],
62 | "sys_fee": "0",
63 | "net_fee": "0",
64 | "scripts": [
65 | {
66 | "invocation": "520131",
67 | "verification": ""
68 | },
69 | {
70 | "invocation": "404c53a9ca937470df9dcbbb71cf00e2b4d75761e4667ccfd820e40829887c4444c7911ed509e564b2bac30e41c92c43f7df2dd2a25ea1c8e2bc10aec3d3208251",
71 | "verification": "21037ebe29fff57d8c177870e9d9eecb046b27fc290ccbac88a0e3da8bac5daa630dac"
72 | }
73 | ],
74 | "script": "14e8e3ce08268d16d867101feaf8c0ea130a923aba51c106726566756e646776db3192722022eb7841038246dc8fa636dcf274f1",
75 | "gas": "0",
76 | "blockhash": "0xd04d56259a6c92e290ab009e2062fbd078c3c371036d74dd745b379a4d55a899",
77 | "confirmations": 14,
78 | "blocktime": 1536907058
79 | }
80 | }
81 | ```
82 |
83 | ## CheckWitness() 和附加见证人
84 |
85 | 注意到这段交易中是有 attributes 的,因为在智能合约代码中有 CheckWitness(),如果验证的是当前的合约的权限,并不需要在交易属性中添加 script,只限于验证的签名不是合约本身,比如 refund 第一步,用户是通过 from 参数传进来的,而 from 的 script hash 不等于 CGAS script hash,这时需要在交易属性中添加 from 的 script hash 作为附加见证人。
86 |
87 | 另外一点,verification 部分是可以省略的(如上面的示例中的第一个验证脚本),如果省略的话节点会自动根据链上的 script hash 进行补充。这就需要知道总共有哪些 script hash,并且知道 witness 中的各项的排列顺序。目前 witness 中的各项的排列顺序为:按照 script hash 从小到大排序。
88 |
89 | 这样,系统知道了总共的 script hash(当前合约的 script hash 加上交易属性中列出来的 script hash)又知道所有调用和验证脚本,以及这些调用和验证脚本和 Script hash 的匹配顺序,就可以执行代码了。
90 |
91 | ## OpCode 脚本
92 |
93 | 讲完了 CheckWitness() 和交易属性,那么来看下第一组调用脚本,上面的示例是 520131,这是什么意思呢。首先将 52 放入调用栈,然后放入 01,再放入 31。
94 |
95 | 取数据的时候按照 [OpCode](https://github.com/neo-project/neo-vm/blob/master/src/neo-vm/OpCode.cs) 中的注释来理解,52 的意思是 Push 2。
96 |
97 | 16 进制的 01 的意思是后面这是一个数组,长度为 1(0x01 对应 10 进制的 1),之后 1 字节的数据是数据本身,并非指令。
98 |
99 | 16 进制的 31 对应 ASCII 码中的字母 ‘1’
100 |
101 | 所以第一个参数是数字 2,第二个参数是字符串 “1”。
102 |
103 | 通过这个顺序将两个参数放入调用栈,读取的时候按照栈的顺序,先取出来第一个参数是字符串 “1”,再取出来第二个参数是数字 2。
104 |
105 | **示例1**
106 |
107 | 有了上面的例子,下面来看下第二组的调用脚本:
108 |
109 | ```
110 | 404c53a9ca937470df9dcbbb71cf00e2b4d75761e4667ccfd820e40829887c4444c7911ed509e564b2bac30e41c92c43f7df2dd2a25ea1c8e2bc10aec3d3208251
111 | ```
112 |
113 | 首先是 16 进制的 40,对应 10 进制的 64,后面 64 位是个字节数组(其实是签名)。
114 |
115 | **示例2**
116 |
117 | 再看一下第二组的验证脚本:
118 |
119 | ```
120 | 21037ebe29fff57d8c177870e9d9eecb046b27fc290ccbac88a0e3da8bac5daa630dac
121 | ```
122 |
123 | 首先是 16 进制的 21,对应 10 进制的 33,后面 33 位是个字节数组(其实是公钥),最后一个 0xac 意思是 CHECKSIG,意思是验证签名,就这么简单。
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/20190219-112142.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/20190219-112142.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/20190219-113025.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/20190219-113025.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/20190219-120404.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/20190219-120404.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/20190219-120735.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/20190219-120735.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/20190219-140640.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/20190219-140640.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/20190219-140958.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/20190219-140958.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/20190222-153331.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/20190222-153331.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/20190222-153712.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/20190222-153712.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/20190222-153941.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/20190222-153941.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/20190222-154922.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/20190222-154922.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/20190222-155235.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/20190222-155235.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/20190222-155608.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/20190222-155608.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/check.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/check.gif
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/check.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/check.jpg
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/newbie.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/newbie.jpg
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/plugin.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/plugin.jpg
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/smart-contracts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/smart-contracts.png
--------------------------------------------------------------------------------
/cn/9-smartContract/imgs/vs.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/9-smartContract/imgs/vs.jpg
--------------------------------------------------------------------------------
/cn/9-smartContract/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | lang: cn
4 | lang-ref: sc-index
5 | ---
6 |
7 |
8 | - Smart Contract
9 | - [What is smart contract](What_is_smart_contract.md)
10 | - [Write your NEO contact with any languages](What_is_smart_contract.md#write-smart-contracts-in-any-language)
11 | - [Prepare the development environment of your smart contract](Development_set_up.md)
12 | - Learn smart contract by demos in C#
13 | - [Smart Contract basic](Smart_Contract_basics.md)
14 | - [Smart contract structure](Smart_Contract_basics.md#contract-structure)
15 | - [Properties](Smart_Contract_basics.md#constract-property)
16 | - [Storage usage](Smart_Contract_basics.md#storage-property)
17 | - [Data types](Smart_Contract_basics.md#data-type)
18 | - [Your first NEO smart contract](Smart_Contract_basics.md#Your first NEO contract)
19 | - [Method and triggers](Smart_Contract_basics.md#trigger)
20 | - [Events](Smart_Contract_basics.md#events)
21 |
22 | - Make your NEP-5 Token
23 | - [Introduction to NEP-5](What_is_nep5.md#introduction-to-nep-5)
24 | - [Implementation of NEP-5](What_is_nep5.md#implementation-of-nep-5)
25 | - [ITO(Initial Token Offering)](Give_an_ITO.md#give-an-ito-initial-token-offering)
26 | - [Timestamp in blockchain](Give_an_ITO.md#timestamp)
27 | - [UTXO basics](UTXO.md)
28 | - [Minting Tokens](Give_an_ITO.md#minttoken)
29 | - CGAS
30 | - [What is CGAS](cgas/1_what_is_cgas.md)
31 | - [Global asset and NEP-5](cgas/2_global_asset_and_nep5.md)
32 | - [UTXO model](cgas/3_utxo_model.md)
33 | - [Trigger](cgas/4_trigger.md)
34 | - [Mint and Refund](cgas/5_minttokens_and_refund.md)
35 | - [Signature and Verification](cgas/6_signature_and_verification.md)
36 | - [Transaction Invocation](cgas/7_invocation.md)
37 | - Write NEO smart contract with Python
38 | - what is Neo-python
39 | - Prepare the Neo-python development procedure environment
40 | - NEO python basics
41 | - Python smart contract example
42 | - Domain Name Service
43 | - Dapp demo based on neo python
44 | - Lucky neo
45 | - Write NEO smart contract with JS
46 | - Introduction of neo-one
47 | - neo-one smart contract example
48 | - ICO template
49 | - Escrow
50 | - Build a Dapp based on neo-one
51 | - Write NEO smart contract with Go.
52 | - Introduction to neo-storm framework
53 | - Issue a NEP5 token on using Go.
54 | - Build game on blockchain
55 | - The structure of blockchain game
56 | - Build a game with NEO + Unity
57 |
--------------------------------------------------------------------------------
/en/1-introduction/1-Introduction_to_NEO.md:
--------------------------------------------------------------------------------
1 | # NEO Tutorial
2 |
3 | ## Introduction to NEO
4 |
5 | [NEO](https://neo.org/) is a public and global open-source blockchain project that aims to facilitate the creation of a Smart Economy.
6 |
7 | The Smart Economy is a vision for the future where business is revolutionized by the adoption of digital assets and identities, allowing for the automated and trustless management of those assets through the use of smart contracts.
8 |
9 | NEO, originally AntShares, was founded by Da Hongfei and Erik Zhang. As co-founders of the non-profit NEO Foundation, the two oversee the ongoing development of the NEO blockchain. NEO Foundation’s execution arm is NEO Global Development (NGD), which is committed to the development of the NEO protocol and its supporting ecosystem. There are currently two NGD offices; a head office located in Shanghai, and a second office based in Seattle, US.
10 |
11 | NGD maintains [a team of core developers](https://neo.org/team) who are primarily responsible for protocol development, though NEO both encourages and rewards contributions from independent developers.
12 |
13 | NEO is a community-driven project, which has led to the creation and funding of numerous community development groups distributed around the world. These teams contribute to the development of NEO's core infrastructure, in addition to producing user facing applications such as wallets or tooling for developers looking to build on NEO.
14 |
15 | [Next chapter](2-Cryptography_Blockchain_and_Smart_Contracts.md) or [return to contents](README.md#contents).
16 |
--------------------------------------------------------------------------------
/en/1-introduction/2-Cryptography_Blockchain_and_Smart_Contracts.md:
--------------------------------------------------------------------------------
1 | ## Cryptography, Blockchain, and Smart Contracts
2 |
3 | Cryptography is one of the fundamental pillars of blockchain, referring to a branch of mathematics and computer science that can be used to protect information or validate the authenticity of a given piece of data.
4 |
5 | In addition to its role in a blockchain's consensus mechanism, cryptography is used to create digital signatures, which are used to prove that an individual has the right to perform a given action.
6 |
7 | Through public-key cryptography, keys are created in asymmetric pairs; one public key that can be freely shared, and one private key that must be kept secret. In essence, the private key is used to prove ownership of the public key.
8 |
9 | The use of cryptography coupled with the immutability of a blockchain allows individuals to send or receive value (in the form of digital assets such as cryptocurrencies) safely without requiring trust in a third party. This trustlessness is instrinsically linked to the decentralization of the blockchain.
10 |
11 | Transfer of value in this manner is a desirable property, however it is limited. For more complex operations, smart contracts can be used. Smart contracts are a set of programmed instructions that can be run by nodes within a blockchain network, typically through the use of a virtual machine.
12 |
13 | Smart contracts are executed automatically and deterministically, ensuring that the results are predictable. Users can interact with contract-based services in much the same way they would interact with an intermediary in the real world, all without compromising on trust.
14 |
15 | A good resource with a more detailed primer on blockchain technology and its implications can be found [here](https://www2.deloitte.com/insights/us/en/topics/emerging-technologies/blockchain-technical-primer.html).
16 |
17 | [Next chapter](3-Fundamentals_of_NEO.md) or [return to contents](README.md#contents).
18 |
--------------------------------------------------------------------------------
/en/1-introduction/3-Fundamentals_of_NEO.md:
--------------------------------------------------------------------------------
1 | ## NEO Fundamentals
2 |
3 | NEO is a public blockchain that offers smart contract functionality, allowing developers to build decentralized applications that can manage digital assets and identities. It is often compared to [Ethereum](https://www.ethereum.org/), the largest and most well known smart contract platform, however the two have many fundamental differences that set them apart.
4 |
5 | ### Dual Token Model
6 |
7 | Although NEO can support an unlimited number of digital assets created by contracts, it has two assets that are native to the network itself; NEO and GAS.
8 |
9 | NEO, referred to as the governance token, is used to elect consensus nodes via the use of a voting mechanism. NEO owners can be considered as the managers of the NEO network, responsible for selecting which candidates are best suited to participate in the creation and validation of blocks.
10 |
11 | In return, NEO holders receive GAS, the second native asset on the NEO blockchain. GAS is the utility token, used to pay for operations on the network. This includes system fees, such as the cost of deploying a smart contract, and also network fees that are used to give priority to a transaction.
12 |
13 | ### Consensus and Transaction Finality
14 |
15 | Unlike the majority of current blockchains that use variants of PoW (Proof-of-Work) or PoS (Proof-of-Stake) for their respective consensus mechanisms, NEO uses an original consensus mechanism known as dBFT (delegated Byzantine Fault Tolerance).
16 |
17 | PoW- and PoS-based consensus mechanisms encourage a large number of participants to propose blocks to the network. Conflicts are resolved through the use of forks, with the longest chain considered to be the truthful chain.
18 |
19 | In these blockchains, transactions within blocks are finalized over time in a probabilistic manner through the use of confirmations. The more blocks have been added to the blockchain since the block containing a given transaction, the less likely that transaction will be nullified by a fork.
20 |
21 | In dBFT, NEO owners vote to elect a set of consensus nodes; a delegated group responsible for producing blocks. Each block in NEO must be agreed on by a 2/3 majority of consensus nodes before it is committed to the blockchain.
22 |
23 | As each potential block must receive full network consensus in this manner before being accepted, transactions in NEO have absolute finality as soon as they are confirmed in a single block. This prevents transactions from being reversed by preventing forks, allowing for immediate settlement of all transactions on the network.
24 |
25 | ### Contract Languages
26 |
27 | In an effort to be as developer-friendly as possible, NEO supports a diverse list of programming languages that can be used to create smart contracts. Currently, NEO allows contracts to be created in C#, Java, Python, Golang, JavaScript/TypeScript, and other languages.
28 |
29 | Contracts in NEO are compiled to NVM bytecode before being deployed to the NEO blockchain. When called, these deployed contracts are interpreted and executed by NeoVM.
30 |
31 | [Next chapter](4-NEO_Tutorial.md) or [return to contents](README.md#contents).
32 |
--------------------------------------------------------------------------------
/en/1-introduction/4-NEO_Tutorial.md:
--------------------------------------------------------------------------------
1 | ## NEO Tutorial
2 |
3 | NEO Tutorial is designed as an onboarding tool for developers or other individuals that wish to become more familiar with the internal workings of NEO. The included tutorials will demonstrate the underlying technology used by NEO, such as information on how addresses are generated, how blocks are created and validated, and how the dBFT consensus mechanism operates.
4 |
5 | It should be noted that this version of NEO Tutorial is applicable only to NEO 2.x, the current version of the NEO MainNet. Large changes are expected during the transition to NEO3, at which point an updated tutorial will be created.
6 |
7 | The NEO Tutorial contents page may be found [here](https://neo-ngd.github.io/NEO-Tutorial/).
8 |
--------------------------------------------------------------------------------
/en/1-introduction/README.md:
--------------------------------------------------------------------------------
1 | ## Contents
2 |
3 | 1. [Introduction to NEO](1-Introduction_to_NEO.md)
4 | 2. [Cryptography, Blockchain, and Smart Contracts](2-Cryptography_Blockchain_and_Smart_Contracts.md)
5 | 3. [NEO Fundamentals](3-Fundamentals_of_NEO.md)
6 | 4. [NEO Tutorial](4-NEO_Tutorial.md)
7 |
8 | ## Additional Resources
9 |
10 | ### Useful NEO Documentation
11 |
12 | * NEO Whitepaper - https://docs.neo.org/docs/en-us/basic/whitepaper.html
13 | * Technical Documentation - https://docs.neo.org/docs/en-us/index.html
14 | * Awesome NEO Docs - https://github.com/CityOfZion/awesome-neo-docs
15 |
16 | ### NEO Development Communities
17 |
18 | * COZ - [Website](https://cityofzion.io/) | [Github](https://github.com/CityOfZion/)
19 | * NeoResearch - [Website](https://neoresearch.io/) | [Github](https://github.com/NeoResearch)
20 | * NEO SPCC - [Website](https://nspcc.ru/en/) | [Github](https://github.com/CityOfZion/)
21 | * NewEconoLabs - [Website](https://nel.group/) | [Github](https://github.com/neweconolab/)
22 | * O3 Labs - [Website](https://o3.network/) | [Github](https://github.com/O3Labs/)
23 |
--------------------------------------------------------------------------------
/en/1-introduction/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | lang: en
4 | lang-ref: NEO-intro
5 | ---
6 |
7 | - Introduction to NEO
8 | - The introduction of Cryptography and CryptoCurrency
9 | - NEO
10 | - History
11 | - White Paper
12 | - Features
13 | - Documentations
14 |
--------------------------------------------------------------------------------
/en/2-wallet/1-Introduction_to_wallets.md:
--------------------------------------------------------------------------------
1 |
2 | ## Understanding Wallets
3 | For a user to begin interacting with NEO or other blockchains, they must first create a unique user "wallet" locally on their machine, allowing them to create any number of accounts (keypairs) that can be used to make transactions on the network. This is different from modern centralized applications where users must create a user account, which is then stored on a centralized server where it is managed exclusively by the service provider.
4 |
5 | Although a wallet is used to access NEO, GAS, and other NEO-based tokens, the name "wallet" is actually a misnomer. At its core, a wallet is a cryptographic public/private key pair which is used to sign and authenticate database transactions that occur on the NEO network.
6 |
7 | Let's first consider how a user would perform a write operation on a traditional centralized database, and compare it to how a user would perform a write operation on the NEO blockchain. This should help clear up the misconception that coins are stored on a wallet, as opposed to them being stored in the blockckchain.
8 |
9 | ## Centralized Database
10 | In client/server architecture, a user would first create an account using identity credentials such as an email/password combination. These credentials are then stored on the service's database. When the user logs in to the service they receive a session token in their local environment which allows them to perform write operations on the services database.
11 |
12 | So if this centralized application was a banking service, the "coins" would be stored on the bank's servers, and you would be able to perform transfers after providing valid credentials to the bank.
13 |
14 |
15 | ### Advantages:
16 | * If the user loses their credential information, it can be recovered by the service provider
17 | * Email/Password is a standardized UX paradigm that almost all internet users are accustomed to
18 |
19 | ### Disadvantages
20 | * Storing all user credentials in a centralized server makes it an attractive target for hacking
21 | * A separate set of credentials needs to be generated for every single service
22 |
23 | But most importantly, and a phrase often spread in the cryptocurrency community:
24 |
25 | "Not your keys, not your coins."
26 |
27 | The nature of traditional client/server architecture means that the end user has very little control of whatever data is being stored in the server's database. Although this is particularly relevant for financial applications, it applies more broadly to general user data.
28 |
29 |
30 | ## NEO Blockchain
31 | Let's contrast this with how a user would perform write operations on the NEO blockchain. A user would first generate a public/private key pair. These key pairs are stored locally on the user device, in a dedicated hardware module, or somewhere else in the client. These key pairs NEVER touch a remote server. When a user wishes to perform a write operation on the NEO blockchain (database), they generate a transaction locally with their intended operation. For example, this operation could be sending 1 NEO to a friend. They then sign this transaction with their cryptographic signature, which is generated using a private key.
32 |
33 | This transaction is then verified and propagated across the network which then finalizes the write operation. We can see that no other entity can perform write operations to the remote database on the user's behalf without explicit authorization because the cryptographic signature can ONLY be generated by the user.
34 |
35 | ### Advantages
36 | * No central point of attack for a hacker. This removes a lot of responsibility from the service provider
37 | * User public identities can be shared amongst various service providers
38 | * Your Keys, Your Coins
39 |
40 | ### Disadvantages
41 | * No recovery mechanism if a user lose their credentials
42 | * New UX pattern for users who are not experienced with this kind of system
43 |
44 |
45 | In summary, we can accurately describe a wallet as a public/private key pair which is used to perform write operations on a distributed database (blockchain). It has advantages and disadvantages when compared to typical client/server authentication architecture, but we believe that the security and user control that this system provides allows for a more robust experience overall.
46 |
47 | In the next chapter, we will now go into some of the specifics about NEO key architecture.
48 |
49 | [Next chapter](2-Key_derivation_and_address_generation_on_NEO.md) or [return to contents](README.md#contents).
50 |
51 |
52 |
--------------------------------------------------------------------------------
/en/2-wallet/4-UTXO_and_account_models.md:
--------------------------------------------------------------------------------
1 | ## UTXO Model
2 | One of the main functions of a wallet is to facilitate the transfer of assets. Assets on NEO are divided into two categories; UTXO-based (Unspent transaction outputs) and account-based. In NEO, NEO and GAS follow the UTXO model, while NEP-5 tokens follow the account model. Lets explore both in more detail.
3 |
4 | First, let us consider a simple example where a user has 10 NEO. This 10 NEO actually consists of multiple UTXOs. The sum of all the UTXOs must equal 10. For example this 10 NEO may be consist of 3 UTXOs. UTXO_1 is worth 2 NEO, UTXO_2 is worth 3 NEO, and UTXO_3 is worth 5 NEO, which sums up to the total balance of 10 NEO. So if we need to send someone 3 NEO then we can simply use UTXO_2 3 as the input of the transaction, and the recipient receives as an output one UTXO that is also worth 3 NEO.
5 |
6 | If we try to send 5 NEO, then we can combine the UTXO_1 and UTXO_2 together as the inputs, and the recipient recieves 5 NEO as one single output of the transaction. It becomes slightly more complicated when we need to send an amount where we cannot create a perfect sum of UTXOs.
7 |
8 | Let's say that we want to send 4 NEO to someone. No combination of our UTXOs will allows us to get get 4 exactly. The best we can do is use UTXO_1 and UTXO_2 together which will combine to equal 5 NEO. So we use UTXO_1 and UTXO_2 as the inputs to our transaction, but instead of having a single output as with the previous examples, we need to have two output UTXOs. One UTXO worth 4 NEO is generated for the recipient, and then a second UTXO worth 1 NEO is created and returned as change back to the sender's address.
9 |
10 | For core NEO transactions, they must satisfy this formula in order to be considered valid on the network:
11 |
12 | Sum(NEO_i) + Sum(GAS_i) = Sum(NEO_o) + (Sum(GAS_I) - Sum(GAS_sys_fee) - Sum(GAS_net_fee))
13 |
14 | In this sense, UTXOs are not really created or destroyed, but are instead recycled into new ones. Inclusion of UTXOs allows for parallel transaction execution, as each UTXO is unique and therefore is impossible to double spend.
15 |
16 | ## Account Model
17 | The account model, which is adopted by other blockchain platforms such as Ethereum, creates a global state for each account which has funds. Instead of having a set of UTXOs which can be used for a transaction, you would simply have a balance of 10 associated with your account. Because of this, the global state of all acounts must be store locally on the nodes in the network. Transactions are interpreted by the virtual machine in the network, and make the corresponding state changes to all accounts in the global state.
18 |
19 | NEP-5 token contracts deployed on the NEO network typically follow the account model of balance storage. They do not have any associated UTXO data, and changes in balance state are handled via smart contract executions. These executions are interpreted by the NEO virtual machine, and recorded in the smart contract storage area.
20 |
21 | [Return to contents](README.md#contents).
22 |
--------------------------------------------------------------------------------
/en/2-wallet/README.md:
--------------------------------------------------------------------------------
1 | ## Contents
2 |
3 | 1. [Introduction to Blockchain Wallets](1-Introduction_to_wallets.md)
4 | 2. [Key deriviation and address generation on NEO](2-Key_derivation_and_address_generation_on_NEO.md)
5 | 3. [Encrypting private keys and creating contract accounts](3-Key_encryption_and_contract_accounts.md)
6 | 4. [The UTXO and Account models](4-UTXO_and_account_models.md)
7 |
8 | ## Additional Resources
9 |
10 | ### Creating a wallet
11 | There are several options available to you when creating a new wallet.
12 |
13 | For full blockchain synchronization, consider:
14 | * NEO-GUI -> https://docs.neo.org/en-us/node/gui/install.html
15 | * NEO-CLI -> https://docs.neo.org/en-us/node/cli/cli.html
16 |
17 | For light clients which do not require synchronization, consider:
18 | * O3 Wallet -> https://o3.network/
19 | * NEON Wallet -> https://neonwallet.com/
20 |
21 | You can find more detailed usage guides at the relevant wallet links.
22 |
--------------------------------------------------------------------------------
/en/2-wallet/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | lang: en
4 | lang-ref: wallet-index
5 | ---
6 |
7 |
8 | ## Contents
9 |
10 | 1. [Introduction to Blockchain Wallets](1-Introduction_to_wallets.md)
11 | 2. [Key deriviation and address generation on NEO](2-Key_derivation_and_address_generation_on_NEO.md)
12 | 3. [Encrypting private keys and creating contract accounts](3-Key_encryption_and_contract_accounts.md)
13 | 4. [The UTXO and Account models](4-UTXO_and_account_models.md)
14 |
15 | ## Additional Resources
16 |
17 | ### Creating a wallet
18 | There are several options available to you when creating a new wallet.
19 |
20 | For full blockchain synchronization, consider:
21 | * NEO-GUI -> https://docs.neo.org/en-us/node/gui/install.html
22 | * NEO-CLI -> https://docs.neo.org/en-us/node/cli/cli.html
23 |
24 | For light clients which do not require synchronization, consider:
25 | * O3 Wallet -> https://o3.network/
26 | * NEON Wallet -> https://neonwallet.com/
27 |
28 | You can find more detailed usage guides at the relevant wallet links.
29 |
--------------------------------------------------------------------------------
/en/3-transactions/1-Introduction_to_transactions.md:
--------------------------------------------------------------------------------
1 | ## Introduction to transactions
2 | A NEO transaction is a signed data package with an instruction for the network, for example a user indicating that he wants to transfer assets to another address. Each NEO block in the blockchain ledger contains one or more transactions, making each block a transaction batch. To use the NEO blockchain we need to understand how transactions work.
3 |
4 | - **[Structure of transactions](2-Structure_of_NEO_transactions.md)**
5 | - [type](2-Structure_of_NEO_transactions.md#type)
6 | - [version](2-Structure_of_NEO_transactions.md#version)
7 | - [attributes](2-Structure_of_NEO_transactions.md#attributes)
8 | - [outputs](2-Structure_of_NEO_transactions.md#outputs)
9 | - [inputs](2-Structure_of_NEO_transactions.md#inputs)
10 | - [scripts](2-Structure_of_NEO_transactions.md#scripts)
11 |
12 | ### Transaction types
13 | There are several different types of transactions on NEO, each with a different purpose and different properties. Some previously used transaction types are now deprecated or removed from the network, so these should not be used when creating new transactions on the MainNet.
14 |
15 | - **[Transaction types](3-NEO_transaction_types.md)**
16 | - [MinerTransaction](3-NEO_transaction_types.md#minertransaction)
17 | - [ClaimTransaction](3-NEO_transaction_types.md#claimtransaction)
18 | - [ContractTransaction](3-NEO_transaction_types.md#contracttransaction)
19 | - [StateTransaction](3-NEO_transaction_types.md#statetransaction)
20 | - [InvocationTransaction](3-NEO_transaction_types.md#invocationtransaction)
21 | - [Registering assets](3-NEO_transaction_types.md#registering-assets)
22 |
23 | ### Transaction fees
24 | Some transactions on the NEO network require fees. The network uses a fee structure with two types of fees; system fees and network fees. All fees are paid in the native utility token GAS (NeoGas).
25 |
26 | - **[Transaction fees](4-NEO_transaction_fees.md)**
27 | - [System fees](4-NEO_transaction_fees.md#system-fees)
28 | - [Network fees](4-NEO_transaction_fees.md#network-fees)
29 | - [Utility fee in applications](4-NEO_transaction_fees.md#utility-fee-in-applications)
30 |
31 | ## Broadcasting
32 | Once a transaction has been created it can be sent to a network peer node. If the peer node determines the transaction as being valid, it will be placed in the memory pool and distributed through the rest of the network. Eventually a consensus node (validators on the NEO blockchain) will receive the transaction and process it by including it in a block.
33 |
34 | [Next chapter](2-Structure_of_NEO_transactions.md) or [return to contents](README.md#contents).
35 |
--------------------------------------------------------------------------------
/en/3-transactions/README.md:
--------------------------------------------------------------------------------
1 | ## Contents
2 |
3 | 1. [Introduction to transactions](1-Introduction_to_transactions.md)
4 | 2. [Structure of NEO transactions](2-Structure_of_NEO_transactions.md)
5 | 3. [NEO transaction types](3-NEO_transaction_types.md)
6 | 4. [Transaction fees](4-NEO_transaction_fees.md)
7 |
8 | ## Additional Resources
9 |
10 | ### Tools
11 | There are various tools and libraries available to create and broadcast transactions to the NEO network:
12 |
13 | - [neon-js](https://github.com/CityOfZion/neon-js) is a JavaScript library that can be used to build extensive transactions in any JavaScript application
14 | - [neo-python](https://github.com/CityOfZion/neo-python) is a full NEO node that can be used as an SDK to create transactions and interact with the NEO network
15 | - [neo-gui](https://github.com/neo-project/neo-gui/) is the official Windows GUI to interact with the NEO network
16 | - [neo-cli](https://github.com/neo-project/neo-cli/) is the official full node implementation that runs as a command line implementation and can be used to create and broadcast transactions to the NEO network
17 | - Many other wallet or node implementations like [neo-lux](https://github.com/CityOfZion/neo-lux) and [neo-thinsdk-cs](https://github.com/NewEconoLab/neo-thinsdk-cs) in C#
18 |
--------------------------------------------------------------------------------
/en/3-transactions/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | lang: en
4 | lang-ref: transaction-index
5 | ---
6 |
7 |
8 | ## Contents
9 |
10 | 1. [Introduction to transactions](1-Introduction_to_transactions.md)
11 | 2. [Structure of NEO transactions](2-Structure_of_NEO_transactions.md)
12 | 3. [NEO transaction types](3-NEO_transaction_types.md)
13 | 4. [Transaction fees](4-NEO_transaction_fees.md)
14 |
15 | ## Additional Resources
16 |
17 | ### Tools
18 | There are various tools and libraries available to create and broadcast transactions to the NEO network:
19 |
20 | - [neon-js](https://github.com/CityOfZion/neon-js) is a JavaScript library that can be used to build extensive transactions in any JavaScript application
21 | - [neo-python](https://github.com/CityOfZion/neo-python) is a full NEO node that can be used as an SDK to create transactions and interact with the NEO network
22 | - [neo-gui](https://github.com/neo-project/neo-gui/) is the official Windows GUI to interact with the NEO network
23 | - [neo-cli](https://github.com/neo-project/neo-cli/) is the official full node implementation that runs as a command line implementation and can be used to create and broadcast transactions to the NEO network
24 | - Many other wallet or node implementations like [neo-lux](https://github.com/CityOfZion/neo-lux) and [neo-thinsdk-cs](https://github.com/NewEconoLab/neo-thinsdk-cs) in C#
25 |
--------------------------------------------------------------------------------
/en/4-blocks/1-Introduction_to_blocks_and_blockchain.md:
--------------------------------------------------------------------------------
1 | ## Introduction to blocks & blockchain
2 |
3 | ### Concept
4 | When Alice wants to send a transaction to Bob, she will sign her transaction and broadcast it to the nodes in the network. The consensus nodes will select from the available pool of valid transactions, which may then be included into a block. A block is a batch of transactions that are confirmed and stored at the same time. Aside from all transactions that a certain block includes, there are some other fields present in each block which are discussed [here](2-Structure_of_a_block.md).
5 |
6 | ## Chaining the blocks
7 | One of these fields that is present in each block (bn) is a reference to the previous block that was just confirmed before this block (bn-1). In more detail, it is the hash of the header of the previous block. It is up to the nodes to calculate the hash to validate the parent block. In turn, this previous block(bn-1) also has the same behaviour, linking to the block before it(bn-2). This chain of connections leads all the way back to the first block ever created, called the Genesis (b0) block. This is the origin of the term 'blockchain' as it is, in fact, a line of blocks that are linked together as a chain.
8 |
9 | ## Parents & Children
10 | Every block can only have one parent, referenced in the field for the previous block. Most blockchains can have a temporary situation where a single parent block can have multiple children, that is, multiple blocks can point to the same block as its parent. This happens, on average, once every week for Bitcoin. This happens when 2 miners find a valid nonce for a new block ("solve the puzzle") at approximately the same time, both broadcasting valid blocks to the network. This is what is called a fork, which is automatically resolved when new blocks are mined. This is because additional blocks will only continue on one side of the path, and the longest path (path of most difficulty) is accepted as the truth. The second path is abandoned.
11 |
12 | Thanks to its dBFT consensus mechanism, the NEO blockchain does not suffer from this behaviour and will, by algorithmic certainty, never fork, and thus will never encounter a situation in which 2 valid versions of the blockchain exists. For more information on this consensus mechanism, you can read the [whitepaper](https://docs.neo.org/en-us/basic/consensus/whitepaper.html).
13 |
14 | [Next chapter](2-Structure_of_a_block.md) or [return to contents](README.md#contents).
15 |
--------------------------------------------------------------------------------
/en/4-blocks/2a-Merkle-Tree.md:
--------------------------------------------------------------------------------
1 | # Merkle tree
2 |
3 | ## Introduction to Merkle tree
4 |
5 | 
6 |
7 | A Merkle tree is a tree in which leaves of the tree are hashed in couples. So the hashes of L1 and L2 are hashed together, and the hashes of L3 and L4 get hashed together. Then the process is recursively applied to those hashes, until only 1 hash value is left, the Root of the tree. It is mostly visualized using an upside-down tree, with the Root at the top, branches coming down, and the leaves at the bottom. Using a Merkle tree, it is efficient to verify if a specific data point is part of the full tree. For more information on Merkle trees in general, visit [Wikipedia](https://en.wikipedia.org/wiki/Merkle_tree).
8 |
9 | ## Merkle tree and Network Security
10 |
11 | Many blockchains use Merkle trees to efficiently secure the transactions each block contains. Since every transaction has an effect on the final hash value of the root of the Merkle tree, changing any transaction in the block will totally change the value of the Merkle tree's root hash. Therefore by only storing and validating the Root Hash of the Merkle tree, the full list of transactions can be validated. This could of course be achieved with any hash operation on all transactions. There are more advantages to using a Merkle tree, one of them can be found in Simplified Payment Verification (SPV), where the time required to validate that a transaction is part of a block can be drastically reduced thanks to the use of Merkle trees.
12 |
--------------------------------------------------------------------------------
/en/4-blocks/README.md:
--------------------------------------------------------------------------------
1 | ## Contents
2 |
3 | 1. [Introduction to Blocks and Blockchain](1-Introduction_to_blocks_and_blockchain.md)
4 | 2. [Structure of a Block](2-Structure_of_a_block.md)
5 | 3. [Block Creation & Broadcasting](3-Block_creation_broadcasting.md)
6 | 4. [Block Validation & Processing](4-Block_validation_processing.md)
7 |
8 | ## Additional Resources
9 |
10 | ### Merkle trees
11 | Most blockchains, NEO included, use Merkle trees to efficiently secure the transactions contained in each block.
12 |
13 | As Merkle roots are found in the block headers on NEO, it is recommended to familiarize yourself with Merkle trees before reading about the structure of blocks on NEO. An introduction to Merkle trees may be found [here](2a-Merkle-Tree.md).
14 |
--------------------------------------------------------------------------------
/en/4-blocks/block-info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/4-blocks/block-info.png
--------------------------------------------------------------------------------
/en/4-blocks/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | lang: en
4 | lang-ref: blocks-index
5 | ---
6 |
7 | ## Contents
8 |
9 | 1. [Introduction to Blocks and Blockchain](1-Introduction_to_blocks_and_blockchain.md)
10 | 2. [Structure of a Block](2-Structure_of_a_block.md)
11 | 3. [Block Creation & Broadcasting](3-Block_creation_broadcasting.md)
12 | 4. [Block Validation & Processing](4-Block_validation_processing.md)
13 |
14 | ## Additional Resources
15 |
16 | ### Merkle trees
17 | Most blockchains, NEO included, use Merkle trees to efficiently secure the transactions contained in each block.
18 |
19 | As Merkle roots are found in the block headers on NEO, it is recommended to familiarize yourself with Merkle trees before reading about the structure of blocks on NEO. An introduction to Merkle trees may be found [here](2a-Merkle-Tree.md).
20 |
--------------------------------------------------------------------------------
/en/4-blocks/merkle-tree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/4-blocks/merkle-tree.png
--------------------------------------------------------------------------------
/en/4-blocks/txn-with-fee.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/4-blocks/txn-with-fee.png
--------------------------------------------------------------------------------
/en/5-network/1-Introduction_to_the_NEO_network_protocol.md:
--------------------------------------------------------------------------------
1 | ## NEO Protocol and Networking Tutorial
2 |
3 | [NEO](https://neo.org/) is an open-source platform for decentralized applications. It is a blockchain with the [dBFT](https://docs.neo.org/en-us/basic/consensus/consensus.html) consensus protocol, baring similarity to Ethereum in that it can deploy and execute smart contracts.
4 |
5 | This tutorial targets developers/students that want to write their own NEO P2P client in order to participate in the distributed system. This tutorial will not go into details of distributed systems and the reader should be familiar with the basics of distributed systems, about networking protocols, and the Golang programming language.
6 |
7 | The NEO network consists of two kind of protocols: a protocol to communicate with local clients and wallets, and an external protocol to communicate with other NEO nodes. To connect to a local node, [JSON-RPC](https://www.jsonrpc.org/) is used. This JSON-RPC can also be exposed to other external nodes.
8 |
9 | ```
10 | +--------------+
11 | +----------+ | +----------+ |
12 | | | NEO Protocol | | | |
13 | | NEO node +----------------+ NEO peer | |
14 | | | | | | |
15 | +----------+ | +----+-----+ |
16 | | | |
17 | | |JSON |
18 | | |RPC |
19 | | | |
20 | | +----+-----+ |
21 | | | | |
22 | | |Local node| |
23 | | | | |
24 | | +----------+ |
25 | +--------------+
26 | NEO node
27 | ```
28 | In this tutorial, we will focus on the other protocol, the [NEO protocol](https://docs.neo.org/en-us/network/network-protocol.html). Using the Golang programming language, we will learn how to communicate with a NEO node.
29 |
30 | [Follow this link to get started](2-Developing_a_NEO_ping_using_Golang.md) or [return to contents](README.md#contents).
31 |
--------------------------------------------------------------------------------
/en/5-network/README.md:
--------------------------------------------------------------------------------
1 | ## Contents
2 |
3 | 1. [Introduction to the NEO network protocol](1-Introduction_to_the_NEO_network_protocol.md)
4 | 2. [Developing a NEO Ping using Golang](2-Developing_a_NEO_ping_using_Golang.md)
5 |
6 | ## Additional Resources
7 |
8 | ### Further networking links and Literature
9 | * [https://medium.com/neoresearch/understanding-neo-network-in-five-pictures-e51b7c19d6e0](https://medium.com/neoresearch/understanding-neo-network-in-five-pictures-e51b7c19d6e0)
10 | * [https://github.com/neo-ngd/NEO-Tutorial](https://github.com/neo-ngd/NEO-Tutorial)
11 | * [https://en.wikipedia.org/wiki/NEO_(cryptocurrency)](https://en.wikipedia.org/wiki/NEO_(cryptocurrency))
12 | * [https://github.com/neo-project](https://github.com/neo-project)
13 | * [https://docs.neo.org/en-us/network/network-protocol.html](https://docs.neo.org/en-us/network/network-protocol.html)
14 | * [https://github.com/O3Labs/neo-transaction-watcher/blob/master/neotx/network.go](https://github.com/O3Labs/neo-transaction-watcher/blob/master/neotx/network.go)
15 |
--------------------------------------------------------------------------------
/en/5-network/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | lang: en
4 | lang-ref: network-index
5 | ---
6 |
7 | ## Contents
8 |
9 | 1. [Introduction to the NEO network protocol](1-Introduction_to_the_NEO_network_protocol.md)
10 | 2. [Developing a NEO Ping using Golang](2-Developing_a_NEO_ping_using_Golang.md)
11 |
12 | ## Additional Resources
13 |
14 | ### Further networking links and Literature
15 | * [https://medium.com/neoresearch/understanding-neo-network-in-five-pictures-e51b7c19d6e0](https://medium.com/neoresearch/understanding-neo-network-in-five-pictures-e51b7c19d6e0)
16 | * [https://github.com/neo-ngd/NEO-Tutorial](https://github.com/neo-ngd/NEO-Tutorial)
17 | * [https://en.wikipedia.org/wiki/NEO_(cryptocurrency)](https://en.wikipedia.org/wiki/NEO_(cryptocurrency))
18 | * [https://github.com/neo-project](https://github.com/neo-project)
19 | * [https://docs.neo.org/en-us/network/network-protocol.html](https://docs.neo.org/en-us/network/network-protocol.html)
20 | * [https://github.com/O3Labs/neo-transaction-watcher/blob/master/neotx/network.go](https://github.com/O3Labs/neo-transaction-watcher/blob/master/neotx/network.go)
21 |
--------------------------------------------------------------------------------
/en/6-persistence/persistence_1_byte.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/6-persistence/persistence_1_byte.png
--------------------------------------------------------------------------------
/en/6-persistence/persistence_3_bytes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/6-persistence/persistence_3_bytes.png
--------------------------------------------------------------------------------
/en/6-persistence/persistence_address.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/6-persistence/persistence_address.png
--------------------------------------------------------------------------------
/en/6-persistence/persistence_block.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/6-persistence/persistence_block.png
--------------------------------------------------------------------------------
/en/6-persistence/persistence_blockchain.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/6-persistence/persistence_blockchain.png
--------------------------------------------------------------------------------
/en/6-persistence/persistence_coin_reference.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/6-persistence/persistence_coin_reference.png
--------------------------------------------------------------------------------
/en/6-persistence/persistence_contract.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/6-persistence/persistence_contract.png
--------------------------------------------------------------------------------
/en/6-persistence/persistence_header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/6-persistence/persistence_header.png
--------------------------------------------------------------------------------
/en/6-persistence/persistence_memory_pool_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/6-persistence/persistence_memory_pool_1.png
--------------------------------------------------------------------------------
/en/6-persistence/persistence_snapshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/6-persistence/persistence_snapshot.png
--------------------------------------------------------------------------------
/en/6-persistence/persistence_var_string.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/6-persistence/persistence_var_string.png
--------------------------------------------------------------------------------
/en/7-consensus/1-Introduction_to_consensus.md:
--------------------------------------------------------------------------------
1 | ## Introduction to Consensus
2 |
3 | Multi-Agent Systems (MAS) are the core of Internet-of-Things (IoT), in which autonomous devices are able to interact with each other whilst following their own specific goals. Blockchain consensus operates in the same manner, where autonomous nodes aim to reach an agreement through a negotiation protocol despite the existence of selfish nodes attempting to maximize their own interests. Typically in the literature, MAS protocols are described as having three pillars for reaching agreements: voting, auction, and coordination.
4 |
5 | We believe that blockchain protocols are able to safely perform distributed rational decision making during the consensus process. In particular, this may happen if the right incentives are provided. Incentives are not just directly monetary (though rewards) but also involve prestige and the safeguarding of projects that participating nodes are interested in.
6 |
7 | In the case of NEO Consensus Nodes (CN), two key points of this interest can be raised, involving two different spheres:
8 |
9 | 1) Stakeholders interested in promoting their image as a reliability link for assisting the creation of blocks;
10 | 2) Nodes that want to increase their reputation among the NEO holders, which motivates holders to support their candidature and utilize their services.
11 |
12 | The consensus mechanism used by the NEO protocol, named Delegated Byzantine Fault Tolerance (dBFT), has its design rooted in the works of Practical Byzantine Fault Tolerance by Miguel Castro and Barbara Liskov around 1999.
13 |
14 | This tutorial will introduce the basic steps for understanding the importance of designing and developing such a mechanism for the NEO ecosystem.
15 |
16 | ## What we expect that you will learn
17 |
18 | After reading this material, it is expected that you will learn:
19 |
20 | - Distinguish Proof-of-Work and other consensus mechanisms based on coordination;
21 | - Learn more about cryptography and multi-sig accounts;
22 | - Learn about Byzantine Fault Tolerant systems;
23 | - Comprehend the design of a fully distributed network, in which consensus operates using digital signatures;
24 | - Understand the beauty of **one block finality**.
25 |
26 | [Next chapter](2-Proof_of_work_and_proof_of_stake.md) or [return to contents](README.md#contents).
27 |
--------------------------------------------------------------------------------
/en/7-consensus/2-Proof_of_work_and_proof_of_stake.md:
--------------------------------------------------------------------------------
1 | ## The Roots of Proof-of-Work
2 |
3 | Proof-of-Work was first mentioned by Satoshi Nakamoto as a mechanism that could combine CPU usage with voting, namely one-CPU-one-vote. The basic idea behind this is to create a protocol in which blocks are generating every `X` seconds. If blocks are generated faster or slower, difficulty would be altered.
4 |
5 | For instance, let's take the string `NEO Ecosystem` and convert it to a Hash256 `4bf65a74b608f6b785286b5da1d39ceb36ed87b62fee6ba97a65ecd4655b7661`.
6 | Now let's take the string `NEO Ecosystem+Nonce`, let's say `NEO Ecosystem+1` and we would get the following Hash256 `0739bcb67c6e934c669b95d65f1c98cdd67bcef0ef8ab22a7c1b4404f0e11450`.
7 | Next, we will test `NEO Ecosystem+12345678`, resulting in `011c65a33085565814548bc2860a1a3b1c68b627581381382447147788b0240c`, which has its beginning with `01`, less significative than `07`.
8 | Now, start to play with this nonce until you gets words that should start with `0000000000` and you are going to verify how hard this task is.
9 | Hashes are a kind of cryptographic signature for any data file, which has its basin on the classic SHA-256 algorithm that generates nearly unique fixed-size 32 bytes words.
10 | Hashes are so unidirectional that any known algorithm can revert its information, even with the assist of quantum computers.
11 |
12 | At the early times of BTC mining, in 2009, a standard computer could produce around 1 megahash per second.
13 | Since then, mining has evolved from GPUs, FPGAs and ASICs, reaching the impressive dedicated power of generating 13 TH/s per second, around 13000000 faster than in the beginning.
14 |
15 | If computers and knowledge dedicated in generating hashes has been evolving so drastically, why would not be the same for digital signatures and communication protocols?
16 | IoT has been a hot topic and focus of dedication of renowned researchers and industries, and its roots are related with communication and agreement between autonomous devices.
17 |
18 | The roots of NEO dBFT are digital signatures shared by a group of nodes (autonomous agents), which were selected by the majority of all NEO holders.
19 |
20 | ## Coordination x Proof-of-Stake x Voting
21 |
22 | Notoriously, the so-called Proof-of-Stake (PoS) based algorithms have similarities with what we mentioned about MAS in the introduction.
23 |
24 | The core idea of PoS is to leave decision making for those that have a larger financial stake in the Ecosystem, which would motivates them to keep the network running safely and efficiently.
25 | As can be noticed, if we turn this power to those that are part of the ecosystem we would have a similar PoS in which voting would be the main mechanism for selecting such nodes.
26 | The power of voting can even remove those that are acting as promised.
27 |
28 | Summarizing this, we should see that coordination is the core for reaching agreement in decentralized scenarios.
29 | Coordination not in the sense of a centralized coordinator, but in the sense that multiple goals are considered when a decision is being taken.
30 |
31 | [Next chapter](3-PBFT_and_DBFT.md) or [return to contents](README.md#contents).
32 |
--------------------------------------------------------------------------------
/en/7-consensus/3-PBFT_and_DBFT.md:
--------------------------------------------------------------------------------
1 | ## Practical Byzantine Fault Tolerance (pBFT)
2 |
3 | It has been argued that implementing a consensus fully based on an asynchronous system is not possible, in the work of *M. Fischer, N. Lynch, and M. Paterson*, "Impossibility of
4 | Distributed Consensus With One Faulty Process", in the Journal of the ACM, in 1985.
5 |
6 | In this sense, we must rely on a basic notion of synchrony for providing liveness.
7 |
8 | possible [9].
9 | We guarantee liveness, i.e., clients
10 |
11 | A brief summary of the pBFT follows of states can be seen in the .
12 |
13 | pBFT was designed for....
14 |
15 | ## Delegated Byzantine Fault Tolerance (dBFT)
16 |
17 | **Disclaimer:** *Part of the content of this tutorial has been extracted from the [dBFT formal specification](https://github.com/NeoResearch/yellowpaper/blob/master/sections/08_dBFT.md).*
18 |
19 | While the previous aforementioned liveness was proved for pBFT, the scenario in which dBFT works is a real-word large-scale public blockchain with state machine replication. The nature of the information shared is different and information can not be leaked. This required a refined and precisely designed recovery mechanism to be created for dBFT.
20 |
21 |
22 | The current dBFT 2.0 flow of states can be seen below: 
23 |
24 | ### One-block finality
25 |
26 | One block finality offers significant advantages for real-world applications. For example, end users, merchants, and exchanges can be confident that their transactions were definitively processed and settled, with no chance for them to be reverted. While the NEO blockchain has been designed for hosting Decentralized Applications (DApps), it is noteworthy that persisting SC transactions, which involves State Machine Replication (SMR) and is the core functionality of several DApps, poses a unique set of challenges. Maintaining block finality is a difficult task, as consensus nodes may not expose and reveal the information of duplicated blocks. Due to this, block signatures should be only provided when the majority of consensus nodes are already in an agreement.
27 |
28 | This problem has been called as the **indefatigable miners problem** (defined below):
29 |
30 | 1. The speaker is a Geological Engineer who is searching for a place to dig for Kryptonite;
31 | 1. He proposes a geographical location (coordinates to dig);
32 | 1. The majority (`M` guys) agrees with the coordinates (with their partial signatures);
33 | 1. Time to dig! The miners will now dig until they really find Kryptonite (no other location will be accepted to be dug until Kryptonite is found). Kryptonite is an infinitely divisible crystal, thus as soon as one miner finds some, he will share the Kryptonite so that everyone will have a piece to submit, finishing their contract (3.);
34 | 1. If one of the miners dies, it will resurrect, see the agreement it previously signed (3.), and will automatically start to dig again. The other miners will suffer the same, and also receive hidden messages saying that they should also dig.
35 |
36 | ### Blocking changing views and giving the network extra time
37 |
38 | For preserving liveness, and additional property needed to be ensured:
39 |
40 | - Nodes should be blocked to commit their signatures if they do not believe in the current network topology (asked `change_view`).
41 |
42 | However, in practice, summed up with the Commit phase locking, the dBFT had lost liveness in some case in which nodes were just with network problems.
43 | A workaround for this problem was to introduce a counting mechanism for checking committed nodes (easy to check) and failed nodes (those that you have not been in touch in the last blocks).
44 | This mechanism ensured an extra layer of protection before asking for changing view.
45 |
46 | Along with this, another strategy that has been designed was to avoid `change_views` when nodes are seeing progress on the network.
47 | In this sense, each time that nodes shared signed information between them, extra timeout are added to their internal timers, summarizing that nodes are reaching agreements and communicating between them.
48 |
49 | [Next chapter](4-Examples_and_consensus_scenarios_for_dBFT.md) or [return to contents](README.md#contents).
50 |
--------------------------------------------------------------------------------
/en/7-consensus/README.md:
--------------------------------------------------------------------------------
1 | ## Contents
2 |
3 | 1. [Introduction to Consensus](1-Introduction_to_consensus.md)
4 | 2. [Proof of Work and Proof of Stake](2-Proof_of_work_and_proof_of_stake.md)
5 | 3. [pBFT and dBFT](3-PBFT_and_DBFT.md)
6 | 4. [dBFT consensus examples and scenarios](4-Examples_and_consensus_scenarios_for_dBFT.md)
7 |
8 | ## Additional Resources
9 |
10 | ### Practical exercise (hands-on)
11 |
12 | We suggest that those who are interested in initializing, testing, and observing dBFT consensus take some time to view the [NeoCompiler-Eco Github](https://github.com/NeoResearch/neocompiler-eco), following its guidelines for setting up a local blockchain system.
13 |
14 | Follow the [README](https://github.com/NeoResearch/neocompiler-eco/blob/master/README.md) and the steps described therein to initialize the consensus nodes on your private network according to your desired specification.
15 |
--------------------------------------------------------------------------------
/en/7-consensus/cn_characters.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/7-consensus/cn_characters.jpg
--------------------------------------------------------------------------------
/en/7-consensus/multisig_3_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/7-consensus/multisig_3_4.png
--------------------------------------------------------------------------------
/en/7-consensus/scripthash_address.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/7-consensus/scripthash_address.png
--------------------------------------------------------------------------------
/en/7-consensus/watch-only-node.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/7-consensus/watch-only-node.png
--------------------------------------------------------------------------------
/en/8-nvm/README.md:
--------------------------------------------------------------------------------
1 | - NVM
2 | - What is NEO VM
3 | - The Neo virtual machine architecture
4 | - The NVM Instruction Set
5 | - Arithmatic operation
6 | - Stack operations
7 | - System operations
8 | - Logic operations
9 | - Environmental operations
10 | - Block operations
11 | - Gas Consumption During Execution
--------------------------------------------------------------------------------
/en/9-smartContract/Development_compile.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | lang: en
4 | lang-ref: Development_compile
5 | ---
6 |
7 | # Compile and Deploy the Smart Contract
8 |
9 | >
10 | > **Objective**: Know the process of compile, deploy and invoke the smart contract
11 | >
12 | > **Main points**:
13 | >
14 | > 1. Compile the smart contract to AVM
15 | >
16 | > 2. Deploy the smart contract use the GUI
17 | >
18 | > 3. Invoke the smart contract and get the result
19 | >
20 |
21 |
22 | ## Compiling contract file
23 |
24 | Let's go back to the visual studio and start to compile this simple project.
25 |
26 |
27 |
28 |
29 |
30 |
31 | Click `generate`->`generate solutions` (hotkeys: Ctrl + Shift + B) in the Visual Studio menu to start compilation.
32 |
33 |
34 | When the compilation is done, NEO smart contract file named`NEP5.avm` is generated in the `bin/Debug` directory of the project.
35 |
36 |
37 | `SmartContractDemo.abi.json` is a descriptive file of the smart contract, which contains descriptions of the ScriptHash, entry, parameters and return values of the contract. More information about the smart contract ABI can be found in [NeoContract ABI](https://github.com/neo-project/proposals/blob/master/nep-3.mediawiki).
38 |
39 |
40 |
41 |
42 |
43 | > [!!!!**Note**]
44 | >
45 | > Given that neon compiles .dll with nep-8 by default, which conflicts with nep-5, thus we need to execute .avm using nep-5 compatible method.
46 | >
47 | > Open Power Shell or command prompt (CMD), enter bin/Debug directory and input the following command (replace nep5.dll with your own project file):
48 | >
49 | > ```
50 | > neon SmartContractDemo.dll --compatible
51 | > ```
52 |
53 | > The new `SmartContractDemo.avm` file and `SmartContractDemo.abi.json` file will overwrite the old files.
54 |
55 |
56 | ## Deploy the contract
57 |
58 |
59 |
60 |
61 |
62 | We may use NEO-GUI to deploy the newly generated contract file.
63 |
64 | 1. Open 0.json wallet file, click `advance` -> `deploy contracts`.
65 |
66 | 2. Click `load` to select the compiled contract file `xxx.avm` in the contract deployment dialog.
67 |
68 | *Copy the contract script hash displayed under the code box for late use in contract invocation.*
69 |
70 | 3. Fill in the params in the information and meta data fields.
71 |
72 | For this contract, the argument is written as 0710 and the return value is 05.
73 |
74 | Detailed rules can be referred to [Smart Contract Parameters and Return Values](http://docs.neo.org/zh-cn/sc/Parameter.html)。
75 |
76 | Check the box of `required to create a storage area`/
77 |
78 | No need to check the options` require dynamic invocation`.
79 |
80 | 4. After all the params are defined, click `deploy` -> `test` -> `invoke`.
81 |
82 |
83 | #### Invoking contract
84 |
85 | Now you may invoke the smart contract released just recently.
86 |
87 | 1. Click `advance` -> `contract call` -> `function call`。
88 |
89 | 2. Paste the contract scripthash copied in the last step to `ScriptHash` and press search button. Relevant contract information will be displayed automatically.
90 |
91 | 3. Click `...` beside `arguments` to enter the edit interface. Fill in the argument. In this contract, any arguments is ok because the main method does not use that.
92 |
93 | 4. Click `trial` to test the contract. If no error is spotted, click `invoke`, which may cost several GAS.
94 |
95 |
96 | If invoke successfully, the gas will be reduced in the account balance.
97 |
98 | ## Next Step
99 | **Congratulations!**, you set up your private network and invoke your first smart contract successfully. Now let's begin to learn [the basic of NEO smart contract and get your first one.](Smart_Contract_basics.md)
100 |
101 | ## Previous Step
102 | If you are not set up the IDE yet , you may first click [here](Development_set_up.md).
103 |
--------------------------------------------------------------------------------
/en/9-smartContract/Development_set_up.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | lang: en
4 | lang-ref: Development_set_up
5 | ---
6 |
7 |
8 | # C# Smart contract development environment
9 |
10 | >
11 | > **Objective**: Meet the development requirements
12 | >
13 | > **Main points**:
14 | >
15 | > 1. System requirement
16 | >
17 | > 2. Visual Studio Setup
18 | >
19 | > 3. Neo-Compiler
20 | >
21 |
22 |
23 | For NEO C# developers, it is very fortune for them because NEO blockchain is build based on the C# and therefore, from compiler to toolbox, the C# development environment has been widely supported and it is very easy for those .NET developers begin to learn NEO Smart contract development. It is also easy for users who did not get touch with C# to begin his smart contract and Dapp.
24 |
25 | ## Environment
26 | For smart contract using C#, the best way is to develop with a local development environment with a IDE which support the NEO smart contract. Luckily, NEO is preparing a number of tools that achieve this. The only requirement for that is the operating system of your computer is Windows, preferred Windows 10 64 bit.
27 |
28 | For non-windows users, such as MAC and Linux users, the best choice is to use the online editor and compiler which is more convenient for smart contract developing and deploying. This will be detailed in this [document](https://medium.com/neweconolab/with-neoray-neo-smart-contract-development-has-never-been-easier-edad41cc3ae6).
29 |
30 |
31 |
32 | ### Windows
33 |
34 | In order to set-up a NEO private net and development environment, developer must install some dependencies:
35 |
36 | - [NET FrameWork](https://dotnet.microsoft.com/download/dotnet-framework-runtime/net472)
37 | - [NET Core](https://dotnet.microsoft.com/download)
38 |
39 | In addition, in order to develop the C# based smart contract, also we have to use the IDE and the best choice is Visual Studio:
40 |
41 | - [Microsoft Visual Studio](https://visualstudio.microsoft.com/vs/community/)
42 |
43 |
44 | Now let us prepare the smart contract development environment.
45 |
46 | ### Visual studio setup
47 |
48 | #### Install and open visual studio.
49 | Select `.NET Core cross-platform` development option during installation
50 |
51 |
52 |
53 |
54 |
55 | #### Install NeoContractPlugin
56 | Open Visual Studio 2017 and click `tool` -> `extensions and Updates`,click `online`on the left column, search NEO and install NeoContractPlugin (the process must be completed online).
57 |
58 |
59 |
60 |
61 |
62 | #### Configure neo-compiler
63 |
64 | 1. Download [neo-compiler](https://github.com/neo-project/neo-compiler) project to your localhost.
65 |
66 | 2. Click `file` -> `open` -> `project/solutions` in Visual Studio 2017 and select neo-compiler.sln in the project file.
67 |
68 | 3. Right click neon project in the list and click `release`.
69 |
70 | 4. After the release path is configured, click `release`.
71 |
72 | In my setting, a `neon.exe` file is generated in `xxx\neo-compiler-master\neo-compiler-master\neon\bin\Debug\netcoreapp2.0\publish`
73 |
74 | 5. Add the neon to the `PATH` in system environment.
75 |
76 | For Windows10, press `Windows+S`, input environment parameter and select edit the account's environment parameters, and add it to `Path`.
77 |
78 | #### Create a smart contract project
79 | 1. Click `file` -> `create` -> `project`.
80 | 2. Select `NeoContract` in the list and change settings where necessary, then click `confirm`.
81 |
82 |
83 | Â
84 |
85 |
86 | A C# file will be auto-generated after the project is created with a default class inherited from the SmartContract. As indicated in the screenshot below, now you have a Hello World contract.
87 |
88 |
89 |
90 |
91 |
92 | Nevertheless, the above only demonstrates a simple data storage method - to store data in private storage area using key-value method.
93 |
94 | ## Next Step
95 | **Congratulations!**, After set up the development tools, next step is to [compile the contract, deploy it and invoke it.](Development_compile.md)
96 |
97 | ## Previous Step
98 | If you are not set up the private chain yet , you may first click [here](Development_privateChain.md).
99 |
--------------------------------------------------------------------------------
/en/9-smartContract/README.md:
--------------------------------------------------------------------------------
1 | - Smart Contract
2 | - [What is smart contract](What_is_smart_contract.md)
3 | - [Write your NEO contact with any languages](What_is_smart_contract.md#write-smart-contracts-in-any-language)
4 | - [Prepare the development environment of your smart contract](Development_set_up.md)
5 | - Learn smart contract by demos in C#
6 | - [Smart Contract basic](Smart_Contract_basics.md)
7 | - [Smart contract structure](Smart_Contract_basics.md#contract-structure)
8 | - [Properties](Smart_Contract_basics.md#constract-property)
9 | - [Storage usage](Smart_Contract_basics.md#storage-property)
10 | - [Data types](Smart_Contract_basics.md#data-type)
11 | - [Your first NEO smart contract](Smart_Contract_basics.md)
12 | - [Method and triggers](Smart_Contract_basics.md#trigger)
13 | - [Events](Smart_Contract_basics.md#events)
14 |
15 | - Make your NEP-5 Token
16 | - [Introduction to NEP-5](What_is_nep5.md#introduction-to-nep-5)
17 | - [Implementation of NEP-5](What_is_nep5.md#implementation-of-nep-5)
18 | - [ITO(Initial Token Offering)](Give_an_ITO.md#give-an-ito-initial-token-offering)
19 | - [Timestamp in blockchain](Give_an_ITO.md#timestamp)
20 | - [UTXO basics](UTXO.md)
21 | - [Minting Tokens](Give_an_ITO.md#minttoken)
22 | - CGAS
23 | - [What is CGAS](cgas/1_what_is_cgas.md)
24 | - [Global asset and NEP-5](cgas/2_global_asset_and_nep5.md)
25 | - [UTXO model](cgas/3_utxo_model.md)
26 | - [Trigger](cgas/4_trigger.md)
27 | - [Mint and Refund](cgas/5_minttokens_and_refund.md)
28 | - [Signature and Verification](cgas/6_signature_and_verification.md)
29 | - [Transaction Invocation](cgas/7_invocation.md)
30 | - Write NEO smart contract with Python
31 | - what is Neo-python
32 | - Prepare the Neo-python development procedure environment
33 | - NEO python basics
34 | - Python smart contract example
35 | - Domain Name Service
36 | - Dapp demo based on neo python
37 | - Lucky neo
38 | - Write NEO smart contract with JS
39 | - Introduction of neo-one
40 | - neo-one smart contract example
41 | - ICO template
42 | - Escrow
43 | - Build a Dapp based on neo-one
44 | - Write NEO smart contract with Go.
45 | - Introduction to neo-storm framework
46 | - Issue a NEP5 token on using Go.
47 | - Build game on blockchain
48 | - The structure of blockchain game
49 | - Build a game with NEO + Unity
50 |
--------------------------------------------------------------------------------
/en/9-smartContract/UTXO.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | lang: en
4 | lang-ref: UTXO
5 | ---
6 |
7 | # UTXO
8 |
9 | >
10 | > **Objective**: Understand the idea of UTXO
11 | >
12 | > **Main points**:
13 | >
14 | > 1. The concept of UTXO
15 | > 2. The Stucture of UTXO in NEO
16 | >
17 | >
18 |
19 | ## The conept of UTXO
20 |
21 | If you are familiar with blockchain or use some digital coins before, you may hear of the word `UTXO`. The UTXO stands for **Unspent Transaction Output**, which means an output of a blockchain transaction that has not been spent and can be used as an input in a new transaction.
22 |
23 | When you use some digital coin wallets, you may see there is an account balance number. Actually, if it is a UTXO based blockchain, there is the concept of `account balance`. Actually the stored number is aggregated by the wallet application itself and the source it use is the UTXO. The concept of the UTXO is very similar to the wallet in the real life. Let's think you open your wallet, you see 100 dollars. You do not know where the 100 dollar come from. It might come from your customer as the payment for your website designing last week, and that is a UTXO which from you customer to you and the amount is 100 dollars. Then, you want to spent 10 dollar from your wallet to buy a magazine. After spent 10 dollars you get 90 dollar as change. Then the UTXO you have is 90 dollars. The 10 dollars you spent to the magazine shop becomes a UTXO to him until he spent it to his next transaction.
24 |
25 |
26 | ## UTXO in NEO
27 |
28 | The NEO blockchain supports native assets, the two most important ones being NEO and GAS. Native assets are Unspent Transaction Output (UTXO) based and are understood natively by the blockchain. Contrast this with tokens like the one we’ve built so far which live entirely in custom smart contracts. Unlike the account balance model, the UTXO model does not directly record account assets, but calculates user assets through unspent output. Each UTXO asset (such as a global asset) is an input-output association model, `input` specifies the source of funds, and `output` indicates the asset destination.
29 |
30 | In the picture below, Alice gets 8 GAS's share from her hold NEO, which is recorded in the first output in transaction *#101*. When Alice transfers 3 GAS to Bob, input of new transaction records the asset is 8 GAS, which is represented by output position 0 of transaction *#101*. Furthermore, in another transaction *#201*, one output points to the 3 GAS transferred to Bob, while another one to 5 GAS back to Alice herself (small change).
31 |
32 |
33 |
34 |
35 |
36 | Let's view the transaction structure in NEO. AS show in the picture above, the `output` itself has an index attributes because it is located in a list of outputs. The `output` it self consists of `AssetId`,`Amount` and `ScriptHash` which is the receipt address. The `Input` structure is the source of a transaction and it contains a `PreHash` which points to the transaction it comes from and a `Preindex` which points to the corresponding output from previous transaction
37 |
--------------------------------------------------------------------------------
/en/9-smartContract/cgas/2_global_asset_and_nep5.md:
--------------------------------------------------------------------------------
1 | # Global assets and NEP-5 assets
2 |
3 | Two types of assets are supported in NEO: global assets and NEP-5 assets.
4 |
5 | Global assets are the native assets supported by NEO. With a unified template, registration, issue, and transfer can be easily done by filling in the parameters in the neo-gui client. Global assets’ issuers can be identified by binding digital certificates. For example, a company can issue real-name certified assets such as stocks, vouchers, membership cards, etc. on NEO with a digital certificate issued by the CA authority. However, the cost is high. Taking the price of GAS 15 yuan as an example, the annual cost of issuing global assets is about 5000 * 15 = 75,000 yuan.
6 |
7 | In simple terms, the advantages of global assets are simplicity, security and supporting digital certificates, while the cost is high.
8 |
9 | NEP is called NEO Enhancement Proposals, and NEP-5 refers to the No.5 NEO enhancement proposal, named Token Standard, which specifies the asset specifications in smart contracts. NEP-5 assets are technically contract assets that meet the NEP-5 standards. It is the "asset" stipulated by the developer to register issue and transfer in the smart contract. The circulation, name, precision, and balance of all users are stored in the storage area of the smart contract. The security of the NEP-5 asset depends on the contract developer, who can open source the contract for community audit or not. To use NEP-5 assets means trusting developers not to do evil.
10 |
11 | In simple terms, NEP-5 assets have the advantages of high degree of freedom, supporting complex smart contracts and lower issuance costs, while they do not support digital certificates, with lower security than global assets.
12 |
13 | For an introduction to NEP-5, you can refer to previous tutorials or [GitHub](https://github.com/neo-project/proposals/blob/master/nep-5.mediawiki).
14 |
15 | Here is a systematic comparison of the two assets
16 |
17 | | | Global assets | NEP-5 assets |
18 | | ------------------------ | ----------------------- | ------------------------ |
19 | | Time to start support | native support | Since 2.0 |
20 | | Supposed time to end support | Since NEO 3.0 | |
21 | | Representative assets | NEO、GAS | CGAS、SDUSD、NNC、PHX, etc. |
22 | | Registration fee | 5000GAS/year | 500~1000 GAS |
23 | | Model to store records | UTXO | Balance |
24 | | Security | High | Depends on contract developers |
25 | | Functions | Simple | Complicated |
26 | | Identification via digital certificates | Support | Not support |
27 | | Transfer through smart contracts | No | yes |
28 | | | | |
29 | | | | |
30 |
31 |
32 | ## Next Step
33 | In order to learn the how the UTXO is working in CGAS, we move to [here](3_utxo_model.md)
34 |
35 | ## Previous Step
36 | If you want to know what is CGAS, click [here](1_what_is_cgas.md).
37 |
--------------------------------------------------------------------------------
/en/9-smartContract/cgas/3_utxo_model.md:
--------------------------------------------------------------------------------
1 | # UTXO usage in the CGAS
2 |
3 | As explained in the [UTXO basics](https://github.com/neo-ngd/NEO-Tutorial/blob/master/9-smartContract/UTXO.md), the global asset used in the NEO system is UTXO based and the transaction used in the NEO is divided into transaction input and transaction output.
4 |
5 | In the CGAS, the UTXO is used in several way. The first usage is in the `MintToken` method, which is to receive the global asset here.
6 |
7 | Here we first get the references for the current transaction.
8 | ```csharp
9 | var references = tx.GetReferences();
10 | ```
11 |
12 | The `tx.GetRenferences` method is actually get the `outputs` of other transaction that construct the inputs of current transaction. Therefore, each reference here contains an AssetId which indicate the type of asset, and an ScriptHash which indicates the receiver of that output.
13 |
14 | In the mintToken method, the `Reference` is used to track the user's address and the type of the asset that send to the CGAS contract. In order to get the amount of the global asset that send to current CGAS contract, we have to use the `Outputs` of current transaction trough the api tx.GetOutputs(). In each output of current transaction, compare the scriptHash with the CGAS scriptHash and the AssetId, and then sum the value of each output.
15 |
16 | ```csharp
17 | //Amount of exchange
18 | var outputs = tx.GetOutputs();
19 | ulong value = 0;
20 | foreach (var output in outputs)
21 | {
22 | if (output.ScriptHash == ExecutionEngine.ExecutingScriptHash &&
23 | output.AssetId.AsBigInteger() == AssetId.AsBigInteger())
24 | {
25 | alue += (ulong)output.Value;
26 | }
27 | }
28 | ```
29 |
30 | The other UTXO used in the CGAS contract is in the refund step. Here we only indicates the knowledge of UTXO in the refund, the detailed principle of refund will be explained in [here](5_minttokens_and_refund.md). In the refund step, in the verification trigger, it will check the marker UTXO using the `inputs`. In the UTXO model of NEO, the input structure is more like a pointer which points to the output of previous transaction which it comes from. It has two fields, the `PrevHash` which indicates the transaction hash and the `PrevIndex` which indicates the corresponding output's position.
31 |
32 | ```csharp
33 | foreach (var input in inputs)
34 | {
35 | if (input.PrevIndex == 0)//If UTXO n is 0, it is possible to be a marker UTXO
36 | {
37 | StorageMap refund = Storage.CurrentContext.CreateMap(nameof(refund));
38 | var refundMan = refund.Get(input.PrevHash); //0.1
39 | //If the input that is marked for refund
40 | if (refundMan.Length > 0)
41 | {
42 | //Only one input and one output is allowed in refund
43 | if (inputs.Length != 1 || outputs.Length != 1)
44 | return false;
45 | return outputs[0].ScriptHash.AsBigInteger() == refundMan.AsBigInteger();
46 | }
47 | }
48 | }
49 | ```
50 |
51 | ## Next Step
52 | In order to learn how the trigger is working in CGAS, we move to [here](4_trigger.md)
53 |
54 | ## Previous Step
55 | If you want to know what is difference between global asset and NEP5, click [here](2_global_asset_and_nep5.md).
56 |
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/20190219-112142.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/20190219-112142.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/20190219-113025.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/20190219-113025.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/20190219-120404.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/20190219-120404.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/20190219-120735.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/20190219-120735.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/20190219-140640.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/20190219-140640.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/20190219-140958.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/20190219-140958.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/20190222-153331.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/20190222-153331.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/20190222-153712.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/20190222-153712.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/20190222-153941.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/20190222-153941.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/20190222-154922.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/20190222-154922.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/20190222-155235.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/20190222-155235.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/20190222-155608.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/20190222-155608.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/check.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/check.gif
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/check.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/check.jpg
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/newbie.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/newbie.jpg
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/plugin.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/plugin.jpg
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/smart-contracts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/smart-contracts.png
--------------------------------------------------------------------------------
/en/9-smartContract/imgs/vs.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/9-smartContract/imgs/vs.jpg
--------------------------------------------------------------------------------
/en/9-smartContract/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | lang: en
4 | lang-ref: sc-index
5 | ---
6 |
7 | - Smart Contract
8 | - [What is smart contract](What_is_smart_contract.md)
9 | - [Write your NEO contact with any languages](What_is_smart_contract.md#write-smart-contracts-in-any-language)
10 | - [Prepare the development environment of your smart contract](Development_set_up.md)
11 | - Learn smart contract by demos in C#
12 | - [Smart Contract basic](Smart_Contract_basics.md)
13 | - [Smart contract structure](Smart_Contract_basics.md#contract-structure)
14 | - [Properties](Smart_Contract_basics.md#constract-property)
15 | - [Storage usage](Smart_Contract_basics.md#storage-property)
16 | - [Data types](Smart_Contract_basics.md#data-type)
17 | - [Your first NEO smart contract](Smart_Contract_basics.md#Your first NEO contract)
18 | - [Method and triggers](Smart_Contract_basics.md#trigger)
19 | - [Events](Smart_Contract_basics.md#events)
20 |
21 | - Make your NEP-5 Token
22 | - [Introduction to NEP-5](What_is_nep5.md#introduction-to-nep-5)
23 | - [Implementation of NEP-5](What_is_nep5.md#implementation-of-nep-5)
24 | - [ITO(Initial Token Offering)](Give_an_ITO.md#give-an-ito-initial-token-offering)
25 | - [Timestamp in blockchain](Give_an_ITO.md#timestamp)
26 | - [UTXO basics](UTXO.md)
27 | - [Minting Tokens](Give_an_ITO.md#minttoken)
28 | - CGAS
29 | - [What is CGAS](cgas/1_what_is_cgas.md)
30 | - [Global asset and NEP-5](cgas/2_global_asset_and_nep5.md)
31 | - [UTXO model](cgas/3_utxo_model.md)
32 | - [Trigger](cgas/4_trigger.md)
33 | - [Mint and Refund](cgas/5_minttokens_and_refund.md)
34 | - [Signature and Verification](cgas/6_signature_and_verification.md)
35 | - [Transaction Invocation](cgas/7_invocation.md)
36 | - Write NEO smart contract with Python
37 | - what is Neo-python
38 | - Prepare the Neo-python development procedure environment
39 | - NEO python basics
40 | - Python smart contract example
41 | - Domain Name Service
42 | - Dapp demo based on neo python
43 | - Lucky neo
44 | - Write NEO smart contract with JS
45 | - Introduction of neo-one
46 | - neo-one smart contract example
47 | - ICO template
48 | - Escrow
49 | - Build a Dapp based on neo-one
50 | - Write NEO smart contract with Go.
51 | - Introduction to neo-storm framework
52 | - Issue a NEP5 token on using Go.
53 | - Build game on blockchain
54 | - The structure of blockchain game
55 | - Build a game with NEO + Unity
56 |
--------------------------------------------------------------------------------
/en/dapp_demo/README.md:
--------------------------------------------------------------------------------
1 | # An NEO Dapp demo
2 |
3 | This is a repository for a petshop Dapp demo which is running on NEO blockchain. The project itself does not contain any business purpose and is only used for learning. The project is utilizing following things :
4 |
5 | - [NEO-local](https://github.com/CityOfZion/neo-local) - A quickly fired NEO privateNet and block explorer
6 | - [NEO-python](https://github.com/CityOfZion/neo-python) - Python Node and SDK for the NEO blockchain.
7 | - [NEO-boa](https://github.com/CityOfZion/neo-boa) - Python compiler for the Neo Virtual Machine
8 | - [NEON-js](https://github.com/CityOfZion/neon-js) - JS SDK for the NEO blockchain platform.
--------------------------------------------------------------------------------
/en/dapp_demo/Screenshot 2019-04-16 at 2.29.54 PM.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/Screenshot 2019-04-16 at 2.29.54 PM.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/Chalkboard-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/Chalkboard-Bold.ttf
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/+.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/+.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/1-1.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/2-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/2-1.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/3-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/3-1.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/4-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/4-1.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/BG.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/BG.jpg
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/HOME-ICON/1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/HOME-ICON/1-1.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/HOME-ICON/2-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/HOME-ICON/2-2.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/HOME-ICON/3-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/HOME-ICON/3-3.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/HOME-ICON/4-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/HOME-ICON/4-4.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/LOGININ/BG.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/LOGININ/BG.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/LOGININ/cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/LOGININ/cancel.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/LOGININ/log_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/LOGININ/log_back.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/NEO.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/NEO.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/NEOHOUSE.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/NEOHOUSE.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/buy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/buy.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/buy_diamonds/BG.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/buy_diamonds/BG.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/buy_diamonds/Buy Button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/buy_diamonds/Buy Button.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/buy_diamonds/input_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/buy_diamonds/input_back.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/buy_diamonds/minus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/buy_diamonds/minus.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/buy_diamonds/plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/buy_diamonds/plus.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/diamond.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/diamond.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/login.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/login.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/popup/Button No.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/popup/Button No.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/popup/Button Yes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/popup/Button Yes.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/popup_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/popup_bg.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/privatenet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/privatenet.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/数量框背景.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/数量框背景.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/树.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/树.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/模板背景.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/模板背景.png
--------------------------------------------------------------------------------
/en/dapp_demo/resources/neo-house/草.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/en/dapp_demo/resources/neo-house/草.png
--------------------------------------------------------------------------------
/en/dapp_demo/smart-contract/NEP.py:
--------------------------------------------------------------------------------
1 | from boa.interop.Neo.Storage import Get, Put, Delete, GetContext
2 | from boa.interop.Neo.Runtime import Notify, CheckWitness, Serialize, Deserialize, Log
3 | from boa.interop.Neo.Action import RegisterAction
4 | from boa.interop.System.ExecutionEngine import GetScriptContainer, GetExecutingScriptHash
5 | from boa.interop.Neo.Transaction import Transaction, GetReferences, GetOutputs, GetUnspentCoins
6 | from boa.interop.Neo.Output import GetValue, GetAssetId, GetScriptHash
7 | from boa.builtins import concat
8 |
9 | ctx = GetContext()
10 |
11 | OnTransfer = RegisterAction('transfer', 'addr_from', 'addr_to', 'amount')
12 |
13 | TOKEN_DECIMALS = 8
14 | # Name of the Token
15 | TOKEN_NAME = 'NGD PET'
16 | # Symbol of the Token
17 | TOKEN_SYMBOL = 'NPT'
18 |
19 | TOKEN_INITIAL_SUPPLY = 1000 * 100000000 # 10m total supply * 10^8 ( decimals)
20 |
21 | TOKEN_OWNER = b'#\xba\'\x03\xc52c\xe8\xd6\xe5"\xdc2 39\xdc\xd8\xee\xe9'
22 |
23 | NEO_ASSET_ID= b'\x9b|\xff\xda\xa6t\xbe\xae\x0f\x93\x0e\xbe`\x85\xaf\x90\x93\xe5\xfeV\xb3J\\"\x0c\xcd\xcfn\xfc3o\xc5'
24 |
25 | def buyCat(from_acc, animal, amount):
26 | if not CheckWitness(from_acc):
27 | Notify("Not the owner, can't buy")
28 | return False
29 |
30 | tmplist = Get(ctx, from_acc + "CAT")
31 | if len(tmplist) != 0:
32 | delist = Deserialize(tmplist)
33 | Notify(delist)
34 | delist.append(animal)
35 | Notify(delist)
36 | Put(ctx, from_acc + "CAT", Serialize(delist))
37 | else:
38 | Put(ctx, from_acc + "CAT", Serialize([animal]))
39 | Notify(Serialize([animal]))
40 |
41 | current_balance = Get(ctx, from_acc)
42 | if current_balance <= amount:
43 | Notify("Insufficient funds")
44 | return False
45 | to_balance = Get(ctx, TOKEN_OWNER)
46 | to_balance += amount
47 | Put(ctx, TOKEN_OWNER, to_balance)
48 | current_balance -= amount
49 | if current_balance != 0:
50 | Put(ctx, from_acc, current_balance)
51 | else:
52 | Delete(ctx, from_acc)
53 | OnTransfer(from_acc, TOKEN_OWNER, amount)
54 | return True
55 |
56 | def checkCat(owner):
57 | exists = Get(ctx, owner + "CAT")
58 | if len(exists) != 0:
59 | tmp = Deserialize(exists)
60 | Notify(tmp)
61 | return exists
62 | return False
63 |
64 | def deploy():
65 | if not Get(ctx,"initialized"):
66 | Put(ctx, 'initialized', 1)
67 | Put(ctx, TOKEN_OWNER,TOKEN_INITIAL_SUPPLY)
68 | return True
69 | return False
70 |
71 | def balanceOf(acc):
72 | itemValue = Get(ctx, acc)
73 | if len(itemValue) != 0:
74 | return itemValue
75 | return 0
76 |
77 | def exchange_token():
78 | tx = GetScriptContainer()
79 | references = tx.References
80 | sender_addr = None
81 | receiver_addr = GetExecutingScriptHash()
82 | sent_amount_neo = 0
83 | sender_addr = 1
84 | neo_amount = 0
85 | if len(references) > 0:
86 | reference = references[0]
87 | sender_addr = reference.ScriptHash
88 | for output in tx.Outputs:
89 | if output.ScriptHash == receiver_addr:
90 | neo_amount += output.Value
91 | if neo_amount == 0:
92 | return false
93 | exchanged_amount = neo_amount * 10
94 | current_balance = Get(ctx, sender_addr)
95 | Put(ctx, sender_addr, current_balance + exchanged_amount)
96 | return True
97 |
98 | def Main(operation, args):
99 | if operation == "totalSupply":
100 | return TOKEN_TOTAL_SUPPLY
101 |
102 | if operation == "name":
103 | return TOKEN_NAME
104 |
105 | if operation == "symbol":
106 | return TOKEN_SYMBOL
107 |
108 | if operation == "decimals":
109 | return TOKEN_DECIMALS
110 |
111 | if operation == "buyCat":
112 | return buyCat(from_acc = args[0], animal = args[1],amount = args[2])
113 |
114 | if operation == "checkCat":
115 | return checkCat(owner = args[0])
116 |
117 | if operation == "deploy":
118 | return deploy()
119 |
120 | if operation == "balanceOf":
121 | return balanceOf(args[0])
122 |
123 | if operation == "exchange_token":
124 | return exchange_token()
125 |
126 | return "Undefined operation."
--------------------------------------------------------------------------------
/en/dapp_demo/src/index.js:
--------------------------------------------------------------------------------
1 | function openTab(event, pageName) {
2 | var i, tabcontent, tablinks;
3 | tabcontents = document.getElementsByClassName("tab-content");
4 | for ( i = 0; i < tabcontents.length; i++) {
5 | tabcontents[i].style.display = "none";
6 | }
7 | tablinks = document.getElementsByClassName("tablinks");
8 | for (i = 0; i < tablinks.length; i++) {
9 | tablinks[i].className = tablinks[i].className.replace(" active", "");
10 | }
11 | document.getElementById(pageName).style.display = "block";
12 | event.currentTarget.className += " active";
13 | }
14 |
15 | document.getElementById("defaultOpen").click();
--------------------------------------------------------------------------------
/en/dapp_demo/src/itemsInfo.js:
--------------------------------------------------------------------------------
1 | const ITEMS = [
2 | {
3 | name: 'Alice',
4 | image: './resources/neo-house/1-1.png',
5 | homeIcon: './resources/neo-house/HOME-ICON/1-1.png',
6 | price: 20
7 | },
8 | {
9 | name: 'Bob',
10 | image: './resources/neo-house/2-1.png',
11 | homeIcon: './resources/neo-house/HOME-ICON/2-2.png',
12 | price: 25
13 | },
14 | {
15 | name: 'Cindy',
16 | image: './resources/neo-house/3-1.png',
17 | homeIcon: './resources/neo-house/HOME-ICON/3-3.png',
18 | price: 100
19 | },
20 | {
21 | name: 'Dan',
22 | image: './resources/neo-house/4-1.png',
23 | homeIcon: './resources/neo-house/HOME-ICON/4-4.png',
24 | price: 500
25 | }
26 | ];
--------------------------------------------------------------------------------
/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/favicon.ico
--------------------------------------------------------------------------------
/index.cn.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | lang: cn
4 | lang-ref: NEO-Tutorial
5 | ---
6 |
7 |
8 |
NEO-Tutorial
9 |
10 |
A complete learning tutorial for NEO developers and learners