├── .gitignore ├── Gemfile ├── LICENSE ├── README.md ├── Standard.md ├── _config.yml ├── _data └── languages.yml ├── _includes └── header.html ├── _layouts ├── default.html └── post.html ├── cn ├── 1-introduction │ ├── README.md │ └── index.md ├── 2-wallet │ ├── 1-钱包介绍.md │ ├── 2-NEO私钥和地址生成.md │ ├── 3-密钥加密与合约账户.md │ ├── 4-UTXO与账户模型.md │ ├── README.md │ └── index.md ├── 3-transaction │ ├── 1-交易介绍.md │ ├── 2-NEO交易结构.md │ ├── 3-NEO交易类型.md │ ├── 4-NEO交易费用.md │ ├── README.md │ └── index.md ├── 4-blocks │ ├── 1-区块与区块链介绍.md │ ├── 2-区块结构.md │ ├── 3-区块创建与广播.md │ ├── 4-区块验证与处理.md │ ├── README.md │ ├── block-info.png │ ├── index.md │ ├── merkle-tree.png │ ├── neo-block.json │ ├── txn-with-fee.png │ └── 默克尔树.md ├── 5-network │ ├── 1-NEO网络协议介绍.md │ ├── 2-使用Golang实现NEO-ping功能.md │ ├── README.md │ └── index.md ├── 6-persistence │ ├── README.md │ ├── README2.md │ ├── persistence_1_byte.png │ ├── persistence_3_bytes.png │ ├── persistence_address.png │ ├── persistence_block.png │ ├── persistence_blockchain.png │ ├── persistence_coin_reference.png │ ├── persistence_contract.png │ ├── persistence_header.png │ ├── persistence_memory_pool_1.png │ ├── persistence_snapshot.png │ └── persistence_var_string.png ├── 7-consensus │ ├── 1-共识介绍.md │ ├── 2-工作量证明与权益证明.md │ ├── 3-pBFT与dBFT.md │ ├── 4-dBFT共识示例与场景.md │ ├── README.md │ ├── cn_characters.jpg │ ├── multisig_3_4.png │ ├── scripthash_address.png │ └── watch-only-node.png ├── 8-nvm │ └── README.md └── 9-smartContract │ ├── Development_compile.md │ ├── Development_privateChain.md │ ├── Development_set_up.md │ ├── Give_an_ITO.md │ ├── Implementation_of_NEP5.md │ ├── NFT.md │ ├── README.md │ ├── Smart_Contract_basics.md │ ├── UTXO.md │ ├── What_is_nep5.md │ ├── What_is_smart_contract.md │ ├── cgas-cn │ ├── 1_what_is_cgas.md │ ├── 2_global_asset_and_nep5.md │ ├── 3_utxo_model.md │ ├── 4_trigger.md │ ├── 5_minttokens_and_refund.md │ ├── 6_signature_and_verification.md │ └── 7_test_and_invocation.md │ ├── imgs │ ├── 20190219-112142.png │ ├── 20190219-113025.png │ ├── 20190219-120404.png │ ├── 20190219-120735.png │ ├── 20190219-140640.png │ ├── 20190219-140958.png │ ├── 20190222-153331.png │ ├── 20190222-153712.png │ ├── 20190222-153941.png │ ├── 20190222-154922.png │ ├── 20190222-155235.png │ ├── 20190222-155608.png │ ├── check.gif │ ├── check.jpg │ ├── newbie.jpg │ ├── plugin.jpg │ ├── smart-contracts.png │ └── vs.jpg │ └── index.md ├── en ├── 1-introduction │ ├── 1-Introduction_to_NEO.md │ ├── 2-Cryptography_Blockchain_and_Smart_Contracts.md │ ├── 3-Fundamentals_of_NEO.md │ ├── 4-NEO_Tutorial.md │ ├── README.md │ └── index.md ├── 2-wallet │ ├── 1-Introduction_to_wallets.md │ ├── 2-Key_derivation_and_address_generation_on_NEO.md │ ├── 3-Key_encryption_and_contract_accounts.md │ ├── 4-UTXO_and_account_models.md │ ├── README.md │ └── index.md ├── 3-transactions │ ├── 1-Introduction_to_transactions.md │ ├── 2-Structure_of_NEO_transactions.md │ ├── 3-NEO_transaction_types.md │ ├── 4-NEO_transaction_fees.md │ ├── README.md │ └── index.md ├── 4-blocks │ ├── 1-Introduction_to_blocks_and_blockchain.md │ ├── 2-Structure_of_a_block.md │ ├── 2a-Merkle-Tree.md │ ├── 3-Block_creation_broadcasting.md │ ├── 4-Block_validation_processing.md │ ├── README.md │ ├── block-info.png │ ├── index.md │ ├── merkle-tree.png │ ├── neo-block.json │ └── txn-with-fee.png ├── 5-network │ ├── 1-Introduction_to_the_NEO_network_protocol.md │ ├── 2-Developing_a_NEO_ping_using_Golang.md │ ├── README.md │ └── index.md ├── 6-persistence │ ├── README.md │ ├── README2.md │ ├── persistence_1_byte.png │ ├── persistence_3_bytes.png │ ├── persistence_address.png │ ├── persistence_block.png │ ├── persistence_blockchain.png │ ├── persistence_coin_reference.png │ ├── persistence_contract.png │ ├── persistence_header.png │ ├── persistence_memory_pool_1.png │ ├── persistence_snapshot.png │ └── persistence_var_string.png ├── 7-consensus │ ├── 1-Introduction_to_consensus.md │ ├── 2-Proof_of_work_and_proof_of_stake.md │ ├── 3-PBFT_and_DBFT.md │ ├── 4-Examples_and_consensus_scenarios_for_dBFT.md │ ├── README.md │ ├── cn_characters.jpg │ ├── multisig_3_4.png │ ├── scripthash_address.png │ └── watch-only-node.png ├── 8-nvm │ └── README.md ├── 9-smartContract │ ├── Development_compile.md │ ├── Development_privateChain.md │ ├── Development_set_up.md │ ├── Give_an_ITO.md │ ├── Implementation_of_NEP5.md │ ├── NFT.md │ ├── README.md │ ├── Smart_Contract_basics.md │ ├── UTXO.md │ ├── What_is_nep5.md │ ├── What_is_smart_contract.md │ ├── cgas │ │ ├── 1_what_is_cgas.md │ │ ├── 2_global_asset_and_nep5.md │ │ ├── 3_utxo_model.md │ │ ├── 4_trigger.md │ │ ├── 5_minttokens_and_refund.md │ │ ├── 6_signature_and_verification.md │ │ └── 7_invocation.md │ ├── imgs │ │ ├── 20190219-112142.png │ │ ├── 20190219-113025.png │ │ ├── 20190219-120404.png │ │ ├── 20190219-120735.png │ │ ├── 20190219-140640.png │ │ ├── 20190219-140958.png │ │ ├── 20190222-153331.png │ │ ├── 20190222-153712.png │ │ ├── 20190222-153941.png │ │ ├── 20190222-154922.png │ │ ├── 20190222-155235.png │ │ ├── 20190222-155608.png │ │ ├── check.gif │ │ ├── check.jpg │ │ ├── newbie.jpg │ │ ├── plugin.jpg │ │ ├── smart-contracts.png │ │ └── vs.jpg │ ├── index.md │ └── sourceCode │ │ ├── ITO.cs │ │ ├── NEP5.cs │ │ └── nft.cs └── dapp_demo │ ├── README.md │ ├── Screenshot 2019-04-16 at 2.29.54 PM.png │ ├── dapp.md │ ├── index.html │ ├── resources │ ├── Chalkboard-Bold.ttf │ └── neo-house │ │ ├── +.png │ │ ├── 1-1.png │ │ ├── 2-1.png │ │ ├── 3-1.png │ │ ├── 4-1.png │ │ ├── BG.jpg │ │ ├── HOME-ICON │ │ ├── 1-1.png │ │ ├── 2-2.png │ │ ├── 3-3.png │ │ └── 4-4.png │ │ ├── LOGININ │ │ ├── BG.png │ │ ├── cancel.png │ │ └── log_back.png │ │ ├── NEO.png │ │ ├── NEOHOUSE.png │ │ ├── buy.png │ │ ├── buy_diamonds │ │ ├── BG.png │ │ ├── Buy Button.png │ │ ├── input_back.png │ │ ├── minus.png │ │ └── plus.png │ │ ├── diamond.png │ │ ├── login.png │ │ ├── popup │ │ ├── Button No.png │ │ └── Button Yes.png │ │ ├── popup_bg.png │ │ ├── privatenet.png │ │ ├── 数量框背景.png │ │ ├── 树.png │ │ ├── 模板背景.png │ │ └── 草.png │ ├── smart-contract │ ├── NEOSHOP.cs │ └── NEP.py │ └── src │ ├── app.js │ ├── bundleDemo.js │ ├── index.css │ ├── index.js │ ├── itemsInfo.js │ └── neon.js ├── favicon.ico ├── index.cn.md ├── index.md ├── neo-rebranding.png ├── neo_color_dark.png ├── neo_docs_SmartContract_QuickStart ├── 2_gui_4.png ├── 2_privatechain_12.jpg ├── 2_privatechain_14.jpg ├── 2_privatechain_20.jpg ├── 2_privatechain_21.jpg ├── 2_privatechain_26.jpg ├── 2_privatechain_demo.png ├── 2_wallet_height.png ├── 3_1545037391347.png ├── 3_1545632430020.png ├── 3_1545633970239.png ├── 3_1546846629992.png ├── 3_2017-06-07_12-07-03.png ├── 3_check_nep5.png ├── 3_download_and_install_smart_contract_plugin.jpg ├── 3_edit_environment_variable.png ├── 3_environment_variable.png ├── 3_install_core_cross_platform_development_toolset.jpg ├── 3_new_smart_contract_project.png ├── 3_publish_and_profile_settings.jpg ├── 3_publish_and_profile_settings.png ├── 3_publish_neo_compiler_msil_project.jpg ├── 3_smart_contract_function_code.png ├── README.md ├── SmartContract_quickStart_cn.md ├── SmartContract_quickstart_en.md ├── compile.png ├── contractfile.png ├── deploy.png └── nep5.png └── neo_docs_neopython_tutorial ├── NeoPythonGuide ├── 1.png ├── 10.png ├── 11.png ├── 12.png ├── 13.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png └── 9.png ├── README.md ├── assets ├── build_contract1.png ├── build_test_contract1.png ├── build_test_contract2.png ├── build_test_contract3.png ├── built_test_contract4_1.png ├── built_test_contract4_2.png ├── built_test_contract4_3.png ├── claim_gas.png ├── contract_hash.png ├── contract_search.png ├── create_wallet.png ├── deploy_contract1.png ├── deployed_contract1.png ├── docker_pull.png ├── initialising.png ├── invoke_contract3.png ├── invoke_contract4_1.png ├── invoke_contract4_2.png ├── invoke_contract5_delete.png ├── invoke_contract5_delete_query.png ├── invoke_contract5_query.png ├── invoke_contract5_register.png ├── invoke_contract5_transfer.png ├── invoke_contract5_transfer_query.png ├── new_domain_wallet.png ├── open_wallet.png ├── own_wallet_with_assets.png ├── sc1.png ├── scripthash_to_address.png ├── scripthash_to_address2.png ├── scripthash_to_address3.png ├── send_assets.png ├── smartcontracts_in_neopy.png ├── started.png ├── testinvoke_contract1.png ├── testinvoke_success_contract1.png ├── wallet_address_box.png ├── wallet_claimed_gas.png ├── wallet_claimed_gas_box.png ├── wallet_content.png └── wallet_content_box.png ├── neo_python_quickstart_cn.md ├── part1_setup.md ├── part2_neopy.md └── smart-contracts ├── 1-print.py ├── 2-print-and-notify.py ├── 3-calculator.py ├── 4-storage.py └── 5-domain.py /.gitignore: -------------------------------------------------------------------------------- 1 | _site 2 | Gemfile.lock 3 | .DS_Store 4 | .vscode 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'github-pages', group: :jekyll_plugins 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 NEO GLOBAL DEVELOPMENT 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

NEO-Tutorial

3 | NEO-Tutorial 4 |

A complete learning tutorial for NEO developers and learners

5 |
6 | 7 | ## Table of Tutorials 8 | - [Introduction to NEO](en/1-introduction) 9 | - [Wallet](en/2-wallet) 10 | - [Transactions](en/3-transactions) 11 | - [Blocks](en/4-blocks) 12 | - [Network](en/5-network) 13 | - [Persistence](en/6-persistence) 14 | - [Consensus](en/7-consensus) 15 | - [NVM](en/8-nvm) 16 | - [Smart Contract](en/9-smartContract) 17 | 18 | ## Smart contract development Learning Resources 19 | - [Neo Smart contract quick start](neo_docs_SmartContract_QuickStart) 20 | - [Neo-python tutorial](neo_docs_neopython_tutorial) 21 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /_data/languages.yml: -------------------------------------------------------------------------------- 1 | en: 2 | label: English 3 | cn: 4 | label: 中文 -------------------------------------------------------------------------------- /_includes/header.html: -------------------------------------------------------------------------------- 1 | 2 | {% assign posts=site.posts | where:"lang-ref", page.lang-ref | sort: 'lang' %} 3 | {% if posts.size == 0 %} 4 | {% assign posts=site.pages | where:"lang-ref", page.lang-ref | sort: 'lang' %} 5 | {% endif %} 6 | {% if posts.size > 1 %} 7 |
8 |
9 | {% for post in posts %} 10 | {{ site.data.languages[post.lang].label }} 11 | {% endfor %} 12 | 13 | 14 | 15 |  Edit this page 16 | 17 | 18 |
19 |
20 | {% endif %} 21 | -------------------------------------------------------------------------------- /_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {% if site.google_analytics %} 5 | 6 | 12 | {% endif %} 13 | 14 | {% seo %} 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 29 |
30 | {{ content }} 31 | 35 |
36 | 37 | 38 | -------------------------------------------------------------------------------- /_layouts/post.html: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | --- 4 | 5 |
6 | {{ content }} 7 |
8 | -------------------------------------------------------------------------------- /cn/1-introduction/README.md: -------------------------------------------------------------------------------- 1 | - NEO介绍 2 | - 加密算法与加密货币介绍 3 | - NEO 4 | - 历史 5 | - 白皮书 6 | - 特性 7 | - 文档 -------------------------------------------------------------------------------- /cn/1-introduction/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: cn 4 | lang-ref: NEO-intro 5 | --- 6 | 7 | - NEO介绍 8 | - 加密算法与加密货币介绍 9 | - NEO 10 | - 历史 11 | - 白皮书 12 | - 特性 13 | - 文档 14 | -------------------------------------------------------------------------------- /cn/2-wallet/1-钱包介绍.md: -------------------------------------------------------------------------------- 1 | # 了解钱包 2 | 在与NEO或其他区块链交互前,用户必须在他们的本地机器上创建一个唯一的用户“钱包”,从而在网络上发起交易。 这与当前中心化的应用程序不同,中心化程序要求用户必须创建账户,且所创建的账户存储在中心化的服务器上并由服务提供商管理。 虽然钱包可以用来存取NEO,GAS和基于NEO的其他代币,但“钱包”这个名称实际上是取得不太恰当的。 钱包的核心功能应该是加密公钥/私钥对,用于对NEO网络上出现的数据库交易进行签名和验证。 3 | 4 | 首先让我们来想想看用户是如何在传统的中心化数据库上执行写操作的,并将这种操作与用户在NEO区块链上执行的写操作进行比较。 这应该有助于消除你认为代币是存储在钱包中,而不是存储在区块链上的这种误解。 5 | 6 | ## 中心化数据库 7 | 在客户端/服务器架构体系中,用户首先会使用身份凭证(如电子邮件/密码组合)来创建一个账户, 然后这些凭证会存储在服务数据库中。 当用户登录到服务系统时,他们会在本地收到一个会话令牌,持有该令牌可以对服务数据库执行写操作。 8 | 9 | 因此,如果这个中心化的应用程序是银行服务,那么“资金”就会存储在银行的服务器上,你可以通过向银行提供有效凭证来执行转账操作。 10 | 11 | ### 优点 12 | - >如果用户丢失了凭证信息,服务提供商可以进行恢复 13 | - >电子邮件/密码是一种标准的用户体验模式,几乎所有的互联网用户都习惯这种操作 14 | 15 | ### 缺点 16 | - >将所有用户的凭证都存储在中心化服务器中,这非常容易遭受到黑客攻击 17 | - >需要为每个服务生成一组单独的凭证 18 | 19 | 但最为重要的是,正如这句常出现在加密货币社区的话所说的: 20 | 21 | “不是你的密钥,就不是你的代币” 22 | 23 | 传统客户端/服务器体系结构的本质意味着终端用户对服务器端数据库中存储的数据几乎没有什么控制权。 虽然在金融应用程序中这点尤为突出,但对于一般的用户数据而言也是一样的。 24 | 25 | ## NEO 区块链 26 | 对此我们来比较下用户是如何在NEO区块链上执行写操作的。用户首先会生成公钥/私钥对。所生成的密钥对会存储在用户的本地机器上,比如专用硬件模块或客户端的其他位置。远程服务器永远不可能获取到这些密钥对信息。当用户想要在NEO区块链(数据库)上执行写操作时,他们会在本地生成交易用于执行相关操作。例如,用户可能想给朋友转账1 NEO。然后,他们使用自己的加密签名对该交易进行签名,签名是通过公钥对生成的。 27 | 28 | 之后会对该交易进行验证,验证通过后向网络进行广播并最终完成写操作。我们可以看到,由于加密签名只能由用户自己生成,因此没有其他实体可以在没有显式授权的情况下,代表用户对远程数据库执行写操作。 29 | 30 | ### 优点 31 | - >对黑客而言没有可攻击的中心目标。这免去了服务提供商的许多责任 32 | - >可以在各种服务提供商之间共享用户的公开身份 33 | - >你的密钥,就是你的代币 34 | ### 缺点 35 | - >如果用户丢了凭证,就不可恢复 36 | - >对于没有使用过此类系统的用户而言,这是一种新的用户体验模式 37 | 38 | 总而言之,对钱包更准确地描述应该是利用公钥/私钥对在分布式数据库(区块链)上执行写操作。与典型的客户端/服务器认证体系结构相比,它具有优点也有缺点,但整体上而言,我们相信该系统提供的安全性和用户自主权可以给用户带来更强大的用户体验。 39 | 40 | 下一节,我们会了解一些NEO密钥架构设计的相关细节。 41 | 42 | [下一节](2-NEO私钥和地址生成.md)或者[返回目录](README.md#目录) 43 | -------------------------------------------------------------------------------- /cn/2-wallet/3-密钥加密与合约账户.md: -------------------------------------------------------------------------------- 1 | ## 私钥加密(NEP-6文件) 2 | 将原始的私钥存储在磁盘上会有安全隐患。任何可以访问原始私钥的人都可以使用这些资金。对这些密钥进行加密会是一种更为安全的做法。出于这个原因,我们提供了NEP-2标准格式(https://github.com/neo-project/proposals/blob/master/nep-2.mediawiki) 3 | 4 | 该加密密钥为原始私钥提供了一层额外的安全保障,攻击者要想获得这笔资金就需要同时获取加密密钥以及密码。这个做法是不错,但往往用户会需要多个钱包,这意味着他们会有多个密钥。对每个NEP-2加密密钥都加以存储是非常麻烦的,因此我们可以创建一种文件结构来一并存储这些加密的密钥。 5 | 6 | 该标准提供了一种将钱包导入各种区块链客户端的标准化方法,并提供了对NEP-2格式额外的安全性保证。 7 | 8 | 可以在此处查看有关文件格式的完整规范说明(https://github.com/neo-project/proposals/blob/master/nep-6.mediawiki) 。 文件遵循JSON结构,其中包含有关私钥/公钥对的信息以及每个账户的元数据信息。元数据信息包含:应将哪个钱包设置为默认钱包、加密参数以及其他相关的元数据。 9 | 10 | NEP-6文件还支持watch-only模式的地址。Watch-only地址不包含与私钥相关的任何信息,如果账户是单独存储在一个更为安全的位置的话,这个功能可能会很有用。 11 | 12 | ## 合约账户 13 | NEO还支持更加复杂的账户类型。 在这些类型中,资金不与单个用户相关联,而是存储在智能合约中。 合约会定义一些特殊规则,用于说明从账户中提取资金所需的条件。 14 | 15 | 这种账户类型最常见的是多方签名账户。 多方签名账户要求X个人中有N个人为交易提供签名从而才能执行转账操作。 例如,3个账户所有者中必须要有2个对交易进行签名从而才能提取资金。 16 | 17 | 我们可以使用NEO的操作码为账户生成一个简单的合约。假设我们想为3个人(公钥)创建一个多方签名合约账户: 18 | 19 | **需要注意的是,我们需要在操作之前按ECPoint(X,Y)对公钥进行升序排序,否则我们将得到一个不同的脚本哈希,从而导致生成不同的NEO地址。** 20 | 21 | ``` 22 | //公钥1 23 | 036245f426b4522e8a2901be6ccc1f71e37dc376726cc6665d80c5997e240568fb 24 | 25 | //公钥2 26 | 0303897394935bb5418b1c1c4cf35513e276c6bd313ddd1330f113ec3dc34fbd0d 27 | 28 | //公钥3 29 | 02e2baf21e36df2007189d05b9e682f4192a101dcdf07eed7d6313625a930874b4 30 | ``` 31 | 32 | 我们希望至少有2个人对交易进行签名。 因此,我们必须创建一个自定义脚本。 脚本内容如下: 33 | 34 | ``` 35 | // 最少签名数(2) 36 | PUSH OPCODE 52 37 | 38 | // 附上所有的公钥 39 | PUSH PUBKEY 1 40 | PUSH PUBKEY 2 41 | PUSH PUBKEY 3 42 | 43 | //公钥总数 (3) 44 | PUSH OPCODE 53 45 | 46 | //检验多签 47 | PUSH OPCODE AE 48 | ``` 49 | 50 | 从而得到了如下的脚本 51 | ``` 52 | 5221036245f426b4522e8a2901be6ccc1f71e37dc376726cc6665d80c5997e240568fb210303897394935bb5418b1c1c4cf35513e276c6bd313ddd1330f113ec3dc34fbd0d2102e2baf21e36df2007189d05b9e682f4192a101dcdf07eed7d6313625a930874b453ae 53 | ``` 54 | 55 | 然后,我们使用前面说过的方法计算该账户的脚本哈希和地址。 56 | 57 | 计算脚本哈希(和地址): 58 | 4d0c0932fa032debdceaaf5cd8086cf3f882961f / AJetuB7TxUkSmRNjot1G7FL5dDpNHE6QLZ 59 | 60 | *多方签名示例由NEOResearch提供* 61 | 62 | 这个合约信息也可以存储在NEP-6文件中,从而允许用户跟踪那些不一定与单个私钥相关联的账户。 可以使用NEO的脚本功能来创建更加复杂的账户类型。 63 | 64 | NEO-GUI钱包目前支持多方签名。 65 | 66 | ### NEO DB3 67 | 在引入NEP-6文件格式之前,NEO db3是NEO GUI所支持的一种遗留的文件格式。强烈建议升级到NEP-6文件格式,这可以在NEO-GUI中完成。 68 | https://docs.neo.org/en-us/node/gui/wallet.html 69 | 70 | [下一节](4-UTXO与账户模型.md)或者[返回目录](README.md#目录) 71 | -------------------------------------------------------------------------------- /cn/2-wallet/4-UTXO与账户模型.md: -------------------------------------------------------------------------------- 1 | ## UTXO 模型 2 | 钱包的一个主要功能是方便进行资产转移。NEO中的资产分为两类。一种基于UTXO模型(未花费的交易输出),另一种则是基于账户模型。在NEO中,NEO和GAS都遵循UTXO模型,而NEP-5代币则遵循账户模型。下面让我们详细地讨论下这两个模型。 3 | 4 | 首先,让我们来考虑下用户持有10个NEO的简单示例。这10个NEO实际上由多个UTXO组成。所有UTXO的总和必须等于10。例如,这10个NEO可能由3个UTXO组成。 UTXO_1为2 NEO,UTXO_2为3 NEO,UTXO_3为5 NEO,三者相加是10 NEO。因此,如果我们需要给别人发送3个NEO,那么我们可以简单地使用UTXO_2中的3个NEO作为交易的输入,而接收方接收到的输出UTXO也是3 NEO。 5 | 6 | 如果想尝试发送5个NEO,那么我们可以将UTXO_1和UTXO_2组合在一起作为交易输入,而接收方会收到作为交易的单个输出的5 NEO。当我们需要发送的金额不能通过对UTXO进行组合求和来满足时,情况就会变得稍微复杂一些。 7 | 8 | 现在我们想要向他人发送4个NEO。对UTXO进行组合无法直接得到这4个NEO。我们所能做的就是同时使用UTXO_1和UTXO_2,组合得到5个NEO。所以我们将UTXO_1和UTXO_2作为交易的输入,但与之前只有单一的输出不同,这时我们需要输出2个UTXO。为接收方生成一个值为4 NEO的UTXO,然后创建一个值为1 NEO的UTXO作为零钱发送回我们的账户。 9 | 10 | 对于NEO网络上的有效交易,必须满足以下这个公式:Sum(NEO_i) + Sum(GAS_i) = Sum(NEO_o) + (Sum(GAS_I) - Sum(GAS_sys_fee) - Sum(GAS_net_fee)) 11 | 12 | 从这个意义上说,UTXO不会被创建或销毁,而是会在新的UTXO中重新使用。加入UTXO可以并行地执行交易,因为每个UTXO都是唯一的,因此不可能出现双花的情况。 13 | 14 | ## 账户模型 15 | 其他一些区块链平台(如以太坊)所使用的账户模型会为每个拥有资金的账户创建一个全局状态。因此,你可以简单地使用与账户相关联的余额10,而不用持有一组用于交易的UTXO。因此,所有账户的全局状态必须存储在网络节点上。交易通过网络中的虚拟机解释执行,并对全局状态中的所有账户进行相应的状态更改。 16 | 17 | 在NEO网络上部署的NEP-5资产合约通常都遵循账户余额模型。它们没有关联任何的UTXO数据,余额状态的变化是通过执行智能合约完成的。这些执行由NEO虚拟机进行解释执行,并记录在智能合约存储区中。 18 | 19 | [返回目录](README.md#目录) -------------------------------------------------------------------------------- /cn/2-wallet/README.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | 1. [区块链钱包介绍](1-钱包介绍.md) 4 | 2. [NEO私钥和地址生成](2-NEO私钥和地址生成.md) 5 | 3. [加密私钥与创建合约账户](3-密钥加密与合约账户.md) 6 | 4. [UTXO模型与账户模型](4-UTXO与账户模型.md) 7 | 8 | ## 更多资源 9 | ### 创建钱包 10 | 可以有多种方式创建钱包。 11 | 12 | 完全同步了区块链数据的,可以考虑 13 | * NEO-GUI -> https://docs.neo.org/en-us/node/gui/install.html 14 | * NEO-CLI -> https://docs.neo.org/en-us/node/cli/cli.html 15 | 16 | 对于不需要进行同步的轻客户端,可以考虑 17 | * O3 钱包-> https://o3.network/ 18 | * NEON 钱包-> https://neonwallet.com/ 19 | 20 | 你可以在相关的钱包链接中查看更详细的使用指南 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /cn/2-wallet/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: cn 4 | lang-ref: wallet-index 5 | --- 6 | 7 | 8 | ## 目录 9 | 10 | 1. [区块链钱包介绍](1-钱包介绍.md) 11 | 2. [NEO私钥和地址生成](2-NEO私钥和地址生成.md) 12 | 3. [加密私钥与创建合约账户](3-密钥加密与合约账户.md) 13 | 4. [UTXO模型与账户模型](4-UTXO与账户模型.md) 14 | 15 | ## 更多资源 16 | ### 创建钱包 17 | 可以有多种方式创建钱包。 18 | 19 | 完全同步了区块链数据的,可以考虑 20 | * NEO-GUI -> https://docs.neo.org/en-us/node/gui/install.html 21 | * NEO-CLI -> https://docs.neo.org/en-us/node/cli/cli.html 22 | 23 | 对于不需要进行同步的轻客户端,可以考虑 24 | * O3 钱包-> https://o3.network/ 25 | * NEON 钱包-> https://neonwallet.com/ 26 | 27 | 你可以在相关的钱包链接中查看更详细的使用指南 28 | -------------------------------------------------------------------------------- /cn/3-transaction/1-交易介绍.md: -------------------------------------------------------------------------------- 1 | ## 交易介绍 2 | NEO交易是一个带有网络操作指令的签名数据包,例如,将资产转移到另一个地址。区块链账本中的每个NEO区块都包含有一个或多个交易,使得每个区块可以对交易进行批处理。要使用NEO区块链,我们需要先对交易的工作原理加以了解。 3 | 4 | - **[交易结构](transactions.md)** 5 | - [type](transactions.md#type) 6 | - [version](transactions.md#version) 7 | - [attributes](transactions.md#attributes) 8 | - [outputs](transactions.md#outputs) 9 | - [inputs](transactions.md#inputs) 10 | - [scripts](transactions.md#scripts) 11 | 12 | ### 交易类型 13 | NEO网络中有几种不同类型的交易,每种交易具有不同的用途和属性。部分先前使用的交易类型现在已被弃用或删除了,所以在主网上创建交易时不应该再使用这些类型。 14 | 15 | - **[交易类型](types.md)** 16 | - [MinerTransaction](types.md#minertransaction) 17 | - [ClaimTransaction](types.md#claimtransaction) 18 | - [ContractTransaction](types.md#contracttransaction) 19 | - [StateTransaction](types.md#statetransaction) 20 | - [InvocationTransaction](types.md#invocationtransaction) 21 | - [注册资产](types.md#registering-assets) 22 | 23 | ### 交易费用 24 | 要使用NEO网络,交易需要支付一定的费用。NEO网络中有两种不同的费用结构,即系统费用和网络费用。所有费用均通过系统的功能代币GAS(NeoGas)进行支付。 25 | 26 | - **[交易费用](fees.md)** 27 | - [系统费](fees.md#system-fees) 28 | - [网络费](fees.md#network-fees) 29 | - [应用的使用费用](fees.md#utility-fee-in-applications) 30 | 31 | ## 广播 32 | 一旦交易创建完成,就可以将其发送到网络的其他节点。如果节点通过了对该交易的验证,就会将它放置在内存池中,并将该交易广播转发到网络中的其他节点。最终,共识节点(NEO区块链中的验证人)会接收到该交易并将交易进行打包。 33 | 34 | [下一节](2-NEO交易结构.md)或者[返回目录](README.md#目录) -------------------------------------------------------------------------------- /cn/3-transaction/4-NEO交易费用.md: -------------------------------------------------------------------------------- 1 | ## 交易费用概览 2 | 3 | 要使用NEO网络,交易需要支付一定的费用。NEO网络具有两种不同的交易类型,即系统费和网络费。所有费用均通过系统的功能代币GAS(NeoGas)进行支付。 4 | 5 | | 类型| 说明| 6 | |-------------|---------------------------------------------------------------------| 7 | | 网络费|支付给验证人用于打包交易的费用| 8 | | 系统费| 操作网络的固定费用 | 9 | 10 | ### 网络费 11 | 12 | 对于大小不超过1024字节的交易,网络费目前是可选的。增加网络费(最低为0.001 GAS)可以提高交易的优先级。目前在NEO网络中每个区块最多只能包含20个低优先级的交易,因此在网络流量大的时候支付更高的网络费用可以使交易更快得到处理。 13 | 14 | 对于大小超过1024字节的交易需要支付0.001 GAS的基础费用,超过1024字节的部分按每字节0.00001 GAS收取网络费用。大多数基本的NEP-5资产转账交易大小仍然是远低于1024字节的,但是逻辑更复杂或者有大量[输入](transactions.md#inputs)和[输出](transactions.md#outputs)的交易可能会超过这一阈值因此需要支付一定的网络费用。 15 | 16 | 内存池中交易的优先级取决于每字节支付的费用。网络费由验证人收集并分发到任意的合约地址。 17 | 18 | ### 系统费 19 | 20 | 系统费用是根据[交易类型](types.md)和NEO虚拟机要执行的指令计算得出的固定费用。一般来说,交易对网络资源的需求越大,交易的成本就越高。每笔交易均有10 GAS的免费额度,因此对于大多数用户而言,与网络和智能合约进行交互都是免费的。 21 | 22 | #### 系统调用 23 | 24 | | 系统调用 | 费用(GAS) | 25 | |-----------------------------|---------------------------------------------------------------------------------| 26 | | *默认的* |所有系统调用花费`0.001` | 27 | | `Runtime.CheckWitness` | `0.2` | 28 | | `Blockchain.GetHeader` | `0.1` | 29 | | `Blockchain.GetBlock` | `0.2` | 30 | | `Blockchain.GetTransaction` | `0.1` | 31 | | `Blockchain.GetAccount` | `0.1` | 32 | | `Blockchain.GetValidators` | `0.2` | 33 | | `Blockchain.GetAsset` | `0.1` | 34 | | `Blockchain.GetContract` | `0.1` | 35 | | `Transaction.GetReferences` | `0.2` | 36 | | `Account.SetVotes` | `1` | 37 | | `Validator.Register` | `1000` | 38 | | `Contract.Create` | 每个合约花费`100`, 使用存储花费`400`, 使用动态调用花费`500` | 39 | | `Contract.Migrate` | 每个合约花费`100`, 使用存储花费`400`, 使用动态调用花费`500` | 40 | | `Storage.Get` | `0.1` | 41 | | `Storage.Put` |每千字节花费`1` | 42 | | `Storage.Delete` | `0.1` | 43 | 44 | #### 指令 45 | 46 | | 指令| 费用(GAS) | 47 | |---------------------------|-----------------------------------------------------| 48 | | *默认的* | 虚拟机中所有的指令都花费`0.001` | 49 | | `OpCode.PUSH16` (or less) | `0` | 50 | | `OpCode.NOP` | `0` | 51 | | `OpCode.APPCALL` | `0.01` | 52 | | `OpCode.TAILCALL` | `0.01` | 53 | | `OpCode.SHA1` | `0.01` | 54 | | `OpCode.SHA256` | `0.01` | 55 | | `OpCode.HASH160` | `0.02` | 56 | | `OpCode.HASH256` | `0.02` | 57 | | `OpCode.CHECKSIG` | `0.1` | 58 | | `OpCode.CHECKMULTISIG` | 每个签名花费`0.1` | 59 | 60 | ## 应用的使用费用 61 | 在网络中部署的任何应用都可以要求支付使用费用后才能使用智能合约功能。通常是通过NEP-5兼容的功能代币进行支付,不过智能合约也可以收取GAS。 62 | 63 | [返回目录](README.md#目录) -------------------------------------------------------------------------------- /cn/3-transaction/README.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | 1. [交易介绍](1-交易介绍.md) 4 | 2. [NEO交易结构](2-NEO交易结构.md) 5 | 3. [NEO交易类型](3-NEO交易类型.md) 6 | 4. [交易费用](4-NEO交易费用.md) 7 | 8 | ## 更多资源 9 | ### 工具 10 | 现有多种工具和库可用于创建交易并向NEO网络进行交易广播: 11 | 12 | - [neon-js](https://github.com/CityOfZion/neon-js) 是一个JavaScript版本库,可用于在任一JavaScript应用程序中构建交易; 13 | - [neo-python](https://github.com/CityOfZion/neo-python) 是一个NEO的全节点,可以用作SDK来创建交易并与NEO网络进行交互; 14 | - [neo-gui](https://github.com/neo-project/neo-gui/) 官方提供的与NEO网络进行交互的Windows GUI工具; 15 | - [neo-cli](https://github.com/neo-project/neo-cli/) 官方提供的命令行程序全节点,可用于创建交易并向NEO网络进行交易广播; 16 | -还有许多其他的钱包或者节点的实现工具,比如像[neo-lux](https://github.com/CityOfZion/neo-lux) 以及C#实现的[neo-thinsdk-cs](https://github.com/NewEconoLab/neo-thinsdk-cs)。 17 | 18 | -------------------------------------------------------------------------------- /cn/3-transaction/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: cn 4 | lang-ref: transaction-index 5 | --- 6 | 7 | ## 目录 8 | 9 | 1. [交易介绍](1-交易介绍.md) 10 | 2. [NEO交易结构](2-NEO交易结构.md) 11 | 3. [NEO交易类型](3-NEO交易类型.md) 12 | 4. [交易费用](4-NEO交易费用.md) 13 | 14 | ## 更多资源 15 | ### 工具 16 | 现有多种工具和库可用于创建交易并向NEO网络进行交易广播: 17 | 18 | - [neon-js](https://github.com/CityOfZion/neon-js) 是一个JavaScript版本库,可用于在任一JavaScript应用程序中构建交易; 19 | - [neo-python](https://github.com/CityOfZion/neo-python) 是一个NEO的全节点,可以用作SDK来创建交易并与NEO网络进行交互; 20 | - [neo-gui](https://github.com/neo-project/neo-gui/) 官方提供的与NEO网络进行交互的Windows GUI工具; 21 | - [neo-cli](https://github.com/neo-project/neo-cli/) 官方提供的命令行程序全节点,可用于创建交易并向NEO网络进行交易广播; 22 | -还有许多其他的钱包或者节点的实现工具,比如像[neo-lux](https://github.com/CityOfZion/neo-lux) 以及C#实现的[neo-thinsdk-cs](https://github.com/NewEconoLab/neo-thinsdk-cs)。 23 | -------------------------------------------------------------------------------- /cn/4-blocks/1-区块与区块链介绍.md: -------------------------------------------------------------------------------- 1 | # 区块与区块链介绍 2 | 3 | ## 概念 4 | 当Alice想向Bob发送一个交易时,她会对交易进行签名并将其广播到网络中的节点。共识节点会对内存池中的有效交易进行筛选,并将所选的交易打包到区块中。区块是一批同时得到确认和存储的交易。除了所包含的交易之外,区块结构还包括一些其他字段,相关讨论请点击[此处](2-Structure_of_a_block.md)查看。 5 | 6 | ## 链接区块 7 | 区块(bn)中有一个代表对上一个区块引用的字段,被引用的区块(bn-1)是最近一个在当前区块之前得到确认的区块。更准确地说,它是前一个区块的哈希。由节点来计算哈希值从而验证区块的父节点。同理,上一个区块(bn-1)也具有相同的行为,即链接到它之前的区块(bn-2)。这条链一直延伸直到创建的第一个区块,称为创世块(b0)。这就是术语“区块链”的由来,因为它实际上是一条由区块链接而成的链结构。 8 | 9 | ## 父块与子块 10 | 每个区块只能有一个父块,通过字段引用到前一个区块。大多数区块链都会出现一种临时状态,即一个父块可以有多个子块,也就是说,多个区块可以指向同一个父块。比特币平均每周会出现一次这样的情况。当两个矿工近乎同时地发现新区块的一个有效Nonce时(“解决难题”),就会出现这种情况,两个矿工都会向网络广播有效的区块。这就是所谓的分叉,当挖出新的区块时这个问题就会自动得到解决。因为之后产生的区块只会加在其中一条链上,且最长的那条链(难度最大的路径)才会被大家接受,而另一条则会被放弃。 11 | 12 | 得益于dBFT共识机制,NEO区块链不会受到这种行为的影响,并且根据算法的终局性,NEO永远都不会出现分叉,因此也不会出现区块链存在两个有效版本的情况。有关共识机制的更多信息,可以阅读[白皮书](https://docs.neo.org/en-us/basic/consension/whitepaper.html)。 13 | 14 | [下一节](2-区块结构.md)或者[返回目录](README.md#目录) -------------------------------------------------------------------------------- /cn/4-blocks/3-区块创建与广播.md: -------------------------------------------------------------------------------- 1 | ## 共识节点创建区块 2 | 3 | 正如[第1部分](1-Introduction_to_blocks_and_blockchain.md)中所讨论的,NEO使用dBFT机制来生成区块。简而言之,这意味着网络会选择出一定数量的共识节点,且需要至少2/3个节点的共识才有可能生成新的区块。 4 | 5 | 每一轮共识期间都会有一个共识节点被选为议长。在最好的情况下,不会出现拜占庭节点,议长节点会发起一个新块提案,并将其向网络中的其他共识节点进行广播以达成共识。当从其他共识节点那获得足够多的签名时,区块就会被广播到网络中,且具有终局性。有关dBFT共识机制的更多详细信息,请参阅[白皮书](https://docs.neo.org/en-us/basic/consensus/whitepaper.html)。 6 | 7 | ## 新区块 8 | 9 | 用户想要发送交易,通常的做法是通过钱包创建交易并对交易进行签名,之后将其发送到RPC或P2P节点。 RPC和P2P节点都会向网络中继(有效)交易,最终交易会到达一个共识节点。更多内容请查看 [5. 网络](../5-network/)一节。这篇[Medium上的文章](https://medium.com/neoresearch/understanding-neo-network-in-five-pictures-e51b7c19d6e0)对这一机制也给出了一个很好概述。 10 | 11 | 一旦有效交易到达共识节点,它们就会被存储在节点的内存池中。创建新块时,会从这个内存池中选择要打包的交易。每个区块最多可以包含500笔交易,且第一个交易总是[MinerTransaction类型](../3-transaction/types.md#minertransaction)。 12 | 13 | ## 交易(网络)费用 14 | 15 | 议长节点会选择一些交易并将其打包进新块中。用户要想确保他的交易尽可能快地被执行时,可以选择支付一定的交易费用。目前是不需要交易费用的(不过每个区块只限有20笔免费的交易)。然而,用户可以选择支付交易费用来获得更高的优先级。费用越高,该交易就越有可能被打包进下一个区块中。这是因为内存池中的交易是按每字节支付的手续费进行排序的,且议长节点可以获得提案块所包含的交易的所有交易费用。这使得相较于免费交易而言,议长节点会更倾向于打包那些提供了更高手续费的交易。这笔交易费用不是一个特定的字段,而是在花费UTXO时没有被计入的剩余GAS。 16 | 17 | 这是因为UTXO是不可分割的,需要作为一个整体进行花费。例如,你想给朋友发送5 GAS,但钱包中只有一个价值500 GAS的UTXO。你无法直接将这个500 GAS的UTXO进行划分。你要做的是将这个500 GAS的UTXO作为输入来创建一个交易。此外还会向交易添加2个输出:5个GAS发送给你的朋友,剩下的495个发送回自己的账户。这可以与现实生活中的例子做个对比,当你给了收银员100美元,但实际只需支付1美元时,就会得到99美元的找零。UTXO也是类似的,你需要在同一笔交易中将剩余的零钱发送给自己。 18 | 19 | 未明确指出接收地址的每一单位的UTXO都会被解释为交易费用。继续前面的这个例子,你有一个495 GAS的UTXO。如果你在同一交易中,向朋友发送了另一个5 GAS的UTXO,且只发送回489 GAS给你自己,那么剩下的1 GAS就会被视为交易费用。事实上,你正在告诉共识节点说*零钱给你了*。 20 | 21 | 普通用户在用这种方式构建UTXO交易时不用担心这些问题。大多数高级钱包软件都会为用户提供指定交易费用的选项,并以这种方式生成交易,以便将零钱发送回你的账户。 22 | 23 | 作为一个示例,你可以看看[这个交易](https://neoscan.io/transaction/80b963d68c0f3d65c0e906057f7517a17ef7dcc1b29e2a79205e4aa235131f95)。 24 | 25 | ![费用交易示例](txn-with-fee.png) 26 | 27 | 源地址有一个包含了119.99999987 GAS的UTXO,现在希望将其中的60 GAS发送到另一个地址。为此,指定了接收方地址并发送这60 GAS,同时将剩余的GAS(59.99999986 GAS)以花费的方式再次转回给自己。但是,60+59.99999986等于119.99999986 GAS。与原来的UTXO相差0.00000001 GAS,这就是隐含的交易费用。不指定UTXO中剩余的0.00000001GAS的接收地址,它就会被作为交易费用奖励给创建[相关区块](https://neoscan.io/block/eabb36acfb055592afb06786f831390762000a9aa669016d27eb031f41e14a07)的共识节点。 28 | 29 | ## 系统费 30 | 31 | 交易费用于获得网络的优先权。此外还有一些具有其他特定目的的费用,称为系统费。 32 | - ***智能合约创建*** 当前在主网上部署新合约的费用为100-1000 GAS,具体费用由所需的功能(例如需要存储或者动态调用)和大小决定。对于结构化开发,建议先在[本地的私有测试网](https://github.com/CityOfZion/neo-local)上开始开发。一旦智能合约可以稳定执行了,就可以点击[此处](https://neo.org/testcoin/apply)申请测试网资金用于最后的验证。只有在能保证你的智能合约已经正确无误地实现的情况下,才能将其部署到主网上,因为这个操作是不可撤销的。这意味着即使销毁合约,也不会退回用于部署所支付的GAS。 33 | - ***智能合约执行*** 要想能执行智能合约,节点需要执行特定的计算。为了奖励节点所做的工作,应该在执行合约的交易中附上一定的系统费用。目前,任意系统调用都有10个GAS的免费额度,也就是说,对于费用低于10 GAS的合约调用,不需要支付系统费用。 [本页](https://docs.neo.org/en-us/sc/systemfees.html)提供了执行智能合约所需系统费用的完整概述。对于每个操作,都说明了特定操作所需的费用。 34 | 35 | # 区块广播 36 | 37 | 一旦共识节点根据dBFT机制对新块达成了共识,它们就会将这个新块广播到整个网络。由于dBFT共识机制的特性,实现了一区块终局性。这意味着所有客户端都可以在新块创建后立即查询区块链(任意RPC或P2P节点),并能保证这些交易是最终确定的。 38 | 39 | [下一节](4-区块验证与处理.md)或者[返回目录](README.md#目录) -------------------------------------------------------------------------------- /cn/4-blocks/README.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | 1. [区块与区块链介绍](1-区块与区块链介绍.md) 4 | 2. [区块结构](2-区块结构.md) 5 | 3. [区块创建与广播](3-区块创建与广播.md) 6 | 4. [区块验证与处理](4-区块验证与处理.md) 7 | 8 | ## 更多资源 9 | ### 默克尔树 10 | 11 | 包括NEO在内的大多数区块链都使用默克尔树来有效地保护每个区块中包含的交易。 12 | 13 | 由于NEO的区块头中存储了默克尔树根的值,建议在阅读NEO区块结构之前先熟悉默克尔树。可以点击[此处](默克尔树.md)查看默克尔树的相关介绍。 14 | 15 | -------------------------------------------------------------------------------- /cn/4-blocks/block-info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/4-blocks/block-info.png -------------------------------------------------------------------------------- /cn/4-blocks/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: cn 4 | lang-ref: blocks-index 5 | --- 6 | 7 | ## 目录 8 | 9 | 1. [区块与区块链介绍](1-区块与区块链介绍.md) 10 | 2. [区块结构](2-区块结构.md) 11 | 3. [区块创建与广播](3-区块创建与广播.md) 12 | 4. [区块验证与处理](4-区块验证与处理.md) 13 | 14 | ## 更多资源 15 | ### 默克尔树 16 | 17 | 包括NEO在内的大多数区块链都使用默克尔树来有效地保护每个区块中包含的交易。 18 | 19 | 由于NEO的区块头中存储了默克尔树根的值,建议在阅读NEO区块结构之前先熟悉默克尔树。可以点击[此处](默克尔树.md)查看默克尔树的相关介绍。 20 | -------------------------------------------------------------------------------- /cn/4-blocks/merkle-tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/4-blocks/merkle-tree.png -------------------------------------------------------------------------------- /cn/4-blocks/txn-with-fee.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/4-blocks/txn-with-fee.png -------------------------------------------------------------------------------- /cn/4-blocks/默克尔树.md: -------------------------------------------------------------------------------- 1 | # 默克尔树 2 | 3 | ## 默克尔树介绍 4 | 5 | ![Merkle tree](merkle-tree.png) 6 | 7 | 默克尔树是一种树型结构,存储着叶子节点的哈希值。因此,可以对L1和L2的组合哈希进行哈希计算,并且对L3和L4执行相同的哈希操作。然后将该过程递归地应用于这些哈希,直到最后只剩下1个哈希值,即默克尔树根节点的哈希。默克尔树通常情况下看着是一棵倒置的树型结构,根节点在顶部,分叉向下,叶子节点在底部。使用默克尔树可以有效地验证特定的数据项是否是树结构的一部分。有关默克尔树的更多信息,请访问[维基百科](https://en.wikipedia.org/wiki/merkle-tree)。 8 | 9 | 10 | 11 | ## 默克尔树与网络安全 12 | 13 | 许多区块链都使用默克尔树来有效地保证区块中交易的安全性。由于每个交易都会影响默克尔树根节点的最终哈希值,更改区块中的任意交易都会完全改变默克尔树根节点的哈希。因此,只需存储和验证默克尔树的根节点哈希,就可以验证完整的交易列表。当然,这可以通过在所有交易上执行任意的哈希操作来实现。使用默克尔树还有很多其他的好处,其中一个就是可用于简单支付验证(SPV),由于使用了默克尔树,可以大大减少验证区块中是否包含某个交易的时间。 -------------------------------------------------------------------------------- /cn/5-network/1-NEO网络协议介绍.md: -------------------------------------------------------------------------------- 1 | # NEO协议和网络教程 2 | 3 | [NEO](https://neo.org/)是一个面向去中心化应用的开源平台。NEO区块链使用了 [dBFT](https://docs.neo.org/en-us/basic/consension/consension.html)共识机制,与以太坊类似,可支持部署和运行智能合约。 4 | 5 | 本教程主要受众是那些希望通过编写NEO P2P客户端来参与到这种分布式系统的开发人员/学生。本教程不会对分布式系统的细节做太多的说明,读者应该具备分布式系统的基础知识,熟悉网络协议和Golang编程语言。 6 | 7 | NEO网络由两种协议组成:与本地客户端和钱包进行通信的协议,以及与NEO网络中其他节点通信的外部协议。与本地节点进行连接使用的是[JSON-RPC](https://www.jsonrpc.org/)协议。也可以通过JSON-RPC连接到外部节点。但是,本教程会重点介绍另一个协议,即[NEO协议](https://docs.neo.org/en-us/network/network-protocol.html)。在本教程中,我们将学习如何与其他NEO节点进行通信。 8 | ``` 9 | +--------------+ 10 | +----------+ | +----------+ | 11 | | | NEO 协议| | | | 12 | | NEO 节点+----------------+ NEO 对等节点| | 13 | | | | | | | 14 | +----------+ | +----+-----+ | 15 | | | | 16 | | |JSON | 17 | | |RPC | 18 | | | | 19 | | +----+-----+ | 20 | | | | | 21 | | |本地节点| | 22 | | | | | 23 | | +----------+ | 24 | +--------------+ 25 | NEO 节点 26 | ``` 27 | 28 | 在本教程中,我们将重点介绍另一个协议,[NEO协议](https://docs.neo.org/en-us/network/network-protocol.html)。我们将使用Golang语言来学习如何与NEO节点通信。 29 | 30 | [点击此链接开始学习](2-使用Golang实现NEO-ping功能.md)或者[返回目录](README.md#目录) 31 | -------------------------------------------------------------------------------- /cn/5-network/README.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | 1. [NEO网络协议介绍](1-NEO网络协议介绍.md) 4 | 2. [使用Golang实现NEO ping功能](2-使用Golang实现NEO-ping功能.md) 5 | 6 | ## 更多资源 7 | ### 更多网络链接与文档 8 | 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 | -------------------------------------------------------------------------------- /cn/5-network/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: cn 4 | lang-ref: network-index 5 | --- 6 | 7 | ## 目录 8 | 9 | 1. [NEO网络协议介绍](1-NEO网络协议介绍.md) 10 | 2. [使用Golang实现NEO ping功能](2-使用Golang实现NEO-ping功能.md) 11 | 12 | ## 更多资源 13 | ### 更多网络链接与文档 14 | 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 | -------------------------------------------------------------------------------- /cn/6-persistence/persistence_1_byte.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/6-persistence/persistence_1_byte.png -------------------------------------------------------------------------------- /cn/6-persistence/persistence_3_bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/6-persistence/persistence_3_bytes.png -------------------------------------------------------------------------------- /cn/6-persistence/persistence_address.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/6-persistence/persistence_address.png -------------------------------------------------------------------------------- /cn/6-persistence/persistence_block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/6-persistence/persistence_block.png -------------------------------------------------------------------------------- /cn/6-persistence/persistence_blockchain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/6-persistence/persistence_blockchain.png -------------------------------------------------------------------------------- /cn/6-persistence/persistence_coin_reference.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/6-persistence/persistence_coin_reference.png -------------------------------------------------------------------------------- /cn/6-persistence/persistence_contract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/6-persistence/persistence_contract.png -------------------------------------------------------------------------------- /cn/6-persistence/persistence_header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/6-persistence/persistence_header.png -------------------------------------------------------------------------------- /cn/6-persistence/persistence_memory_pool_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/6-persistence/persistence_memory_pool_1.png -------------------------------------------------------------------------------- /cn/6-persistence/persistence_snapshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/6-persistence/persistence_snapshot.png -------------------------------------------------------------------------------- /cn/6-persistence/persistence_var_string.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/6-persistence/persistence_var_string.png -------------------------------------------------------------------------------- /cn/7-consensus/1-共识介绍.md: -------------------------------------------------------------------------------- 1 | # 介绍 2 | 3 | 多代理系统(MAS)是物联网(IOT)的核心,系统中的自治设备能够按照各自的特定目标彼此交互。 4 | 区块链共识以同样的方式运作,自治节点应通过协商协议达成一致。虽然可能有一个需要优化的全局指标,但肯定会出现一些自私的节点试图最大化他们自己的利益。通常而言,正如通篇文章所说的,MAS协议达成共识的三辆马车是:投票、拍卖和协调。 5 | 6 | 我们相信区块链协议能够在达成共识的过程中安全地执行分布式理性决策。特别是,如果给出正确的激励措施,这种情况是可以发生的。 7 | 激励不仅仅是直接的金钱奖励(虽然是奖励),而且还涉及声望以及节点感兴趣的项目的维护。对于NEO共识节点(CN)而言,可以提出这一兴趣的两个关键点,分别涉及到两个不同的领域:1)有兴趣拥有一个与协助创建区块相关的可靠形象的利益相关者; 2)希望增加Neo持有者对他们信任度的节点,这可以让持有者支持他们的候选资格并使用他们的服务。 8 | 9 | NEO协议,即所谓的委托拜占庭容错(dBFT),其设计源于实用拜占庭容错,由Miguel Castro和Barbara Liskov在1999年提出。 10 | 11 | 本教程将介绍一些基本步骤,以便理解为我们的生态系统设计和开发这样的机制的重要性。 12 | 13 | 14 | ## 希望你能学到 15 | 16 | 读完本材料后,你将学到: 17 | 18 | - 区分工作量证明机制和其他基于协调的共识机制; 19 | - 了解关于加密和多签名账户的更多信息; 20 | - 了解拜占庭容错系统; 21 | - 理解完全分布式网络的设计,其中共识使用数字签名; 22 | - 了解**一区块终局性**的美妙之处。 23 | 24 | [点击此链接开始学习](2-工作量证明与权益证明.md)或者[返回目录](README.md#目录) -------------------------------------------------------------------------------- /cn/7-consensus/2-工作量证明与权益证明.md: -------------------------------------------------------------------------------- 1 | ## 工作量证明机制的本质 2 | 3 | 中本聪提到了工作量证明机制可以跨CPU投票,即一CPU一票制。这背后的基本思想是创建一个协议,其中每隔`X`秒产生一个新的区块。如果更快或者更慢地生成区块,则难度会降低。 4 | 5 | 例如,让我们把`NEO Ecosystem`这个词进行Hash256计算 `b1f65a74b608f6b785286b5da1d39ceb36ed87b62fee6ba97a65ecd4655b7661`。 6 | 现在让我们来看看`NEO Ecosystem + Nonce`这个词,比如说`NEO Ecosystem + 1`,Hash256处理后可以得到 `0739bcb67c6e934c669b95d65f1c98cdd67bcef0ef8ab22a7c1b4404f0e11450`。 7 | 现在,看看`NEO Ecosystem + 12345678`,我们可以得到`011c65a33085565814548bc2860a1a3b1c68b627581381382447147788b0240c`,它以`01`开头,没有`07`那么有意义。现在,开始玩转这个随机数,直到你得到以0000000000`开头的值,你可以验证这个任务有多困难。哈希是数据文件的一种加密签名,它基于经典的SHA-256算法,可生成几乎唯一的固定大小为32字节长的值。哈希是单向的,即使使用量子计算机,任何已知的算法都难以恢复其信息。 8 | 9 | 在比特币挖矿的早期,2009年一台标准计算机可以达到每秒大约1百万哈希的算力。从那时起,由GPU,FPGA和ASIC发展而来,挖矿的算力已经达到了令人印象惊叹的每秒130亿哈希的专用功率,比开始时快1300万左右。 10 | 11 | 专门用于生成哈希的计算机和知识发展得如此之快,为什么数字签名和通信协议没有得到这么快速的发展呢?物联网一直是业内研究人员和行业工作的热点和焦点,其根源与自治设备之间的通信和协议有关。 12 | 13 | NEO dBFT的本质是由一组节点(自治代理)共享的数字签名,这些节点是由大多数NEO持有者选择出来的。 14 | 15 | ## 协调 x 权益证明 x 投票 16 | 17 | 众所周知,所谓的基于权益证明(PoS)的算法与我们提到的MAS有相似之处。PoS的核心思想是让那些在生态系统中财务状况较好的人有决策权,这将激励他们保持网络安全且高效地运行。可以注意到,如果我们将这种力量转变为生态系统的一部分,我们将拥有一个类似的PoS,其中投票将是选择此类节点的主要机制。使用投票权甚至可以淘汰那些按照承诺行事的人。 18 | 19 | 总而言之,我们应该看到协调是在去中心化场景中达成一致的核心。协调的意义不在于中心协调员,而在于做出决定时需要考虑多个目标。 20 | 21 | [点击此链接开始学习](3-pBFT与dBFT.md)或者[返回目录](README.md#目录) -------------------------------------------------------------------------------- /cn/7-consensus/3-pBFT与dBFT.md: -------------------------------------------------------------------------------- 1 | ## pBFT 2 | 3 | 有人认为,完全基于异步系统实现共识是不可能的,*M. Fischer, N. Lynch, and M. Paterson*于1985年在ACM期刊上发表的"具有单一故障过程的分布式共识的不可能性"一文提到。 4 | 5 | 从这个意义上说,我们必须依靠同步的基本概念来提供网络的活性。 6 | 7 | 可能[9]。我们保证系统活性,即客户端 8 | 9 | 有关pBFT状态图的概述可以查看下图。![Neo 规范](https://github.com/NeoResearch/yellowpaper/blob/master/sections/graphviz-images/graphviz-pbft.jpg?raw=true) 10 | 11 | pBFT专为......而设计 12 | 13 | 14 | ## dBFT 15 | 16 | **免责声明:** *本教程的部分内容摘自[dBFT正式规范](https://github.com/NeoResearch/yellowpaper/blob/master/sections/08_dBFT.md)。* 17 | 18 | 虽然前面提到的活性已经被证明可用于pBFT机制,但是dBFT的工作场景是现实中一个具有状态机副本机制的大型公有链。其中共享信息的性质不同,且信息不可泄露。为此,精细设计的恢复机制是dBFT机制的一部分。 19 | 20 | 下图为当前dBFT 2.0的状态图 21 | 22 | ![这里](https://github.com/NeoResearch/yellowpaper/blob/master/sections/graphviz-images/graphviz-dbft-v2-recover.jpg?raw=true) 23 | 24 | ### 一区块终局性 25 | 26 | 一区块终局性为现实世界的应用程序带来了显著的优势。例如,终端用户,商家和交易所可以确保他们的交易已被最终处理,并且不可能被撤销。虽然NEO生态系统是为托管的去中心化应用程序(DApps)设计的,但值得注意的是,持久化的SC交易(涉及状态机复制(SMR)并且是部分DApp的核心功能)会带来一系列独特的挑战。由于共识节点无法公开和显示任何重复区块的信息,因此保证区块终局性是一项棘手的任务。从这个意义上讲,只有当大多数共识节点已经达成协议时,才应提供区块的签名。 27 | 28 | 这个问题被称为**不知疲倦的矿工问题**(在此定义): 29 | 30 | 1. 该议长是一名地质工程师,正在寻找一个可以挖掘氪石的地方; 31 | 1. 他提议了一个地理位置(待挖掘的地理坐标); 32 | 1. 团队中的大多数成员(`M` 个人)对该坐标达成了共识(带有他们的签名)并签署了合约同意开始挖掘; 33 | 1. 挖掘的时间:他们会不停地挖掘,直到他们找到氪石(在发现氪石前不会去任何其他地方进行挖掘)。氪石是一种无限可分的晶体,因此,一旦有人挖掘到氪石,他就可共享以便所有人都能拥有一块氪石从而履行完他们的合约(3.); 34 | 1. 如果有人死亡了,当有其他人加入时,他将看到先前签署的协议(3.),并自动开始挖掘。其他小部分人也会遇到相同的问题,可以通过隐藏的信息来告知他们也应该进行挖掘。 35 | 36 | ### 出块更改视图且给予网络额外的时间 37 | 38 | 为了保持活性,需要保证系统具备一些额外的性质: 39 | 40 | - 如果节点不相信当前的网络拓扑结构,则应阻止节点提交它们的签名(请求`更改视图`)。 41 | 42 | 然而,在实际操作中dBFT在某些情况下会失去活性,其中节点仅仅只是出现了网络问题,可概括为Commit阶段锁定。该类问题的解决方法是引入计数机制,用于检查已提交的节点(易于检查)和故障节点(超过一个区块高度没有收到过其共识信息的共识节点)。在要求改变视图之前,该机制提供了额外的保护措施。 43 | 44 | 同时,设计的另一个策略是当节点看到网络有进展时,避免`更改视图`。每次节点与其他节点共享签名信息时,会将额外的超时信息添加到它们的内部计时器中,表明节点正在参与共识并与其他节点进行通信。 45 | 46 | [点击此链接开始学习](4-dBFT共识示例与场景.md)或者[返回目录](README.md#目录) -------------------------------------------------------------------------------- /cn/7-consensus/4-dBFT共识示例与场景.md: -------------------------------------------------------------------------------- 1 | ## Watch-only模式的共识节点 2 | 3 | 正如可以在[网络教程](linkToNetworkTODO)中验证的那样,NEO网络以完全分布式的方式运行,如上图所示,摘自[Medium文章](https://medium.com/neoresearch/understanding-neo-network-in-five-pictures-e51b7c19d6e0): 4 | 5 | ![转发交易,直至达到共识节点(绿色)](https://cdn-images-1.medium.com/max/800/1*vKbm_Di8GgQep8SyKeAWNw.png) 6 | 7 | 绿色框代表共识,可出现在节点池中。消息全部广播给相邻节点(最好的情况下)。具有特殊功能的节点可以设计为仅监控来自共识节点的P2P消息,可以访问[NeoCompiler Eco共享私有链](https://neocompiler.io/#!/ecolab/cnnodesinfo)来查看相关信息。 8 | 9 | ![仅限监视节点的信息](./watch-only-node.png) 10 | 11 | 在这个图中,该Watch-Only节点还具有RPC功能。值得注意的是,节点可以具有其他特性并整理任意管理该客户端的节点所需的信息,如[教程](./linkToPluginsTodo)中所强调的那样。 12 | 13 | ## dBFT 场景 14 | 15 | 为了举例说明一些可能的共识场景,考虑以下角色: 16 | 17 | ![dBFT共识节点角色](./cn_characters.jpg) 18 | 19 | - **N1:** 张铮文,绝地大师 ; 20 | - **N2:** 达鸿飞,智能经济的壁炉; 21 | - **N3:** 林鹏涛,壁炉中的真相; 22 | - **N4:** NEO 生态系统,用户、交易所和开发人员的所有项目和利益的总和; 23 | - **N5:** City of Zion,世界各地的结合和合作; 24 | - **N6:** NeoResearch Buterfly,探索、恢复和改造的能力; 25 | - **N7:** 尤达大师,从过往的经验中学习。 26 | 27 | 通过使用这7个共识节点并结合他们的优点,我们会给出一些例子让读者了解dBFT机制的工作原理: 28 | 29 | ### 创世块 30 | 31 | 创世块创建了3个交易,其中原生资产NEO和GAS在该块中注册并创建,并转移到当前验证人的账户中(由这7个角色组成的多签名账户); 32 | 33 | ### 情况 1 (正常运行) 34 | 35 | - 我们处于高度`1`以及视图编号`0`, 议长节点是`N1`(考虑一个数学公式); 36 | - 张铮文选择了由多签账户签名的第一组交易,并且发起了提案块`b_1_0`; 37 | - 需要`2f+1`个节点对该提案达成一致。N2, N3, N4 and N5是首先响应希望处理这个区块的节点。包括N1,现在有5个节点 (正好是2f +1); 38 | - N1, ..., N5可能会首先进入提交阶段。 39 | - 处于提交阶段的节点会自动发送针对当前区块提案`b_1_0`的签名; 40 | - 一旦节点收集到`2f+1`个签名,就会向网络广播一个有效地区块。即便是一个**watch-only模式的节点**也可能是第一个执行该任务的节点(突出显示了这个MAS环境可能的工作方式)。 41 | 42 | ### 情况 2 (议长故障) 43 | 44 | - 现在我们处于高度`2`且视图编号为`0`, 议长节点是`N2`; 45 | - 达鸿飞小睡了一会儿,在这几秒钟内无法与其他角色交流了; 46 | - `2f+1`个节点同意应该`更改视图`。网络上没有任何进展,节点应该严格按照将`出块时间`左移1位来设置超时时间。如果是15秒,则超时时间是30秒。 47 | - 议长节点更改为N3。 48 | - N3节点只有在参与`视图更改`的情况下才会发起新的提案块, 否则, 它仍将等待`N2`的提案块。 49 | - 考虑到N3得到了`2f+1`条`更改视图`消息, 它现在将发起新的提案块`b_2_1`; 50 | - 从这里开始执行情况1下的正常流程。 51 | 52 | ### 情况 3 (提交之后发生故障) 53 | 54 | - 现在我们处于高度`3`以及视图`0`, 议长节点是`N3`; 55 | - N3发起了提案块`b_3_0`; 56 | - 从`N3`, ..., `N7`开始的大多数节点都同意提案; 57 | - 然而,在进入提交节点后,`N4`在广播其对区块`b_3_0`的签名前发生故障了; 58 | - `N3`, `N5`, `N6` 以及`N7`,现在只有`2F`个节点,仍然还需要一个对`b_3_0`的签名。 可能的情况是: 1) `N4`从故障中恢复了; 2) `N1`以及`N2`可以看到它们丢失的消息; 3) `N1`和`N2`请求`更改视图`,但不会获得大多数`M` 的同意,其他节点将发送一条`Recovery`消息来响应它们, 在该消息中,它们将自动接收到所有已知的消息。一旦这3个节点中的任何一个收到此类消息,它们将对当前区块`b_3_0`进行操作。 59 | 60 | 需要注意的是,3个故障节点个数是`f+1`,这会阻止网络的运行。另一方面,应该注意的是,没有检测到真正的拜占庭行为,这只是延迟和连接的问题。从这个意义上来说,由于部分同步协议,消息有时会达到这些节点. 61 | 62 | ### 情况 4 (议长节点出现拜占庭) 63 | 64 | - 现在我们处于高度`4`且视图编号为`0`, 议长节点是`N4`; 65 | - `N4`是恶意节点,且试图向网络发送一个不同的区块; 66 | - 每个节点设计为只接受每个`视图`下的单的提案。在大多数`M = 2f+1`个节点不能就同一个提案达成共识之前(通过`hash`汇总),不会提交任何节点。 67 | - 如果`M`个节点提交了而另外的`f = 2`个节点缓存了一个不同的提案块,它们将在某个时刻收到一条`Recover`消息, 这将允许它们匹配哈希值。如果哈希值不同,我们将有一个针对这个议长节点的反证,这肯定会使得NEO持有者将这个节点从验证人中删除。 68 | 69 | ## 一个由4个节点组成的共识 70 | 71 | 正如你可能知道的那样,NEO区块链2.x中的地址由`21`(表示[“向计算栈推送34个字节”](https://github.com/neo-project/neo-vm/blob/f81c3039d5fb4417b3c1ad780378c7f92499964a/src/neo-vm/OpCode.cs#L144))、 公钥和`ac`(操作码,用于调用一个脚本来对地址见证人执行验证)组成。 72 | 73 | 建议读者看看以下文章: 74 | 75 | - [了解NEO的多方签名](https://medium.com/neoresearch/understanding-multisig-on-neo-df9c9c1403b1)。 76 | 77 | 让我们考虑具有以下公钥的节点(21 + rootOfPubKey + ac): 78 | 79 | - N1:`2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406eac` 80 | - N2:`2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62ac` 81 | - N3:`2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2ac` 82 | - N4:`2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699ac` 83 | 84 | 可以使用以下脚本来创建一个多方签名账户: 85 | 86 | `532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae` 87 | 88 | 解读为:`53`(签名个数)+`21` +`02 ... 6e` +`21` + `02 ... 62` +`21` + `02 ... c2` +`21`+`03 ... 99` +`54`(公钥所有者个数)+`ae` 89 | 90 | 我们选择这4个节点作为验证人节点,下面的脚本将为每个区块提供签名,地址如下:`AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU`。后者可以通过将该脚本转换为“大端存储的脚本哈希”然后再进行base-58编码来获取。如果读者想要试着转换格式的话,我们建议访问[NeoCompiler-Eco](https://neocompiler.io/#!/ecolab/conversor)。 91 | 92 | ![multisig 3/4](./multisig_3_4.png) 93 | 94 | ![scripthash to address base58](./scripthash_address.png) 95 | 96 | ## 一个简单的单节点共识 97 | 98 | 让我们以前面描述的第一个节点(N1)为例,通过将`53`和`54`转换为`4f`,来创建一个包含1个所有者和1个签名者的多签名账户。 99 | 100 | `512102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc251ae` 101 | 102 | 后者将产生以下地址:`AbU69m8WUZJSWanfr1Cy66cpEcsmMcX7BR` 103 | 104 | [返回目录](README.md#目录) -------------------------------------------------------------------------------- /cn/7-consensus/README.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | 1. [共识介绍](1-共识介绍.md) 4 | 2. [工作量证明与权益证明](2-工作量证明与权益证明.md) 5 | 3. [pBFT与dBFT](3-pBFT与dBFT.md) 6 | 4. [dBFT共识示例与场景](4-dBFT共识示例与场景.md) 7 | 8 | ## 更多资源 9 | ### 实践练习(动手操作) 10 | 11 | 我们建议那些对初始化和测试这种共识感兴趣,且能读懂日志信息的人,花一些时间来查看下[NeoCompiler Eco Github](https://github.com/neoresearch/neocompiler-eco),按照上面的指南搭建一个本地的区块链系统。 12 | 13 | 按照 [README](https://github.com/neoresearch/neocompiler-eco/blob/master/readme.md) 中描述的步骤,根据所需规范来初始化你的共识节点。 14 | 15 | -------------------------------------------------------------------------------- /cn/7-consensus/cn_characters.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/7-consensus/cn_characters.jpg -------------------------------------------------------------------------------- /cn/7-consensus/multisig_3_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/7-consensus/multisig_3_4.png -------------------------------------------------------------------------------- /cn/7-consensus/scripthash_address.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/7-consensus/scripthash_address.png -------------------------------------------------------------------------------- /cn/7-consensus/watch-only-node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/cn/7-consensus/watch-only-node.png -------------------------------------------------------------------------------- /cn/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 -------------------------------------------------------------------------------- /cn/9-smartContract/Development_compile.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: cn 4 | lang-ref: Development_compile 5 | --- 6 | 7 | # 智能合约的编译和部署 8 | 9 | ## 编译合约文件 10 | 11 | 让我们回到IDE Visual Studio,来编译这个简单的合约工程。 12 | 13 |

14 | 15 |

16 | 17 | 18 | 在Visual Studio菜单中单击 `生成`->`生成解决方案` (快捷键: Ctrl + Shift + B) 开始编译。 19 | 20 | 编译完成后,在项目的`bin/Debug`路径下会生成一个名为`NEP5.avm`的NEO 智能合约文件。 21 | 22 | `SmartContractDemo.abi.json`是一个智能合约的描述文件,它包含有关于合约的ScriptHash、合约项、参数和返回值信息。有关智能合约ABI的更多信息可以查看[NeoContract ABI](https://github.com/neo-project/proposals/blob/master/nep-3.mediawiki)。 23 | 24 |

25 | 26 |

27 | 28 | > [!!!!**注意**] 29 | > 30 | > 由于neon默认使用nep-8编译.dll文件,这会与nep-5发生冲突,因此我们需要使用nep-5兼容的方法执行.avm。 31 | > 32 | > 打开Power Shell或命令提示符(CMD),输入路径bin/Debug,并输入以下命令 (用自己的工程文件替换nep5.dll): 33 | > 34 | > ``` 35 | > neon SmartContractDemo.dll --compatible 36 | > ``` 37 | 38 | > 新的`SmartContractDemo.avm`文件和 `SmartContractDemo.abi.json` 文件将覆盖相应的旧文件。 39 | 40 | ## 部署合约 41 | 42 |

43 | 44 |

45 | 46 | 我们可以使用NEO-GUI来部署新生成的合约文件。 47 | 48 | 1. 打开0.json钱包文件,单击 `高级` -> `部署合约`。 49 | 50 | 2. 单击合约部署对话框中的 `加载` 按钮选择已编译的合约文件`xxx.avm`。 51 | 52 | *复制代码框下显示的合约脚本散列,以备稍后在合约调用中使用。* 53 | 54 | 3. 填写信息和元数据字段中的参数。 55 | 56 | 对于这个合约,参数是0710,返回值是05。 57 | 58 | 详细规则可以参考[智能合约参数和返回值](http://docs.neo.org/zh-cn/sc/Parameter.html)。 59 | 60 | 选中 `需要创建存储区域` 复选框 61 | 62 | 不需要检查 `需要动态调用` 选项。 63 | 64 | 4. 所有参数都设置完成后,单击 `部署` -> `测试` -> `调用`。 65 | 66 | 67 | #### 调用合约 68 | 69 | 现在你可以调用最近发布的智能合约了。 70 | 71 | 1. 单击 `高级` -> `合约调用` -> `方法调用`。 72 | 2. 将最后一个步骤中复制的合约脚本散列粘贴到 `ScriptHash` 并点击搜索按钮。这时会自动显示合约的相关信息。 73 | 74 | 3. 点击 `参数` 按钮旁边的 `…`,进入参数编辑界面。输入参数。在这个合约中,可以输入任意参数,因为main方法中不使用这些参数。 75 | 76 | 4. 单击 `尝试` 按钮来测试合约。如果没有发现错误,则单击 `调用`,这可能需要花费一些GAS。 77 | 78 | 79 | 如果调用成功,账户余额中将减少相应的GAS数。 80 | 81 | ## 下一步骤 82 | **恭喜你!**, 你已经成功地设置了私有网络并调用了你的第一个智能合约。现在让我们开始学习[NEO 智能合约的基础知识并开发你的第一个合约。](Smart_Contract_basics.md) 83 | -------------------------------------------------------------------------------- /cn/9-smartContract/Development_privateChain.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: cn 4 | lang-ref: Development_privateChain 5 | --- 6 | 7 | # 私有网络 8 | 9 | NEO区块链已经上线多年,每天都有大量的用户在主网上进行交易和使用dApps。当开发智能合约时,你必须将合约部署到区块链上并通过调用对其进行测试。在主网上部署智能合约或者dApp需要花费真正的Gas,这对于我们这些开发人员来说并不是一个经济的选择。当开发人员想要在那里测试智能合约或者dApp时,最好的方式是使用测试网络 (TestNet) 或私有网络(PrivateNet)。 10 | 11 | 测试网络是一个用户可以开发、委托和测试程序的环境。测试网络上的测试程序会花费测试网的GAS(不是真正的GAS!!)作为网络的手续费。测试网络的 NEO和GAS可以在官方网站上免费申请使用。 12 | 13 | 测试网络的所有区块链都独立于主网。如果只是想要开发一个简单的智能合约或者尝试去注册资产,使用测试网络就足够了。测试通过后,再将开发转移到主网上进行在线操作。 14 | 15 | 所有交易和区块信息都可以在 [NEO scan](https://neoscan-testnet.io/) 上查看。 16 | 17 | 此外,对于像我们这样的想要逐步学习开发智能合约的开发人员来说,使用四个节点构建一个私有链并从私有链中提取NEO和GAS是一种更方便、更快速的方法。通过使用这样的私有链,开发人员不必担心GAS的开销,而且在本地网络上进行部署和测试要快得多。 18 | 19 | 20 | #### 搭建私有链 21 | 22 | 在本教程中,我们在一个简化的私有链上进行开发,可以在这个 [Github存储库]( https://github.com/steven1227/NEO-Private-Net) 中下载。 23 | 24 | 这个存储库中包含一个配置好的私有链,可以在下载之后运行它。其中neo-cli的版本号是2.8.0,gui版本号是2.7.6。 25 | 26 | 克隆或下载存储库之后,运行以下四个命令行脚本来启动私有网络。 27 | 28 | ``` 29 | enter node1 folder,double click 1Run.cmd 30 | 31 | enter node2 folder,double click 1Run.cmd 32 | 33 | enter node3 folder,double click 1Run.cmd 34 | 35 | enter node4 folder,double click 1Run.cmd 36 | 37 | ``` 38 | 39 | 现在私有链就可以运行起来了。所有的NEO和GAS创世区块都放在钱包文件 `1.json`中。 40 | 41 | 打开NEO-GUI,点击 `钱包` -> `打开钱包库`,打开位于*文件夹* `node1`下的 `1.json` 文件,输入密码 **11111111**。 42 | 43 | 区块高度大约是30。请打开Neo-GUI查看账户余额。 44 | 45 |

46 | 47 |

48 | 49 | 50 | > [!注意] 51 | > 智能合约的部署和调用需要消耗GAS。由于每产生一个新的区块就会产生GAS,这就使得在新建的私有链上会产生有限的GAS,因此建议用户现在不要关闭私有链,从而可以产生足够的GAS以便之后使用。 52 | 53 | 你可以试着去创建一个新的钱包,并向钱包中转入一笔资金。 54 | 55 | 1. 打开NEO-GUI并单击 `钱包` -> `创建一个钱包库` ,然后按照屏幕上显示的说明进行操作。 56 | 2. 钱包创建成功后,右键单击标准账户中的地址,选择 `查看私钥` 来查看账户信息(地址,公钥,私钥)。 57 | 3. 复制地址进行下一步操作。 58 | 4. 再次打开钱包文件 `1.json` 并单击 `交易` ,然后单击 `+` 号。现在让我们添加一个新的交易。 59 | 60 | *资产* 类型是 `NEO` ,金额是要转账的NEO数量,`payto` 是上一个步骤中复制的地址。 61 | 62 |

63 | 64 |

65 | 66 | 5. 确认完成后,就可以看到交易成功了,同时会产生一个交易ID。单击 `交易历史ID` ,可以看到刚刚发起的那笔交易,这个时候可能显示的状态是 `未确认` 。等待几秒钟后,它将显示确认数,这个数字代表着区块已被共识节点确认。之后,打开刚才创建的新钱包,你会发现余额发生了变化。 67 | 6. 再次打开钱包文件 `1.json` ,你可以看到另一个全局资产 `GAS` 。在NEO的区块链上,GAS是部署和运行智能合约的燃料。 `NEO` 的持有者可以领取GAS。在GUI中,单击 `高级` -> ` NEO Gas领取` ,你将看到可以领取的GAS数。然后点击 `领取` ,就会在你的账户中增加相应的GAS余额。 68 | -------------------------------------------------------------------------------- /cn/9-smartContract/Development_set_up.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: cn 4 | lang-ref: Development_set_up 5 | --- 6 | 7 | 8 | # C#智能合约开发环境 9 | 10 | NEO C#的开发人员是非常幸运的,因为NEO区块链本身是基于C#搭建的,从编译器到工具箱,C#开发环境得到了广泛的支持,因此对于那些.NET开发人员来说,开始学习NEO智能合约的开发是一件非常容易的事情。而对于那些没有接触过C#的用户而言,开始编写智能合约和dApp也不是一件难事。 11 | 12 | ## 环境 13 | 使用C#语言编写智能合约最好的方式是,在本地开发环境中使用支持NEO智能合约的IDE进行开发。幸运的是,NEO正在为开发人员提供一系列工具从而可以方便他们的开发。对开发环境的唯一的要求是Windows的操作系统,建议是Windows 10 64位系统。 14 | 15 | 对于非windows用户,如MAC和Linux用户,最好的选择是使用在线编辑器和编译器,这样更便于智能合约的开发和部署。这部分内容在这篇[文档]( https://medium.com/neweconolab/with-neoray-neo-smart-contract-development-has-never-been-easier-edad41cc3ae6)中有详细说明。 16 | 17 | 18 | 19 | ### Windows 20 | 21 | 为了建立一个NEO私有网络和开发环境,开发人员必须安装一些依赖项: 22 | 23 | - [NET FrameWork](https://dotnet.microsoft.com/download/dotnet-framework-runtime/net472) 24 | - [NET Core](https://dotnet.microsoft.com/download) 25 | 26 | 另外,为了开发基于C#的智能合约,我们还必须使用IDE,而最好的选择是Visual Studio: 27 | 28 | - [Microsoft Visual Studio](https://visualstudio.microsoft.com/vs/community/) 29 | 30 | 31 | 现在让我们准备智能合约的开发环境。 32 | 33 | ### Visual Studio 安装 34 | 35 | #### 安装并打开 visual studio. 36 | 37 | 在安装期间选择 `.NET Core 跨平台` 开发选项 38 | 39 |

40 | 41 |

42 | 43 | #### 安装 NeoContractPlugin 44 | 45 | 打开Visual Studio 2017,点击 `工具` - > `扩展和更新` ,单击左侧栏的 `联机` 选项,搜索NEO并安装NeoContractPlugin (过程中必须联网操作)。 46 | 47 |

48 | 49 |

50 | 51 | #### 配置 neo-compiler 52 | 53 | 1. 下载 [neo-compiler](https://github.com/neo-project/neo-compiler) 工程到本地主机。 54 | 2. 在Visual Studio 2017中点击 `文件` -> `打开` -> `工程/解决方案`,在工程文件中选择neo-compiler.sln。 55 | 56 | 3. 右键单击列表中的neon项目,然后单击 `启动` 。 57 | 58 | 4. 配置好发布路径后,单击 `启动` 。 59 | 60 | 在我的设置中,在`xxx\neo-compiler-master\neo-compiler-master\neon\bin\Debug\netcoreapp2.0\publish` 路径下会生成一个 `neon.exe` 文件。 61 | 62 | 5. 将neon添加到系统变量 `PATH` 中。 63 | 64 | 对于Windows10用户,按 `Windows+S` 并输入环境变量,选择编辑账户的环境变量并将其添加到 `Path` 中。 65 | 66 | 67 | #### 创建一个智能合约工程 68 | 1. 点击 `文件` -> `创建` -> `工程`。 69 | 2. 在列表中选择 `NeoContract` 并对设置做一些必要的修改,然后单击 `确认`。 70 | 71 |

72 | 73 |

74 | 75 | 使用从智能合约继承的默认类创建工程后,将自动生成一个C#文件。如下面的截图所示,现在你就实现了一个Hello World合约了。 76 | 77 |

78 | 79 |

80 | 81 | 然而,上面只演示了一种简单的数据存储方法——使用键值对的方法在私有存储区域中存储数据。 82 | -------------------------------------------------------------------------------- /cn/9-smartContract/Give_an_ITO.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: cn 4 | lang-ref: Give_an_ITO 5 | --- 6 | 7 | # 发起ITO(首次通证发行) 8 | 9 | 10 | > 11 | > **目的**: 了解NEP5的基本概念 12 | > 13 | > **要点**: 14 | > 15 | > 1. 什么是ITO(首次通证发行) 16 | > 17 | > 2. MintToken函数的实现 18 | > 19 | > 20 | 21 | ## 什么是ITO(首次通证发行) 22 | 23 | 我们已经知道什么是 `NEP-5` 通证以及如何 [实现](https://github.com/neo-ngd/NEO-Tutorial/blob/steven/smartContract/What_is_nep5.md)NEP-5通证。 NEP-5通证可用于在用户之间进行转账的资产。但是,仅仅发行此类 `NEP-5` 通证对资产发行人而言并不能盈利,因为你必须手动将此类资产与外部世界进行链接。在NEO中,允许你在 `NEP-5` 通证和NEO等全局资产之间进行交易。 24 | 25 | ITO代表首次通证发行。通过这个过程,你可以对资产进行数字化或通证化,并通过互联网公开发布。这意味着你可以通过任何资产的价值创建业务、公司或项目。通过ITO,你可以生成代表你的资产的数字代币或通证。你可以不断地以电子方式转移这些代币或者通证。 26 | 27 | NEO中的ITO标准是基于我们之前实现的NEP-5标准的。除了已经在NEP-5中定义的那些方法和属性之外,ITO中还应该添加一些新的方法和属性。 28 | 29 | ## 时间戳 30 | 值得注意的是,每个ITO的有效时间和通证数量都是有限制的。因此,在ITO合约中,我们应该定义ITO的开始时间和ITO的完成时间。在这段时间之外,ITO不能被成功调用。 31 | 32 | ```csharp 33 | //ito的开始时间。即2017年8月14日星期一下午4:00:00 34 | private const int ico_start_time = 1502726400; 35 | //ito的结束时间。即2017年8月28日星期一下午4:00:00 36 | private const int ico_end_time = 1503936000; 37 | ``` 38 | 39 | 在合约中,我们添加了 `CurrentSwapRate` 汇率函数。该函数判断当前区块时间是否在预定义的ITO时段内。在函数内部,它通过调用 `Blockchain.GetHeader` 和 `BlockChain.GetHeight ` API获取区块时间。这些API可以直接查询区块和区块头的信息。更多API信息可以点击[此处](https://docs.neo.org/en-us/sc/reference/api/neo.html)查看。 40 | 41 | ```csharp 42 | // 函数CurrentSwapRate()返回在通证兑换期间,ico通证和neo之间的当前汇率 43 | private static ulong CurrentSwapRate() 44 | { 45 | // factor是一个浮点型常量。 rate表示1 NEO => 1000 NEP5 46 | const ulong basic_rate = 1000 * factor; 47 | const int ico_duration = ico_end_time - ico_start_time; 48 | BigInteger total_supply = Storage.Get(Storage.CurrentContext, "totalSupply").AsBigInteger(); 49 | if (total_supply >= total_amount) return 0; 50 | uint now = Blockchain.GetHeader(Blockchain.GetHeight()).Timestamp; 51 | int time = (int)now - ico_start_time; 52 | if (time < 0){ 53 | return 0; 54 | } else if (time > ico_duration){ 55 | return 0; 56 | } else{ 57 | return basic_rate; 58 | } 59 | } 60 | ``` 61 | > 在这个 `CurrentSwapRate` 的代码片段中,只返回了基本汇率,但是,在真实的ITO中,由于时间周期不同,程序可以返回不同的兑换汇率。 62 | 63 | ## MintToken 64 | 65 | `MintToken` 方法是ITO合约中最重要的方法(要学习的内容还有很多)。考虑一下这种情况,项目已经发布并将其通证作为该项目的一部分对外提供。客户可以将手头上的NEO捐赠给该项目,同时将获得该项目的部分 `NEP-5` 通证。这个过程我们称之为 `MintToken`。 66 | 67 | 68 | 69 | 现在让我们实现 `MintToken` 函数。首先,在 `MintToken` 方法中,我们必须首先获取 `交易` 对象,这是该智能合约的脚本容器。 70 | 71 | ```csharp 72 | Transaction tx = (Transaction)ExecutionEngine.ScriptContainer; 73 | ``` 74 | 75 | 接下来,我们必须获取该交易的 `引用` 。这里,引用代表该交易输入的相应输出。获取引用后,我们将验证发送到合约地址(this.address)的输出是否为NEO。确认后,我们可以通过此 `TransactionOutput` 对象的 `ScriptHash` 获取相应的 `发送者` 地址。我们可以在[UTXO](https://github.com/neo-ngd/NEO-Tutorial/blob/master/9-smartContract/UTXO.md)中了解有关 `引用` 、 `输入` 和` 输出`的更多信息。 76 | 77 | ```csharp 78 | TransactionOutput reference = tx.GetReferences()[0]; 79 | // 检查资产是否是neo 80 | if (reference.AssetId != neo_asset_id) return false; 81 | byte[] sender = reference.ScriptHash; 82 | ``` 83 | 84 | 现在我们必须从transactionOutput的输出中获取NEO的总数。这里的 `输出` 是当前交易的每个输出。在ITO合约的这种类型的 `MintToken` 方法中,通常我们只接受一个全局资产如 `NEO` 。因此,在仅检查NEO资产的for循环中,对 `output.Value` 的值求和。 85 | 86 | ```csharp 87 | TransactionOutput[] outputs = tx.GetOutputs(); 88 | byte[] receiver = ExecutionEngine.ExecutingScriptHash; 89 | ulong value = 0; 90 | // 获取转入智能合约地址的Neo总量 91 | foreach (TransactionOutput output in outputs){ 92 | if (output.ScriptHash == receiver){ 93 | if (output.AssetId != neo_asset_id) { 94 | return false; 95 | } 96 | value += (ulong)output.Value; 97 | } 98 | } 99 | ``` 100 | 如果swap_rate等于0,则表示ITO已经完成,或者ITO数量超过了该通证的总供应量。这会导致众筹的失败,并触发 `Refund` 事件。 101 | 102 | ```csharp 103 | //众筹失败 104 | if (swap_rate == 0){ 105 | Refund(sender, value); 106 | return false; 107 | } 108 | ``` 109 | 成功处理以上语句后,就可以完成锻造流程了。首先获得由全局资产交换得到的通证。之后,分别更新余额和总供应量。最后,触发转账事件并返回true。 110 | 111 | ```csharp 112 | // 众筹成功 113 | ulong token = value * swap_rate / 100000000; 114 | BigInteger balance = Storage.Get(Storage.CurrentContext, sender).AsBigInteger(); 115 | Storage.Put(Storage.CurrentContext, sender, token + balance); 116 | BigInteger totalSupply = Storage.Get(Storage.CurrentContext, "totalSupply").AsBigInteger(); 117 | Storage.Put(Storage.CurrentContext, "totalSupply", token + totalSupply); 118 | Transferred(null, sender, token); 119 | return true; 120 | ``` 121 | 122 | 123 | ## 下一步骤 124 | 现在你已经成功地完成了你的第一个ITO,同时也熟悉了智能合约的大部分内容,下一部分内容涉及到更为复杂的合约,[即CGAS](https://github.com/neo-ngd/NEO-Tutorial/blob/master/9-smartContract/cgas/1_what_is_cgas.md)。 125 | -------------------------------------------------------------------------------- /cn/9-smartContract/NFT.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## 什么是非同质通证? 4 | 5 | 非同质通证(NFT)可以被看作是一个财产契约——每个财产都是唯一的,并且携带一些不可更改的信息(例如,财产的物理地址),不过其他信息,例如财产的所有者,是可以更改的。NFT智能合约有助于追踪真实世界中物品的所有权,在网络游戏中也是如此,它允许用户拥有特有的角色或限量供应的道具,这些道具可以在用户之间转移,而无需获得游戏所有者的许可。 6 | 7 | NEO智能经济的NFT提案标准目前正在开发中。这是使用C#写的一个例子,展示了如何编写这样一个智能合约。在NEP-5 (可替换的) 通证功能之间有一些重叠,以便API的编写能更容易的进行适配调整。 8 | 9 | 10 | ### 方法 11 | 12 | #### name 13 | 14 | ```csharp 15 | public static string name() 16 | ``` 17 | 18 | 返回通证的名称。例如, "MyNFT"。 19 | 20 | 每次调用此方法时,它都必须返回相同的值。 21 | 22 | #### symbol 23 | 24 | ```csharp 25 | public static string symbol() 26 | ``` 27 | 28 | 返回此合约中管理的通证的短字符串符号。例如,"MNFT"。这个符号应该是简短的 (推荐是3-8个字符),没有空格字符或换行符,并且应该限于大写的拉丁字母(即英语中使用的26个字母)。 29 | 30 | 每次调用此方法时,它都必须返回相同的值。 31 | 32 | #### totalSupply 33 | 34 | ```csharp 35 | public static BigInteger totalSupply() 36 | ``` 37 | 38 | 返回系统中部署的通证的供应总量。 39 | 40 | #### decimals 41 | 42 | ```csharp 43 | public static byte decimals() 44 | ``` 45 | 46 | 返回通证使用的小数位数——例如,8,表示将通证数量除以100,000,000,从而得到它的用户表示。 47 | 48 | 如果这个合约中管理的通证是不可分割的,函数应该返回 0。 49 | 50 | 如果函数返回非零值,则必须实现此标准中的所有''OPTIONAL''方法。 51 | 52 | 每次调用此方法时,它都必须返回相同的值。 53 | 54 | #### tokens 55 | 56 | ```csharp 57 | public static enumerator tokens() 58 | ``` 59 | 60 | 返回此合约中已经发行的所有通证的 枚举值。 61 | 62 | #### transfer 63 | 64 | ```csharp 65 | public static bool transfer(byte[] to, byte[] tokenid) 66 | ``` 67 | 68 | 将id为 tokenid的通证转到地址to。 69 | 70 | 参数 tokenid应该是一个有效的NFT。如果无效,这个方法应该抛出异常。 71 | 72 | 参数to 应该是一个20字节长的地址。如果不是,这个方法应该抛出异常。 73 | 74 | 如果要转账的通证有多个所有者,函数应该返回false。 75 | 76 | 如果方法执行成功,它必须触发转账 事件,并且必须返回 true,即使通证是被发送给合约所有者本人。 77 | 78 | 函数应该检查所有者的地址是否等于合约调用者的散列值。如果是,则应处理转账;如果不是,函数应该使用SYSCALL Neo.Runtime.CheckWitness 来对转账操作进行验证。 79 | 80 | 如果 to 地址是已经部署的合约,函数应该检查该合约的 payable 标志,从而决定是否应该将通证转账到该合约。 81 | 82 | 如果没有处理转账事件,函数应该返回 false。 83 | 84 | ```csharp 85 | public static bool transfer(byte[] from, byte[] to, BigInteger amount, byte[] tokenid) 86 | ``` 87 | 88 | ''OPTIONAL'': 如果decimals() > 0,则必须实现此方法。 89 | 90 | 将具有id tokenid 的通证相应的数量从一个地址from转到另一个地址to。 91 | 92 | 参数tokenid应该是一个有效的NFT。如果不是,这个方法应该抛出异常。 93 | 94 | 参数 fromto 应该是20字节长的地址。如果不是,这个方法应该抛出异常。 95 | 96 | 参数 amount 应该大于或等于 0,并且应该小于或等于pow(10, decimals())。如果不是,这个方法应该抛出异常。 97 | 98 | 如果from账户余额没有足够的通证来消费,函数应该返回false。 99 | 100 | 如果方法执行成功,它必须触发转账事件,并且必须返回 true,即使数量0,或者通证被发送给合约所有者本人。 101 | 102 | 函数应该检查from 地址是否等于合约调用者的散列值。如果是,则应处理转账;如果不是,函数应该使用SYSCALL Neo.Runtime.CheckWitness 来对转账操作进行验证。 103 | 104 | 如果to地址是已经部署的合约,函数应该检查该合约的payable 标志,从而决定是否应该将通证转到该合约。 105 | 106 | 如果没有处理转账操作,函数应该返回false。 107 | 108 | #### ownerOf 109 | 110 | ```csharp 111 | public static enumerator ownerOf(byte[] tokenid) 112 | ``` 113 | 114 | 返回一个枚举值,该枚举值包含拥有指定通证的所有共同所有者。 115 | 116 | 参数tokenid应该是一个有效的NFT。如果不是,这个方法应该抛出异常。 117 | 118 | #### tokenURI 119 | 120 | ```csharp 121 | public static string tokenURI(byte[] tokenid) 122 | ``` 123 | 124 | 返回给定资产的不同的统一资源标识符(URI)。通证的URI数据提供了一个引用,以获取关于特定通证或通证数据的更多信息。 125 | 126 | 参数tokenid应该是一个有效的NFT。如果不是,这个方法应该抛出异常。 127 | 128 | #### balanceOf 129 | 130 | ```csharp 131 | public static BigInteger balanceOf(byte[] owner, byte[] tokenid) 132 | ``` 133 | 134 | 返回指定所有者账户的指定通证的余额。 135 | 136 | 参数tokenid应该是一个有效的NFT。如果不是,这个方法应该抛出异常。 137 | 138 | 参数owner 应该是一个20字节长的地址。如果不是,这个方法应该抛出异常。 139 | 140 | 如果owner 是未使用的地址,或者不是指定通证的所有者,则此方法应该返回0。 141 | 142 | #### tokensOfOwner 143 | 144 | ```csharp 145 | public static enumerator tokensOfOwner(byte[] owner) 146 | ``` 147 | 返回一个枚举值,该枚举值包含指定地址所拥有的所有通证。 148 | 149 | 参数owner 应该是一个20字节长的地址。如果不是,这个方法应该抛出异常。 150 | 151 | ### 事件 152 | 153 | 154 | #### transfer 155 | 156 | ```csharp 157 | public static event transfer(byte[] from, byte[] to, BigInteger amount, byte[] tokenid) 158 | ``` 159 | 160 | 必须在通证转账(包括零值转账)时触发。 161 | 162 | 创建新通证的合约应该在通证创建时触发转账事件,其中地址from设置为null。 -------------------------------------------------------------------------------- /cn/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#Your first NEO contract) 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 | -------------------------------------------------------------------------------- /cn/9-smartContract/UTXO.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: cn 4 | lang-ref: UTXO 5 | --- 6 | 7 | # UTXO 8 | 9 | > 10 | > **目的**: 了解UTXO的概念 11 | > 12 | > **要点**: 13 | > 14 | > 1. UTXO的概念 15 | > 2. NEO中UTXO的结构 16 | > 17 | > 18 | 19 | ## UTXO的概念 20 | 21 | 如果你熟悉区块链或之前使用过数字货币的话,你可能听说过 `UTXO` 这个词。UTXO代表`未花费的交易输出` ,它表示区块链上未被花费交易的输出,可作为新交易的输入。 22 | 23 | 当使用数字货币钱包时,你可能会看到代表账户余额的数字。事实上,如果它是基于UTXO模型的区块链,就会有 `账户余额` 的概念。实际上,存储的数字是由钱包应用程序聚合产生的,而使用的来源就是UTXO。UTXO的概念与现实生活中的钱包非常相似。假设你打开钱包,看到100美元。你不知道100美元从哪里来。它可能是你的客户给你付款,作为你上周网站设计的报酬,这就是一个UTXO,它来自于你的客户,金额是100美元。然后,你想从钱包里拿出10美元买一本杂志。花了10美元后,你得到90美元作为找零。那么你的UTXO现在就是90美元。你在杂志店花的10美元对他来说就像一个UTXO,直到他把它花在他的下一笔交易上。 24 | 25 | 26 | ## NEO中的UTXO 27 | 28 | NEO区块链支持原生资产,其中最重要的两个是NEO和GAS。原生资产是基于未花费的交易输出(UTXO)的,可得到区块链的原生支持。与此形成对比的是,我们目前所构建的通证完全依赖于定制的智能合约。与账户余额模型不同,UTXO模型不直接记录账户资产,而是通过未花费的输出来计算用户资产。每个UTXO资产(例如全局资产)都是一个输入-输出的关联模型,`输入` 指示资金来源, `输出` 指示资产去处。 29 | 30 | 在下图中,Alice从她手持NEO中领取到8个GAS,这被记录在交易 *#101*的第一个输出中。当Alice向Bob转账3个GAS时,新交易记录的输入为8个GAS,表示为交易 `#101` 的0号输出。此外,在另一个交易 `#201` 中,一个输出指向转账给Bob的3个GAS,而另一个输出指向返回给Alice自己的5个GAS (找零)。 31 | 32 |

33 | 34 |

35 | 36 | 让我们看一下NEO中的交易结构。如上图所示, `输出` 本身具有索引属性,因为它位于输出列表中。`输出` 由 `AssetId` 、`Amount` 和 `ScriptHash` 组成,ScriptHash是收款地址。`输入` 结构指示了交易的来源,它包含一个 `PreHash` ,它指向交易的来源,以及一个 `Preindex` ,它指向前一个交易的相应的输出。 37 | -------------------------------------------------------------------------------- /cn/9-smartContract/What_is_nep5.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: cn 4 | lang-ref: What_is_nep5 5 | --- 6 | 7 | # NEP-5合约 8 | 9 | > 10 | > **目的**: 学习NEP5的基本概念 11 | > 12 | > **要点:**: 13 | > 14 | > 1. 什么是NEP (NEO加强提案) 15 | > 16 | > 2. NEP5的细节 17 | > 18 | 19 | ## 什么是NEP? 20 | NEP代表NEO增强提案。NEP是一种设计文档,用于向NEO社区提供信息,或者描述NEO/流程/环境的新特性。NEP应该提供该特性的简明的技术规范和基本原理。NEP作者负责在社区内建立共识并记录不同意见。在这个 [github存储库]( https://github.com/neo-project/proposals) 中已经有超过10个NEPS。 21 | 22 | 对于NEO实现者而言,NEPs是跟踪其实现进度的一种简便的方法。理想情况下,每个实现维护者都会列出他们已经实现的NEPs。这将为终端用户提供一种便捷的方法,来了解给定实现或库的当前状态。 23 | 24 | 如果有人有兴趣提出一个新的NEP,那么可以先查看一下 [NEP-1]( https://github.com/neo-project/proposals/blob/master/nep-1.mediawiki),然后克隆存储库并将你所提出的NEP添加到存储库中。这里有一个模板NEP。然后向这个存储库提交一个Pull-Request请求。 25 | 26 | ## NEP-5介绍 27 | 28 | NEP-5标准是一个通证标准,它表示一个通证化的智能合约。该标准可以规范在NEO区块链上发行的通证。提供一个规范的与通证进行交互的方法,可以使生态系统无需去维护一些基本操作的定义,而这些操作是使用了通证的智能合约所必需的。 29 | 30 | 在NEP-5标准中,提供了一些方法同时可以触发一个事件 31 | 32 | 33 | ### 方法 34 | 35 | #### totalSupply 36 | 37 | ```csharp 38 | public static BigInteger totalSupply() 39 | ``` 40 | 41 | 返回系统中部署的通证的供应总量。 42 | 43 | #### name 44 | 45 | ```csharp 46 | public static string name() 47 | ``` 48 | 49 | 返回通证的名称。例如,"MyToken"。 50 | 51 | 每次调用此方法时,它都必须返回相同的值。 52 | 53 | #### symbol 54 | 55 | ```csharp 56 | public static string symbol() 57 | ``` 58 | 59 | 返回此合约中管理的通证的短字符串符号。例如,"MYT"。这个符号应该是简短的 (推荐是3-8个字符),没有空格字符或换行符,并且应该限于大写的拉丁字母(即英语中使用的26个字母)。 60 | 61 | 每次调用此方法时,它都必须返回相同的值。 62 | 63 | #### decimals 64 | 65 | ```csharp 66 | public static byte decimals() 67 | ``` 68 | 69 | 70 | 返回通证使用的小数位数——例如,8,表示将通证数量除以100,000,000,从而得到它的用户表示。 71 | 72 | 每次调用此方法时,它都必须返回相同的值。 73 | 74 | #### balanceOf 75 | 76 | ```csharp 77 | public static BigInteger balanceOf(byte[] account) 78 | ``` 79 | 80 | 返回账户的通证余额。 81 | 82 | 参数 account 应该是20字节长的地址。如果不是,这个方法应该抛出异常。 83 | 84 | 如果账户 是未使用的地址,则此方法必须返回0。 85 | 86 | #### transfer 87 | ```csharp 88 | public static bool transfer(byte[] from, byte[] to, BigInteger amount) 89 | ``` 90 | 91 | 从from账户转数量为amount的通证至to账户。 92 | 93 | 参数 fromto 应该是20字节长的地址。如果不是,这个方法应该抛出异常。 94 | 95 | 参数 amount 应该大于或等于 0。如果不是,这个方法应该抛出异常。 96 | 97 | 如果from账户余额没有足够的通证来消费,函数必须返回false。 98 | 99 | 如果方法执行成功,它必须触发转账事件,并且必须返回 true,即使数量0,或者fromto是相同的地址。 100 | 101 | 函数应该检查from 地址是否等于合约调用者的散列值。如果是,则应处理转账;如果不是,函数应该使用SYSCALL Neo.Runtime.CheckWitness 来对转账操作进行验证。 102 | 103 | 如果to地址是已经部署的合约,函数应该检查该合约的payable 标志,从而决定是否应该将通证转到该合约。 104 | 105 | 如果没有处理转账操作,函数应该返回false。 106 | 107 | ### 事件 108 | #### transfer 109 | ```csharp 110 | public static event transfer(byte[] from, byte[] to, BigInteger amount) 111 | ``` 112 | 113 | 必须在通证转账(包括零值转账)时触发。 114 | 115 | 创建新通证的合约必须在通证创建时触发转账事件,其中地址from设置为null。 116 | 117 | 销毁通证的合约必须在通证销毁时触发转账事件,其中地址to设置为null。 118 | 119 | ---------- 120 | 121 | ## 下一步骤 122 | 现在让我们实现一个NEP-5通证! 123 | -------------------------------------------------------------------------------- /cn/9-smartContract/What_is_smart_contract.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: cn 4 | lang-ref: what-is-smart-contract 5 | --- 6 | 7 | 8 | # 什么是智能合约 9 | 10 | ## 智能合约的流行 11 | 12 | 你听说过智能合约吗?最近,每个对区块链感兴趣,甚至那些对区块链不甚了解的人都在讨论“智能合约”这个词。智能合约的概念是由Nick Szabo在1994年提出的。 13 | 14 | > 智能合约是一个计算机层面的交易协议,用于执行一系列的合约项。合约旨在满足一些常见的合约条件。 15 | 16 | 他认为这种新型的合约是“智能的”,因为它们的功能远远超过了那些纸质版的合同。但这个过程并没有涉及到人工智能的范畴。智能合约是一组约定的集合,并以数字化的格式存在,包括各方履行这些约定时所遵循的各种协议。 17 | 18 | 从区块链的角度来看,智能合约是一组数字化的承诺,包括关于合约执行者履行这些承诺时达成的协议。区块链技术给我们提供了一个去中心化的、不可篡改的、高度可靠的系统,而在这个系统中智能合约有着至关重要的作用。智能合约是区块链技术最重要的特性之一,也是区块链被称为颠覆性技术的原因。它正日益提高我们社会结构的生产效率。 19 | 20 | 我们来对比一下智能合约与自动售货机。在现实生活中,投入10美元,按下按钮,你就可以拿到你想要的薯条之类的东西。而在智能合约中,输入数字货币和数据,你的账号就会输出你所预期的结果,例如驾照。智能合约是一种可以自动执行的合约,并接受着成千上万的人的监控,这使得它是不可变的,同时也是去中心化的。 21 | 22 |

23 | 24 |

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 | ![Merkle tree](merkle-tree.png) 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 ![Neo Specification](https://github.com/NeoResearch/yellowpaper/blob/master/sections/graphviz-images/graphviz-pbft.jpg?raw=true). 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: ![here](https://github.com/NeoResearch/yellowpaper/blob/master/sections/graphviz-images/graphviz-dbft-v2-recover.jpg?raw=true) 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 | NEO-Tutorial 10 |

A complete learning tutorial for NEO developers and learners

11 |
12 | 13 | ## 教程目录 14 | - [Introduction to NEO](en/1-introduction) 15 | - [Wallet](en/2-wallet) 16 | - [Transactions](en/3-transactions) 17 | - [Blocks](en/4-blocks) 18 | - [Network](en/5-network) 19 | - [Persistence](en/6-persistence) 20 | - [Consensus](en/7-consensus) 21 | - [NVM](en/8-nvm) 22 | - [Smart Contract](en/9-smartContract) 23 | 24 | ## 其他智能合约开发资料 25 | - [Neo Smart contract quick start](neo_docs_SmartContract_QuickStart) 26 | - [Neo-python tutorial](neo_docs_neopython_tutorial) 27 | -------------------------------------------------------------------------------- /index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | lang: en 4 | lang-ref: NEO-Tutorial 5 | --- 6 | 7 | 8 |
9 |

NEO-Tutorial

10 | NEO-Tutorial 11 |

A complete learning tutorial for NEO developers and learners

12 |
13 | 14 | ## Table of Tutorials 15 | - [Introduction to NEO](en/1-introduction) 16 | - [Wallet](en/2-wallet) 17 | - [Transactions](en/3-transactions) 18 | - [Blocks](en/4-blocks) 19 | - [Network](en/5-network) 20 | - [Persistence](en/6-persistence) 21 | - [Consensus](en/7-consensus) 22 | - [NVM](en/8-nvm) 23 | - [Smart Contract](en/9-smartContract) 24 | 25 | ## Other Smart contract development Learning Resources 26 | - [Neo Smart contract quick start](neo_docs_SmartContract_QuickStart) 27 | - [Neo-python tutorial](neo_docs_neopython_tutorial) 28 | -------------------------------------------------------------------------------- /neo-rebranding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo-rebranding.png -------------------------------------------------------------------------------- /neo_color_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_color_dark.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/2_gui_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/2_gui_4.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/2_privatechain_12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/2_privatechain_12.jpg -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/2_privatechain_14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/2_privatechain_14.jpg -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/2_privatechain_20.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/2_privatechain_20.jpg -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/2_privatechain_21.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/2_privatechain_21.jpg -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/2_privatechain_26.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/2_privatechain_26.jpg -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/2_privatechain_demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/2_privatechain_demo.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/2_wallet_height.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/2_wallet_height.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_1545037391347.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_1545037391347.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_1545632430020.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_1545632430020.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_1545633970239.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_1545633970239.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_1546846629992.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_1546846629992.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_2017-06-07_12-07-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_2017-06-07_12-07-03.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_check_nep5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_check_nep5.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_download_and_install_smart_contract_plugin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_download_and_install_smart_contract_plugin.jpg -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_edit_environment_variable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_edit_environment_variable.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_environment_variable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_environment_variable.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_install_core_cross_platform_development_toolset.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_install_core_cross_platform_development_toolset.jpg -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_new_smart_contract_project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_new_smart_contract_project.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_publish_and_profile_settings.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_publish_and_profile_settings.jpg -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_publish_and_profile_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_publish_and_profile_settings.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_publish_neo_compiler_msil_project.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_publish_neo_compiler_msil_project.jpg -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/3_smart_contract_function_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/3_smart_contract_function_code.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/README.md: -------------------------------------------------------------------------------- 1 | 2 | # NEO Smart contract 3 | This is a quick start for mart contract development . This tutorial is written by [Nicole](https://github.com/nicolegys). 4 | 5 | For English version, please view [EN](SmartContract_quickstart_en.md). 6 | 7 | For Chinese version, please view [CN](SmartContract_quickStart_cn.md). 8 | -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/compile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/compile.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/contractfile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/contractfile.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/deploy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/deploy.png -------------------------------------------------------------------------------- /neo_docs_SmartContract_QuickStart/nep5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_SmartContract_QuickStart/nep5.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/1.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/10.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/11.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/12.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/13.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/2.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/3.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/4.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/5.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/6.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/7.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/8.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/NeoPythonGuide/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/NeoPythonGuide/9.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/README.md: -------------------------------------------------------------------------------- 1 | 2 | # NEO-Python smart contract development 3 | This is a tutorial for smart contract development using neo-python. This tutorial is written by [Steve](https://github.com/HandsomeJeff) for NEO and the Chinese version is written by [Malorne](https://github.com/Malorne) 4 | 5 | Please follow [Part 1](part1_setup.md) for installation and setting up the environment, and [Part 2](part2_neopy.md) for smart contract development. 6 | 7 | For the Chinese version, please view the [quick start](neo_python_quickstart_cn.md). 8 | -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/build_contract1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/build_contract1.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/build_test_contract1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/build_test_contract1.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/build_test_contract2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/build_test_contract2.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/build_test_contract3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/build_test_contract3.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/built_test_contract4_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/built_test_contract4_1.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/built_test_contract4_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/built_test_contract4_2.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/built_test_contract4_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/built_test_contract4_3.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/claim_gas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/claim_gas.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/contract_hash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/contract_hash.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/contract_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/contract_search.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/create_wallet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/create_wallet.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/deploy_contract1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/deploy_contract1.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/deployed_contract1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/deployed_contract1.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/docker_pull.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/docker_pull.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/initialising.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/initialising.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/invoke_contract3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/invoke_contract3.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/invoke_contract4_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/invoke_contract4_1.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/invoke_contract4_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/invoke_contract4_2.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/invoke_contract5_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/invoke_contract5_delete.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/invoke_contract5_delete_query.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/invoke_contract5_delete_query.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/invoke_contract5_query.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/invoke_contract5_query.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/invoke_contract5_register.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/invoke_contract5_register.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/invoke_contract5_transfer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/invoke_contract5_transfer.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/invoke_contract5_transfer_query.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/invoke_contract5_transfer_query.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/new_domain_wallet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/new_domain_wallet.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/open_wallet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/open_wallet.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/own_wallet_with_assets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/own_wallet_with_assets.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/sc1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/sc1.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/scripthash_to_address.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/scripthash_to_address.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/scripthash_to_address2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/scripthash_to_address2.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/scripthash_to_address3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/scripthash_to_address3.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/send_assets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/send_assets.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/smartcontracts_in_neopy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/smartcontracts_in_neopy.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/started.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/started.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/testinvoke_contract1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/testinvoke_contract1.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/testinvoke_success_contract1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/testinvoke_success_contract1.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/wallet_address_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/wallet_address_box.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/wallet_claimed_gas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/wallet_claimed_gas.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/wallet_claimed_gas_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/wallet_claimed_gas_box.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/wallet_content.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/wallet_content.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/assets/wallet_content_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neo-ngd/NEO-Tutorial/3622a1f77aeef86866560d49eda9d6f8f70aeb70/neo_docs_neopython_tutorial/assets/wallet_content_box.png -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/smart-contracts/1-print.py: -------------------------------------------------------------------------------- 1 | """ 2 | In prompt.py, you need to execute `config sc-events on` to see the events showing up. 3 | Test & Build: 4 | neo> build 1-print.py test 07 05 True False 5 | """ 6 | 7 | def Main(): 8 | print("Hello World") 9 | -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/smart-contracts/2-print-and-notify.py: -------------------------------------------------------------------------------- 1 | """ 2 | In prompt.py, you need to execute `config sc-events on` to see the events showing up. 3 | Test & Build: 4 | neo> build 2-print-and-notify.py test 07 05 True False 5 | """ 6 | from boa.interop.Neo.Runtime import Log, Notify 7 | 8 | def Main(): 9 | # Print translates to a `Log` call, and is best used with simple strings for 10 | # development info. To print variables such as lists and objects, use `Notify`. 11 | print("log via print (1)") 12 | Log("normal log (2)") 13 | Notify("notify (3)") 14 | 15 | # Sending multiple arguments as notify payload: 16 | msg = ["a", 1, 2, b"3"] 17 | Notify(msg) 18 | -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/smart-contracts/3-calculator.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | This example shows how to to work with input parameters. 4 | Test & Build: 5 | neo> build 5-calculator.py test 070202 02 False False 6 | """ 7 | 8 | 9 | def Main(operation, a, b): 10 | 11 | if operation == 'add': 12 | return a + b 13 | 14 | elif operation == 'sub': 15 | return a - b 16 | 17 | elif operation == 'mul': 18 | return a * b 19 | 20 | elif operation == 'div': 21 | return a / b 22 | 23 | else: 24 | return -1 25 | -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/smart-contracts/4-storage.py: -------------------------------------------------------------------------------- 1 | """ 2 | This example shows how to write, read and manipulate value in storage. 3 | It is also a good example of using neo-python's `debugstorage`, which 4 | allows you to test `Put` operations with `build .. test` commands. 5 | Debugstorage is enabled by default, you can disable it with 6 | `debugstorage off` and, more importantly, reset it with 7 | `debugstorage reset`. 8 | Test & Build: 9 | neo> build 3-storage.py test 07 05 True False 10 | """ 11 | from boa.interop.Neo.Runtime import Log, Notify 12 | from boa.interop.Neo.Storage import Get, Put, GetContext 13 | 14 | def Main(): 15 | context = GetContext() 16 | 17 | # This is the storage key we use in this example 18 | item_key = 'test-storage-key' 19 | 20 | # Try to get a value for this key from storage 21 | item_value = Get(context, item_key) 22 | msg = ["Value read from storage:", item_value] 23 | Notify(msg) 24 | 25 | if len(item_value) == 0: 26 | Notify("Storage key not yet set. Setting to 1") 27 | item_value = 1 28 | 29 | else: 30 | Notify("Storage key already set. Incrementing by 1") 31 | item_value += 1 32 | 33 | # Store the new value 34 | Put(context, item_key, item_value) 35 | msg = ["New value written into storage:", item_value] 36 | Notify(msg) 37 | 38 | return item_value 39 | -------------------------------------------------------------------------------- /neo_docs_neopython_tutorial/smart-contracts/5-domain.py: -------------------------------------------------------------------------------- 1 | """ 2 | Testing: 3 | neo> build 4-domain.py test 0710 05 True False query ["test.com"] 4 | neo> build 4-domain.py test 0710 05 True False register ["test.com","AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y"] 5 | neo> build 4-domain.py test 0710 05 True False delete ["test.com"] 6 | neo> build 4-domain.py test 0710 05 True False transfer ["test.com","AK2nJJpJr6o664CWJKi1QRXjqeic"] 7 | Importing: 8 | neo> import contract 4-domain.avm 0710 05 True False 9 | neo> contract search ... 10 | Using: 11 | neo> testinvoke 5030694901a527908ab0a1494670109e7b85e3e4 query ["test.com"] 12 | neo> testinvoke 5030694901a527908ab0a1494670109e7b85e3e4 register ["test.com","AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y"] 13 | neo> testinvoke 5030694901a527908ab0a1494670109e7b85e3e4 delete ["test.com"] 14 | neo> testinvoke 5030694901a527908ab0a1494670109e7b85e3e4 transfer ["test.com","AZ9Bmz6qmboZ4ry1z8p2KF3ftyA2ckJAym"] 15 | """ 16 | from boa.interop.Neo.Runtime import Log, Notify 17 | from boa.interop.Neo.Storage import Get, Put, GetContext 18 | from boa.interop.Neo.Runtime import GetTrigger,CheckWitness 19 | from boa.builtins import concat 20 | 21 | 22 | def Main(operation, args): 23 | nargs = len(args) 24 | if nargs == 0: 25 | print("No domain name supplied") 26 | return 0 27 | 28 | if operation == 'query': 29 | domain_name = args[0] 30 | return QueryDomain(domain_name) 31 | 32 | elif operation == 'delete': 33 | domain_name = args[0] 34 | return DeleteDomain(domain_name) 35 | 36 | elif operation == 'register': 37 | if nargs < 2: 38 | print("required arguments: [domain_name] [owner]") 39 | return 0 40 | domain_name = args[0] 41 | owner = args[1] 42 | return RegisterDomain(domain_name, owner) 43 | 44 | elif operation == 'transfer': 45 | if nargs < 2: 46 | print("required arguments: [domain_name] [to_address]") 47 | return 0 48 | domain_name = args[0] 49 | to_address = args[1] 50 | return TransferDomain(domain_name, to_address) 51 | 52 | 53 | def QueryDomain(domain_name): 54 | msg = concat("QueryDomain: ", domain_name) 55 | Notify(msg) 56 | 57 | context = GetContext() 58 | owner = Get(context, domain_name) 59 | if not owner: 60 | Notify("Domain is not yet registered") 61 | return False 62 | 63 | Notify(owner) 64 | return owner 65 | 66 | 67 | def RegisterDomain(domain_name, owner): 68 | msg = concat("RegisterDomain: ", domain_name) 69 | Notify(msg) 70 | 71 | if not CheckWitness(owner): 72 | Notify("Owner argument is not the same as the sender") 73 | return False 74 | 75 | context = GetContext() 76 | exists = Get(context, domain_name) 77 | if exists: 78 | Notify("Domain is already registered") 79 | return False 80 | 81 | Put(context, domain_name, owner) 82 | return True 83 | 84 | 85 | def TransferDomain(domain_name, to_address): 86 | msg = concat("TransferDomain: ", domain_name) 87 | Notify(msg) 88 | 89 | context = GetContext() 90 | owner = Get(context, domain_name) 91 | if not owner: 92 | Notify("Domain is not yet registered") 93 | return False 94 | 95 | if not CheckWitness(owner): 96 | Notify("Sender is not the owner, cannot transfer") 97 | return False 98 | 99 | if not len(to_address) != 34: 100 | Notify("Invalid new owner address. Must be exactly 34 characters") 101 | return False 102 | 103 | Put(context, domain_name, to_address) 104 | return True 105 | 106 | 107 | def DeleteDomain(domain_name): 108 | msg = concat("DeleteDomain: ", domain_name) 109 | Notify(msg) 110 | 111 | context = GetContext() 112 | owner = Get(context, domain_name) 113 | if not owner: 114 | Notify("Domain is not yet registered") 115 | return False 116 | 117 | if not CheckWitness(owner): 118 | Notify("Sender is not the owner, cannot transfer") 119 | return False 120 | 121 | Delete(context, domain_name) 122 | return True 123 | --------------------------------------------------------------------------------