├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── SECURITY.md ├── create-decentralized-apps ├── 1-introduction.yml ├── 2-learn-dapps.yml ├── 3-learn-drizzle.yml ├── 4-drizzle-dapp.yml ├── 5-shipping-dapp.yml ├── 7-summary.yml ├── includes │ ├── 1-introduction.md │ ├── 2-learn-dapps.md │ ├── 3-learn-drizzle.md │ ├── 4-drizzle-dapp.md │ ├── 5-shipping-dapp.md │ ├── 6-knowledge-check.md │ └── 7-summary.md ├── index.yml └── media │ ├── drizzle-dapp.png │ ├── drizzle.png │ ├── modular-overview.png │ └── shipping-dapp.png ├── ethereum-blockchain-dev ├── 0-introduction.md ├── README.md └── index.yml ├── ethereum-networks ├── 1-introduction.yml ├── 2-public-networks.yml ├── 3-private-networks.yml ├── 4-prepare-for-mainnet.yml ├── 5-develop-deploy-development.yml ├── 6-deploy-ropsten-network.yml ├── 8-summary.yml ├── includes │ ├── 1-introduction.md │ ├── 2-public-networks.md │ ├── 3-private-networks.md │ ├── 4-prepare-for-mainnet.md │ ├── 5-develop-deploy-development.md │ ├── 6-deploy-ropsten-network.md │ ├── 7-knowledge-check.md │ └── 8-summary.md ├── index.yml └── media │ ├── .DS_Store │ ├── Infura_Test_Project.png │ ├── Infurakey.png │ ├── Metamask_0_Eth_Connect.png │ ├── Metamask_Ropsten_Test_with_1_Ether.png │ ├── Metamask_balance_after_deploying_to Ropsten.png │ ├── Reveal_Metamask_Seed_Phrase.png │ ├── Ropsten_Etherscan_with_deployed_contract.png │ ├── Ropsten_Test_Faucet_Request_Ether.png │ └── etherscan.png ├── smart-contracts ├── 1-introduction.yml ├── 2-smart-contracts.yml ├── 3-dev-kit-dependencies.yml ├── 4-blockchain-dev-kit.yml ├── 5-truffle.yml ├── 6-write-contract.yml ├── 7-test-contract.yml ├── 8-knowledge-check.yml ├── 9-summary.yml ├── includes │ ├── 1-introduction.md │ ├── 2-smart-contracts.md │ ├── 3-dev-kit-dependencies.md │ ├── 4-blockchain-dev-kit.md │ ├── 5-truffle.md │ ├── 6-write-contract.md │ ├── 7-test-contract.md │ ├── 8-knowledge-check.md │ └── 9-summary.md ├── index.yml └── media │ ├── bdk-install.png │ ├── build-contracts.png │ ├── compile-output.png │ ├── create-basic-project.png │ ├── deploy-contracts.png │ ├── deploy-details.png │ ├── git-download.png │ ├── new-solidity-project-selection.png │ ├── new-solidity-project.png │ ├── node-download.png │ ├── python-download.png │ ├── shipping-status-migration.png │ ├── start-ganache.png │ ├── truffle-test.png │ └── truffle.png ├── solidity ├── 1-introduction.yml ├── 2-what-is-solidity.yml ├── 3-language-basics.yml ├── 4-value-types.yml ├── 5-reference-types.yml ├── 6-exercise-write-your-first-contract.yml ├── 7-knowledge-check.yml ├── 8-summary.yml ├── includes │ ├── 1-introduction.md │ ├── 2-what-is-solidity.md │ ├── 3-language-basics.md │ ├── 4-value-types.md │ ├── 5-reference-types.md │ ├── 6-write-your-first-contract.md │ ├── 7-knowledge-check.md │ └── 8-summary.md └── index.yml └── tokens ├── 1-introduction.yml ├── 2-what-are-tokens.yml ├── 3-token-types.yml ├── 4-open-zeppelin.yml ├── 5-setup-project.yml ├── 6-write-token-contract.yml ├── 7-knowledge-check.yml ├── 8-summary.yml ├── includes ├── 1-introduction.md ├── 2-what-are-tokens.md ├── 3-token-types.md ├── 4-learn-open-zeppelin.md ├── 5-setup-project.md ├── 6-write-token-contract.md ├── 7-knowledge-check.md └── 8-summary.md ├── index.yml └── media ├── contract-library.png └── open-zeppelin.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 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 | # Learning Path: Get started with blockchain development 2 | 3 | This repo contains all the content for development of blockchain Learn modules. Once content is developed here, it will be moved over to the [Learn repository](https://github.com/MicrosoftDocs/learn-pr). 4 | 5 | ## Learn Module Outlines 6 | 7 | ### Module: Learn how to use Solidity 8 | 9 | 1. Introduction 10 | 2. Learn about Solidity 11 | 3. Understand the language basics 12 | 4. Explore value types 13 | 5. Explore reference types 14 | 6. Write your first contract 15 | 7. Knowledge check 16 | 8. Summary 17 | 18 | **Status:** Live 19 | 20 | ### Module: Write Ethereum smart contracts by using Soliidity 21 | 22 | 1. Introduction 23 | 2. Learn what smart contracts are 24 | 3. Install dependencies needed for the Blockchain Developer Kit for Ethereum 25 | 4. Exercise: Install and get started with the Blockchain Development Kit for Ethereum 26 | 5. Exercise: Install truffle 27 | 6. Exercise: Write a smart contract 28 | 7. Exercise: Test your smart contract 29 | 8. Knowledge check 30 | 9. Summary 31 | 32 | **Status:** Live 33 | 34 | ### Module: Create tokens using OpenZeppelin 35 | 36 | 1. Introduction 37 | 2. Learn about tokens 38 | 3. Explore token standards 39 | 4. Learn about OpenZeppelin 40 | 5. Exercise: Setup a new project and integrate with OpenZeppelin 41 | 6. Exercise: Write a token contract 42 | 7. Knowledge check 43 | 8. Summary 44 | 45 | **Status:** Live 46 | 47 | ### Module: Create a decentralized application 48 | 49 | 1. Introduction 50 | 2. Learn about dapps 51 | 3. Learn the technologies for building dapps 52 | 4. Exercise - Get started with Drizzle 53 | 5. Exercise - Create a dapp for a shipping contract 54 | 6. Knowledge check 55 | 7. Summary 56 | 57 | **Status:** Live 58 | 59 | ### Module: Learn how to deploy to Ethereum networks 60 | 61 | 1. Introduction 62 | 1. Overview of public Ethereum networks (mainnet, testnet) 63 | 1. Overview of private Ethereum networks (development, consortium) 64 | 1. Exercise: Connect to a test network and use the faucet 65 | 1. Exercise: Deploy to a network 66 | 1. Knowledge check 67 | 1. Summary 68 | 69 | **Status:** Live 70 | 71 | ## Contributing 72 | 73 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 74 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 75 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. 76 | 77 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide 78 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions 79 | provided by the bot. You will only need to do this once across all repos using our CLA. 80 | 81 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 82 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 83 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 84 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). 40 | 41 | -------------------------------------------------------------------------------- /create-decentralized-apps/1-introduction.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Introduction 5 | description: Introduction 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Introduction 12 | durationInMinutes: 1 13 | content: | 14 | [!include[](includes/1-introduction.md)] -------------------------------------------------------------------------------- /create-decentralized-apps/2-learn-dapps.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Learn about dapps 5 | description: Understand the importance of dapps for the Ethereum blockchain 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Learn about dapps 12 | durationInMinutes: 3 13 | content: | 14 | [!include[](includes/2-learn-dapps.md)] -------------------------------------------------------------------------------- /create-decentralized-apps/3-learn-drizzle.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Learn about Drizzle 5 | description: Understand what Drizzle is and how it's architecture works. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Learn about Drizzle 12 | durationInMinutes: 5 13 | content: | 14 | [!include[](includes/3-learn-drizzle.md)] -------------------------------------------------------------------------------- /create-decentralized-apps/4-drizzle-dapp.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Exercise - Get started with Drizzle 5 | description: Use Drizzle to create your first dapp. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Exercise - Get started with Drizzle 12 | durationInMinutes: 7 13 | content: | 14 | [!include[](includes/4-drizzle-dapp.md)] -------------------------------------------------------------------------------- /create-decentralized-apps/5-shipping-dapp.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Exercise - Create a dapp for a shipping contract 5 | description: Use Drizzle to create a dapp for a shipping contract. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Exercise - Create a dapp for a shipping contract 12 | durationInMinutes: 12 13 | content: | 14 | [!include[](includes/5-shipping-dapp.md)] -------------------------------------------------------------------------------- /create-decentralized-apps/7-summary.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Summary 5 | description: Summary 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Summary 12 | durationInMinutes: 1 13 | content: | 14 | [!include[](includes/7-summary.md)] 15 | quiz: 16 | title: Check your knowledge 17 | questions: 18 | - content: "What is the most accurate definition of Drizzle?" 19 | choices: 20 | - content: "Drizzle is a development framework used to make managing Ethereum projects easier." 21 | isCorrect: false 22 | explanation: "This definition best explains Truffle." 23 | - content: "Drizzle is a collection of libraries to make writing dapps easier." 24 | isCorrect: true 25 | explanation: "Correct. Drizzle provides tools to make it easier to write dapps." 26 | - content: "Drizzle is an Ethereum blockchain to run tests and execute commands." 27 | isCorrect: false 28 | explanation: "This definition best explains Ganache." 29 | - content: "Drizzle is a set of boilerplates that contain contracts, libraries and dapps." 30 | isCorrect: false 31 | explanation: "This definition best explains Truffle boxes." 32 | - content: "How do dapps operate?" 33 | choices: 34 | - content: "They have frontend code that connects in the backend to smart contracts on a blockchain network." 35 | isCorrect: true 36 | explanation: "Correct. Dapps have a frontend interface like a traditional web app, and connect to a smart contract backend." 37 | - content: "They operate just like traditional apps with a frontend that connects to a centralized backend server." 38 | isCorrect: false 39 | explanation: "Dapps are different than traditional apps because their backend is decentralized." 40 | - content: "They have frontend code that runs on it's own and do not require a backend to hook up to." 41 | isCorrect: false 42 | explanation: "Apps that allow for user interaction must have a backend server or blockchain network to connect to." 43 | - content: "They are a set of smart contracts that allow you to interact with them directly by calling their functions." 44 | isCorrect: false 45 | explanation: "Not quite. Dapps do connect to smart contracts in the backend, and must also have a frontend interface." 46 | - content: "Using the Drizzle Truffle Box, we can start up the web server for the project by running which command?" 47 | choices: 48 | - content: "npm rebuild" 49 | isCorrect: false 50 | explanation: "This command recompiles changes in the React project." 51 | - content: "npm run start" 52 | isCorrect: true 53 | explanation: "Correct. This command starts the dev server for React." 54 | - content: "npm build" 55 | isCorrect: false 56 | explanation: "This command compiles the changes in the the React project." 57 | - content: "npm run" 58 | isCorrect: false 59 | explanation: "The run command is used immediately before running a custom defined command such as start." -------------------------------------------------------------------------------- /create-decentralized-apps/includes/1-introduction.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | Blockchain products are useful for a variety of use cases ranging from supply-chain management to decentralized finance. Blockchain technology is being used across major markets and geographies. As the utilization of blockchain has increased and evolved, so has the development of blockchain applications. 4 | 5 | Decentralized apps, or dapps, are applications that have code running on a blockchain network. A dapp has frontend code and graphical user interface that is hooked up in the backend to smart contracts. 6 | 7 | In this module, you'll learn all about dapps and how to build your own. 8 | 9 | ## Learning Objectives 10 | 11 | By the end of this module you will be able to: 12 | 13 | - Explain what decentralized apps are 14 | - Identify the technology needed to create decentralized apps 15 | - Know how to use Drizzle to create apps 16 | - Build your own decentralized apps 17 | 18 | ## Prerequisites 19 | 20 | - [Fundamental knowledge about blockchain](https://docs.microsoft.com/learn/modules/intro-to-blockchain/?azure-portal=true) 21 | - [Solidity programming knowledge](https://docs.microsoft.com/learn/modules/blockchain-learning-solidity/?azure-portal=true) 22 | - [Ethereum smart contract knowledge](https://docs.microsoft.com/learn/modules/blockchain-solidity-ethereum-smart-contracts/?azure-portal=true) 23 | - Previous experience with a programming language like C, Python, or JavaScript 24 | - Basic knowledge of programming concepts 25 | - Familiarity with the command line to create new directories and install programs 26 | - Node.js installed 27 | - Truffle and Ganache CLI installed 28 | - Visual Studio Code installed 29 | - Blockchain Development Kit for Ethereum installed 30 | -------------------------------------------------------------------------------- /create-decentralized-apps/includes/2-learn-dapps.md: -------------------------------------------------------------------------------- 1 | # Learn about dapps 2 | 3 | A [dapp](https://ethereum.org/en/developers/docs/dapps/), or a 4 | decentralized application, uses smart contracts which 5 | execute on a blockchain network and allows users to interact with the application interface either through a web browser or mobile app. 6 | 7 | ## How do dapps operate 8 | 9 | [Dapps](https://ethereum.org/en/developers/docs/dapps/) differ from traditional applications in that they do not rely on a centralized server network, but instead operate on a decentralized peer-to-peer blockchain network. 10 | 11 | A dapp can have frontend code written in any language, just like a traditional web app, that can make calls to its backend. With dapps, the backend are smart contracts that are executed on a blockchain. 12 | 13 | Dapps are: 14 | 15 | - **Decentralized** which means that they execute independently on a decentralized network and not controlled by a centralized authority. 16 | - **Deterministic** which means that they perform the same function independent of which environment executes the code. 17 | - **[Turing complete](https://en.wikipedia.org/wiki/Turing_completeness)**, which means that they can perform any action which can be coded. 18 | - **Isolated** which means they are executed in a virtual environment known as 19 | [Ethereum Virtual Machine](https://ethereum.org/en/developers/docs/evm/) so that bugs or other problems won't affect other blocks or the normal functioning of the blockchain network. 20 | 21 | ## Benefits of dapp development 22 | 23 | Outside of providing a way for users to interact with the blockchain network in an easy and visual way, dapps also provide the additional benefits: 24 | 25 | - **Zero downtime** once the underlying smart contract and app are deployed on the blockchain network, the network will always be available to serve clients looking to interact with the contract. 26 | - **Privacy** users don't need to provide their true real-world identity to interact with a dapp. 27 | - **Censorship resistance** no entity on the network can prevent users from using the dapp in any way. 28 | - **Data integrity** since data stored on the blockchain is immutable, it is not possible for bad actors to modify or falsify data and transactions. 29 | - **Verifiable behavior** smart contracts and their dapps are guaranteed to execute in a predictable way without a central authority. 30 | -------------------------------------------------------------------------------- /create-decentralized-apps/includes/3-learn-drizzle.md: -------------------------------------------------------------------------------- 1 | # Learn about Drizzle 2 | 3 | In past modules, we have introduced the [Truffle Suite](https://www.trufflesuite.com/), a set of tools to make blockchain development easier. And we have previously used [Truffle](https://www.trufflesuite.com/truffle) and [Ganache CLI](https://www.trufflesuite.com/ganache) previously to help with the development, deployment and testing of smart contracts. 4 | 5 | In this unit, we will introduce the next member of the Truffle Suite, [Drizzle](https://www.trufflesuite.com/drizzle). Drizzle is a collection of front-end libraries that make writing dapp user interfaces easier and more predictable. 6 | 7 | :::image type="content" source="media\drizzle.png" alt-text="Image showing the Drizzle homepage"::: 8 | 9 | ## Drizzle architecture 10 | 11 | Before getting into how to use Drizzle, let's focus on the architecture so you know the different parts of the library that you can use to build your dapp. 12 | 13 | Drizzle is completely modular, which means you can use as much or as little of the library portions as you like. 14 | 15 | There are three core packages: 16 | 17 | - **drizzle** The core library responsible for account and contract instantiation and wiring up the smart contracts. 18 | - **drizzle-react** Makes it easier to connect Drizzle with your React app. 19 | - **drizzle-react-components** A library of useful components for common dapp functions 20 | 21 | :::image type="content" source="media\modular-overview.png" alt-text="Image showing the Drizzle's architecture overview"::: 22 | 23 | ### Underlying technologies 24 | 25 | Drizzle provides the mechanisms for synchronizing and managing smart contract data and is based on a [Redux](https://redux.js.org/) store. 26 | 27 | Underlying Technologies for managing the frontend apps which interact with the smart contacts can communicate via an API using a JSON-RPC layer called the Web3 API. 28 | 29 | - [JSON-RPC](https://www.jsonrpc.org/specification) is a stateless,light-weight remote procedure call (RPC) protocol using JSON for the payload. 30 | 31 | - [Web3](http://web3) is the Ethereum compatible javascript API and bindings which is built using the JSON-RPC spec. Any decentralized app can use this s Web3.js for browser based DApps. 32 | 33 | - [Redux](https://redux.js.org/) is a predictable state container for JavaScript apps. 34 | 35 | - [React.js](https://reactjs.org/) is a JavaScript library for building user interfaces. 36 | 37 | ## Drizzle components 38 | 39 | Drizzle includes the following components: 40 | 41 | - [\@drizzle/store](https://github.com/trufflesuite/drizzle/blob/develop/packages/store/README.md) is the state manager of Drizzle. It handles the boilerplate for web3 connection as synchronizing Smart Contract state and events. 42 | - Fully reactive contract data, including state, events and transactions. 43 | - Declarative so as not to waste valuable cycles on unneeded data. 44 | - Maintains access to underlying functionality. Web3 and contract's methods are still there, untouched. 45 | - [\@drizzle/react-plugin](https://github.com/trufflesuite/drizzle/tree/master/packages/react-plugin) defines the Drizzle Provider for a React project. 46 | - Abstracts away the boilerplate of creating a dapp front-end 47 | - Handles instantiating web3 and contracts, fetching accounts, and keeping all of this data in sync with the blockchain. 48 | - [\@drizzle/react-components](https://github.com/trufflesuite/drizzle/tree/master/packages/react-components) is a collection of primitive web controls that transforms smart contract data types to their appropriate html controls. 49 | - Provides a set of useful components for common UI elements. 50 | - [\@drizzle/vue-plugin](https://github.com/trufflesuite/drizzle/blob/develop/packages/vue-plugin/README.md) a Vue adaptor and collection of html controls to support developing a Vue dapp. 51 | -------------------------------------------------------------------------------- /create-decentralized-apps/includes/4-drizzle-dapp.md: -------------------------------------------------------------------------------- 1 | # Exercise - Get started with Drizzle 2 | 3 | We can use [Truffle Boxes](https://www.trufflesuite.com/boxes) as boilerplates or templates that can contain helpful modules, Solidity contracts & libraries, front-end views and more; all the way up to complete 4 | example dapps. 5 | 6 | For this exercise we'll be using the[**Drizzle box**](https://www.trufflesuite.com/boxes/drizzle). This box will help us quickly and easily build our first dapp and provide an overview of Drizzle's capabilities. 7 | 8 | The **Drizzle** box comes with several out of the box smart contracts to check out and a 9 | simplified **truffle-config.js** designed for development and testing. 10 | If using a prior **truffle project,** first create a clean and empty 11 | folder, **unbox** **Drizzle**, then copy over the current project - 12 | smart contracts, migrations, and other project-specific files. 13 | 14 | Using Drizzle to wire smart contacts to a front-end server 15 | 16 | Unboxing Drizzle results in essentially two separate projects within a 17 | single directory: a **truffle** project and a **drizzle-react client** 18 | project. If you already have experience with **Truffle**, then 19 | directory structure will look familiar in the smart contract area. The 20 | primary difference will be how you wire it to **Web3** and 21 | configurations modification which need to be taken into account. 22 | 23 | ## Get started with the Drizzle Box 24 | 25 | We'll begin by creating a new directory which will be used to house the Truffle Drizzle project. You'll need to make sure that you already have **Truffle** installed. 26 | 27 | 1. Open your terminal and create a new empty directory by typing: `mkdir drizzle_tutorial` 28 | 2. Then navigate to the directory by typing: `cd drizzle_tutorial` 29 | 3. Once in the dirzzle_tutorial folder, you can indicate that you want to use the Drizzle Truffle box by typing: `truffle unbox drizzle`. Wait a few minutes for the box to setup. Once it's complete you'll see the message: **Unbox successful, sweet!** 30 | 4. Open up the project in VS Code, and take a look at the folder structure. 31 | 32 | ## Compile, Migrate and test the project 33 | 34 | The **Truffle Drizzle-Box** comes with three contracts that use the 35 | drizzle components for connecting to a Dapp. The contracts directory 36 | contains the files: **ComplexStorage.sol**, **SimpleStorage.sol** and 37 | **TutorialToken.sol** which are used by the **Drizzle** tutorial. 38 | 39 | We'll want to compile, migrate, and test these contracts first before exploring the app components in detail. 40 | 41 | 1. From within VS Code, open up the terminal by going to **Terminal -> New Terminal**. Then start up Ganache CLI by typing: `ganache-cli`. 42 | 1. Open up another terminal window by right-clicking into the terminal and selecting **New Terminal**. 43 | 1. In that new terminal window, type `truffle compile` to compile the contracts. Wait for the compilation to successfully complete. 44 | 1. Once the compilation is complete, you can now test the contracts. The Truffle box comes with the file **simplestorage.js** for testing the **Simple Storage** smart contract. In the terminal window, type: `truffle test`. 45 | 1. After the tests successfully run, you can now deploy the contracts. The migrations folder has JavaScript files that help you deploy contracts to the network of your choice.**2_deploy_contracts.js** located in the migrations folder will migrate the smart contracts in this project. Type `truffle migrate --network develop`. Then wait for the migration to successfully complete. 46 | 47 | ## Explore the dapp components 48 | 49 | The Drizzle Box includes code using the Drizzle libraries to connect the 50 | smart contracts to the dapp's front-end. That code exists within the **app/** directory. 51 | 52 | The files in the **app/** folder which are of interest for connecting the smart contract to the dapp are: 53 | 54 | - **app.js** 55 | - **drizzleOptions.js** 56 | - **MyComponent.js.** 57 | 58 | Next let's explore how the files work together to wire up the smart contracts to the dapp. 59 | 60 | ### MyComponent.js 61 | 62 | The file **MyComponent.js** creates the component for connecting the SimpleStorage, ComplexStorage and TutorialToken smart contracts with the front-end. 63 | 64 | ### drizzleOptions.js 65 | 66 | **drizzleOptions.js** is used to create an **options** object and pass in the desired contract artifacts for **Drizzle** to instantiate. The **options** object sets up and instantiates the 67 | Drizzle store. 68 | 69 | ### App.js 70 | 71 | **App.js** contains the code for the main app. It requires importing React and the Drizzle libraries. It must also import the component file which interacts directly with the smart contract. 72 | 73 | ## Run the dapp 74 | 75 | 1. Focusing your attention back on the terminal window, run the following commands: 76 | 77 | - `cd app` to move into the app/ folder 78 | - `npm rebuild` to run the build and recompile changes in the app/ folder 79 | - `npm run start` to start the web-pack dev server for React and opens up a new browser window for the React project. 80 | 81 | Your browser should now open with a window showing a dapp where you can interact with the contracts: SimpleStorage, TutorialToken, and ComplexStorage. 82 | 83 | :::image type="content" source="media\drizzle-dapp.png" alt-text="Image showing the dapp that is generated from the Drizzle box"::: 84 | -------------------------------------------------------------------------------- /create-decentralized-apps/includes/5-shipping-dapp.md: -------------------------------------------------------------------------------- 1 | # Exercise - Create a dapp for a shipping contract 2 | 3 | In a previous module, we introduced a smart contract to capture the shipping status of an item from Pending to Shipped to Delivered. The contract also adds a counter which keeps track of the number of times that state of the shipping contract is updated and will display that in the frontend interface. 4 | 5 | In this exercise, we'll wire up the contract to a simple dapp to see the status and the number of times that state has been updated. 6 | 7 | ## Add the shipping contract to the Drizzle project 8 | 9 | The shipping contract that we'll be using in this example is displayed below. Copy this code into a new file in VS Code to the same project used in the last unit. The new file should be added in the **contracts/** folder in a file named **Shipping.sol**. 10 | 11 | ```solidity 12 | // SPDX-License-Identifier: MIT 13 | pragma solidity >=0.4.21 <0.7.0; 14 | 15 | contract Shipping 16 | { 17 | // Our predefined values for shipping listed as enums 18 | enum ShippingStatus { Pending, Shipped, Delivered } 19 | enum ShipmentStatus { Pending, Shipped, Delivered } 20 | 21 | // Save enum ShippingStatus in variable status 22 | ShippingStatus private status; 23 | ShipmentStatus public shipstatus; 24 | uint256 public numupdates; 25 | 26 | // Event to launch when package has arrived 27 | event LogNewAlert(string description); 28 | // This initializes our contract state (sets enum to Pending once the program starts) 29 | constructor() public { 30 | status = ShippingStatus.Pending; 31 | numupdates = 0; 32 | } 33 | // Function to change to Shipped 34 | function Shipped() public { 35 | status = ShippingStatus.Shipped; 36 | shipstatus = ShipmentStatus.Shipped; 37 | numupdates = numupdates + 1; 38 | } 39 | 40 | // Function to change to Delivered 41 | function Delivered() public { 42 | status = ShippingStatus.Delivered; 43 | shipstatus = ShipmentStatus.Delivered; 44 | numupdates = numupdates + 1; 45 | emit LogNewAlert("Your package has arrived"); 46 | } 47 | 48 | // Function to get the status of the shipping 49 | function getStatus(ShippingStatus _status) internal pure returns (string memory) { 50 | 51 | // Check the current status and return the correct name 52 | if (ShippingStatus.Pending == _status) return "Pending"; 53 | if (ShippingStatus.Shipped == _status) return "Shipped"; 54 | if (ShippingStatus.Delivered == _status) return "Delivered"; 55 | 56 | } 57 | // Get status of your shipped item 58 | function Status() public view returns (string memory) { 59 | ShippingStatus _status = status; 60 | return getStatus(_status); 61 | } 62 | } 63 | ``` 64 | 65 | ## Modify the migration 66 | 67 | Now, you need to modify **./migrations/2_deploy_contracts.js** to include the Shipping contract. 68 | 69 | On line 4 add: 70 | 71 | ```javascript 72 | const Shipping = artifacts.require("Shipping"); 73 | ``` 74 | 75 | And in the body of the function add a line to deploy the Shipping contract on line 10: 76 | 77 | ```javascript 78 | deployer.deploy(Shipping); 79 | ``` 80 | 81 | You can now compile and migrate the contract. Going to the terminal, confirm that Ganache CLI is running. If it's not running in a terminal window, type: `ganache-cli`. 82 | 83 | Open up another terminal window by right-clicking into the terminal and selecting **New Terminal**. 84 | 85 | In that new terminal window, type: 86 | 87 | - `truffle compile` to compile the Shipping contract 88 | - `truffle migrate --network develop` to migrate the Shipping contract 89 | 90 | ## Wiring up the frontend to the Shipping contract 91 | 92 | ### Create a loading component 93 | 94 | Next, create a loading component for the Shipping contract called **ShipComponent.js** in the folder **app/src/**. You can do that right-clicking on **app/src** and selecting to create a new file. Then copy the code below into the new file. 95 | 96 | ```javascript 97 | import React from "react"; 98 | import { newContextComponents } from "@drizzle/react-components"; 99 | const { ContractData, ContractForm } = newContextComponents; 100 | export default ({ drizzle, drizzleState }) => { 101 | return ( 102 |
103 |
104 |

Shipping Test

105 |

106 | Shipping Status 1-Shipped 2-Delivered 107 | Ship State: 108 | 114 |

115 |

116 | Total number of updates: 117 | 123 |

124 |

125 | Ship: 126 | 131 |

132 |

133 | Deliver: 134 | 139 |

140 |
141 |
142 | ); 143 | }; 144 | ``` 145 | 146 | This loading component defines what the frontend looks like and what interaction it allows with users. 147 | 148 | ### Modify Drizzle's options 149 | 150 | Navigate to **./app/src/drizzleOptions.js** to make a few changes. 151 | 152 | On line 5, add the following to import **Shipping.json.** 153 | 154 | ```javascript 155 | import Shipping from "./contracts/Shipping.json"; 156 | ``` 157 | 158 | Then on line 12, insert `Shipping` in the contracts array so the line looks like: 159 | 160 | ```javascript 161 | contracts: [SimpleStorage, ComplexStorage, TutorialToken, Shipping] 162 | ``` 163 | 164 | ### Modify App.js 165 | 166 | Then modify **/app/src/App.js** to replace **MyComponent** with **ShipComponent** on line 5: 167 | 168 | ```javascript 169 | import ShipComponent from "./ShipComponent"; 170 | ``` 171 | 172 | And also replace **ShipComponent** on line 22: 173 | 174 | ```javascript 175 | 176 | ``` 177 | 178 | ## Running the Shipping Example Code 179 | 180 | You have now completed all the steps to wire up the shipping contract, so that means it's time to run the dapp and check out how it works. 181 | 182 | Going back to the terminal, type the following commands: 183 | 184 | - `cd app` to move to the app folder 185 | - `npm rebuild` to run the build and recompile changes in the app/ folder 186 | - `npm run start` to start the web-pack dev server for React and opens up a new browser window for the React project. 187 | 188 | Your browser should now open at [http://localhost:3000](http://localhost:3000) showing a dapp where you can interact with the Shipping contract. 189 | 190 | You should see the following: 191 | 192 | :::image type="content" source="media\shipping-dapp.png" alt-text="Image showing the dapp that is wired up to the shipping contract"::: 193 | -------------------------------------------------------------------------------- /create-decentralized-apps/includes/6-knowledge-check.md: -------------------------------------------------------------------------------- 1 | 1. What is the most accurate definition of Drizzle? 2 | a. Drizzle is a development framework used to make managing Ethereum projects easier. 3 | b. Drizzle is an Ethereum blockchain to run tests and execute commands. 4 | c. Drizzle is a collection of libraries to make writing dapps easier. (correct) 5 | d. Drizzle is a set of boilerplates that contain contracts, libraries and dapps. 6 | 7 | 1. How do dapps operate? 8 | a. They have frontend code that connects in the backend to smart contracts on a blockchain network. (correct) 9 | b. They operate just like traditional apps with a frontend that connects to a centralized backend server. 10 | c. They have frontend code that runs on it's own and do not require a backend to hook up to. 11 | d. They are a set of smart contracts that allow you to interact with them directly by calling their functions. 12 | 13 | 1. Using the Drizzle Truffle Box, we can start up the web server for the project by running which command? 14 | a. npm rebuild 15 | b. npm run start (correct) 16 | c. npm build 17 | d. npm run 18 | -------------------------------------------------------------------------------- /create-decentralized-apps/includes/7-summary.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | In this module, you learned all about decentralized apps. You read about the benefits of dapps and how they operate. You were exposed to Drizzle, a part of the Truffle Suite family, that is the most popular option for developers building dapps. Finally, you got to use Drizzle to create your own dapps. 4 | -------------------------------------------------------------------------------- /create-decentralized-apps/index.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:Module 2 | uid: learn.reactors.blockchain-apps 3 | metadata: 4 | title: Create a user interface with decentralized apps 5 | description: Learn all about decentralized apps and how to build your own. 6 | ms.date: 11/30/2020 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Create a user interface with decentralized apps 12 | summary: Learn all about decentralized apps and how to build your own. 13 | abstract: | 14 | By the end of this module, you will be able to: 15 | 16 | - Explain what decentralized apps are 17 | - Identify the technology needed to create decentralized apps 18 | - Know how to use Drizzle to create apps 19 | - Build your own decentralized apps 20 | prerequisites: | 21 | - [Fundamental knowledge about blockchain](https://docs.microsoft.com/learn/modules/intro-to-blockchain/?azure-portal=true) 22 | - [Solidity programming knowledge](https://docs.microsoft.com/learn/modules/blockchain-learning-solidity/?azure-portal=true) 23 | - [Ethereum smart contract knowledge](https://docs.microsoft.com/learn/modules/blockchain-solidity-ethereum-smart-contracts/?azure-portal=true) 24 | - Previous experience with a programming language like C, Python, or JavaScript 25 | - Basic knowledge of programming concepts 26 | - Familiarity with the command line to create new directories and install programs 27 | - Node.js installed 28 | - Truffle and Ganache CLI installed 29 | - Visual Studio Code installed 30 | - Blockchain Development Kit for Ethereum installed 31 | iconUrl: /learn/achievements/generic-badge.svg # TODO change 32 | levels: 33 | - beginner 34 | roles: 35 | - developer 36 | - student 37 | products: 38 | - azure 39 | units: 40 | - learn.reactors.blockchain-apps.1-introduction 41 | - learn.reactors.blockchain-apps.2-learn-dapps 42 | - learn.reactors.blockchain-apps.3-learn-drizzle 43 | - learn.reactors.blockchain-apps.4-drizzle-dapps 44 | - learn.reactors.blockchain-apps.5-shipping-dapp 45 | - learn.reactors.blockchain-apps.6-knowledge-check 46 | - learn.reactors.blockchain-apps.7-summary 47 | badge: 48 | uid: learn.reactors.blockchain-apps.badge 49 | -------------------------------------------------------------------------------- /create-decentralized-apps/media/drizzle-dapp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/create-decentralized-apps/media/drizzle-dapp.png -------------------------------------------------------------------------------- /create-decentralized-apps/media/drizzle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/create-decentralized-apps/media/drizzle.png -------------------------------------------------------------------------------- /create-decentralized-apps/media/modular-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/create-decentralized-apps/media/modular-overview.png -------------------------------------------------------------------------------- /create-decentralized-apps/media/shipping-dapp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/create-decentralized-apps/media/shipping-dapp.png -------------------------------------------------------------------------------- /ethereum-blockchain-dev/0-introduction.md: -------------------------------------------------------------------------------- 1 | # Get started with blockchain development 2 | 3 | This learning path introduces you to blockchain and development on the Ethereum platform. Discover what skills are necessary to learn to begin building your own blockchain networks at scale. 4 | 5 | Through these modules, you will: 6 | 7 | - Learn the foundations of blockchain and how blockchain technology works 8 | - Gain an understanding of the tools to develop on the Ethereum blockchain 9 | - Create smart contracts and decentralized applications 10 | - Deploy to local and test Ethereum networks 11 | 12 | ## Prerequisites 13 | 14 | - Previous experience with any programming language like C, Python, or JavaScript 15 | - Basic knowledge of programming concepts 16 | - Familiarity with the command line to create new directories 17 | - Visual Studio Code installed 18 | -------------------------------------------------------------------------------- /ethereum-blockchain-dev/README.md: -------------------------------------------------------------------------------- 1 | # Ethereum blockchain development Learning Path 2 | 3 | Learning Path Title: 4 | 5 | Module Titles: 6 | 7 | 1. Introduction to blockchain on Azure 8 | 2. Learn how to use Solidity 9 | 3. Use Solidity to write Ethereum smart contracts 10 | 4. Create a bank smart contract with exchange rate 11 | 5. Create a decentralized application 12 | 6. Learn how to deploy to Ethereum networks 13 | -------------------------------------------------------------------------------- /ethereum-blockchain-dev/index.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:LearningPath 2 | uid: learn.ethereum-blockchain-development 3 | metadata: 4 | title: Get started with blockchain development 5 | description: This learning path introduces you to blockchain and development on the Ethereum platform. Discover what skills are necessary to learn to begin building your own blockchain networks at scale. 6 | brand: 7 | ms.date: 8 | author: meaghanlewis 9 | ms.author: shanamatthews 10 | ms.topic: interactive-tutorial 11 | ms.prod: learning-azure 12 | title: Get started with blockchain development 13 | summary: | 14 | This learning path introduces you to blockchain and development on the Ethereum platform. Discover what skills are necessary to learn to begin building your own blockchain networks at scale. 15 | 16 | In this learning path you will: 17 | - Learn the foundations of blockchain and how blockchain technology works 18 | - Gain an understanding of the tools to develop on the Ethereum blockchain 19 | - Create smart contracts and decentralized applications 20 | - Deploy to local and test Ethereum networks 21 | 22 | prerequisites: | 23 | - Previous experience with any programming language like C, Python, or JavaScript 24 | - Basic knowledge of programming concepts 25 | - Familiarity with the command line to create new directories 26 | - Visual Studio Code installed 27 | iconUrl: /learn/achievements/generic-trophy.svg # TODO change 28 | levels: 29 | - beginner 30 | roles: 31 | - student 32 | products: 33 | - azure 34 | modules: 35 | - learn.student-evangelism.introduction 36 | trophy: 37 | uid: "" -------------------------------------------------------------------------------- /ethereum-networks/1-introduction.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Introduction 5 | description: Introduction 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Introduction 12 | durationInMinutes: 1 13 | content: | 14 | [!include[](includes/1-introduction.md)] -------------------------------------------------------------------------------- /ethereum-networks/2-public-networks.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Learn about public Ethereum networks 5 | description: Get an overview of the public networks available including testnets and mainnet. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Learn about public Ethereum networks 12 | durationInMinutes: 5 13 | content: | 14 | [!include[](includes/2-public-networks.md)] -------------------------------------------------------------------------------- /ethereum-networks/3-private-networks.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Learn about private Ethereum networks 5 | description: Get an overview of the private networks available including development and consortium networks. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Learn about private Ethereum networks 12 | durationInMinutes: 3 13 | content: | 14 | [!include[](includes/3-private-networks.md)] -------------------------------------------------------------------------------- /ethereum-networks/4-prepare-for-mainnet.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Prepare for deployment to mainnet 5 | description: Get an overview of the steps to complete before deploying to the Ethereum mainnet. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Prepare for deployment to mainnet 12 | durationInMinutes: 2 13 | content: | 14 | [!include[](includes/4-prepare-for-mainnet.md)] -------------------------------------------------------------------------------- /ethereum-networks/5-develop-deploy-development.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Exercise - Develop a todo list and deploy to development 5 | description: Create a new Truffle project, add a smart contract for a todo list, and deploy. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Exercise - Develop a todo list and deploy to development 12 | durationInMinutes: 7 13 | content: | 14 | [!include[](includes/5-develop-deploy-development.md)] -------------------------------------------------------------------------------- /ethereum-networks/6-deploy-ropsten-network.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Exercise - Deploy to the Ropsten test network 5 | description: Deploy the todo list smart contract to the Ropsten network. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Exercise - Deploy to the Ropsten test network 12 | durationInMinutes: 10 13 | content: | 14 | [!include[](includes/6-deploy-ropsten-network.md)] -------------------------------------------------------------------------------- /ethereum-networks/8-summary.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Summary 5 | description: Summary 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Summary 12 | durationInMinutes: 1 13 | content: | 14 | [!include[](includes/8-summary.md)] 15 | quiz: 16 | title: Check your knowledge 17 | questions: 18 | - content: "Which test network only supports Geth clients?" 19 | choices: 20 | - content: "Rinkeby." 21 | isCorrect: true 22 | explanation: "Correct. Rinkeby is the only network that only supports Geth." 23 | - content: "Ropsten." 24 | isCorrect: false 25 | explanation: "Incorrect. Ropsten supports Geth and OpenEthereum clients." 26 | - content: "Kovan." 27 | isCorrect: false 28 | explanation: "Incorrect. Ropsten supports OpenEthereum clients." 29 | - content: "Görli." 30 | isCorrect: false 31 | explanation: "Incorrect. Görli supports multiple clients like Geth, Nethermind, and OpenEthereum" 32 | - content: "Which of the following is necessary to prepare for mainnet deployment?" 33 | choices: 34 | - content: "Verifying source code." 35 | isCorrect: true 36 | explanation: "Correct. Source code should be submitted to be verified by a service like Etherscan." 37 | - content: "Smart contract testing." 38 | isCorrect: false 39 | explanation: "Incorrect. Smart contract testing should happen during development, but it is not required." 40 | - content: "Key distribution to project managers" 41 | isCorrect: false 42 | explanation: "Incorrect. Keys should be stored securely and only shared with those who govern or administrate the project." 43 | - content: "Documentation for smart contracts and dapps." 44 | isCorrect: false 45 | explanation: "Incorrect. Documentation for the blockchain solution is helpful, but not required." 46 | - content: "What service does Infura provide?" 47 | choices: 48 | - content: "A wallet service to add ether, test ether, and other tokens" 49 | isCorrect: false 50 | explanation: "Incorrect. This best describes the service that Metamask provides." 51 | - content: "A development suite that provides API access to Ethereum networks" 52 | isCorrect: true 53 | explanation: "Correct. Infura provides an API to easily access and connect your solution to different Ethereum networks." 54 | - content: "A development suite to make it easy to create, compile and deploy smart contracts." 55 | isCorrect: false 56 | explanation: "Incorrect. This best describes what the TruffleSuite provides." 57 | - content: "A destination to stage and test blockchain solutions before deploying to the mainnet." 58 | isCorrect: false 59 | explanation: "Incorrect. This best describes test networks." -------------------------------------------------------------------------------- /ethereum-networks/includes/1-introduction.md: -------------------------------------------------------------------------------- 1 | Ethereum is a protocol with multiple independent networks that are part of this protocol. 2 | 3 | Networks are Ethereum environments you can access for development, testing, or production use cases. It’s important to have an understanding of the networks that Ethereum provides, how they differ from one another, and how to connect and deploy to the networks of your choice. For whatever blockchain solution you create, you’re going to need to choose if you'll have a private or public solution and how to go from development to test to production network. 4 | 5 | The goal of this module is to get more familiar with the network options in the Ethereum protocol, some tools you can use to interact with them, and learn how to work with to different networks. 6 | 7 | ## Learning objectives 8 | 9 | By the end of this module, you'll be able to: 10 | 11 | - Identify the public and private networks available in Ethereum. 12 | - Explain what is required to prepare a solution for the mainnet. 13 | - Know how to use Metamask with Infura to connect a blockchain solution to networks. 14 | 15 | ## Prerequisites 16 | 17 | - [Fundamental knowledge about blockchain](https://docs.microsoft.com/learn/modules/intro-to-blockchain/?azure-portal=true) 18 | - [Solidity programming knowledge](https://docs.microsoft.com/learn/modules/blockchain-learning-solidity/?azure-portal=true) 19 | - [Ethereum smart contract knowledge](https://docs.microsoft.com/learn/modules/blockchain-solidity-ethereum-smart-contracts/?azure-portal=true) 20 | - Previous experience with a programming language like C, Python, or JavaScript 21 | - Basic knowledge of programming concepts 22 | - Familiarity with the command line to create new directories and install programs 23 | - Node.js installed 24 | - Truffle and Ganache CLI installed 25 | - Visual Studio Code installed 26 | -------------------------------------------------------------------------------- /ethereum-networks/includes/2-public-networks.md: -------------------------------------------------------------------------------- 1 | # Learn about public Ethereum networks 2 | 3 | The [Ethereum](https://ethereum.org/?azure-portal=true) protocol is made up of multiple public networks. Different Ethereum networks can have different properties, uses, functionality and consensus mechanisms. There are currently four different test networks, called *testnets*, and one production network, called *mainnet*. 4 | 5 | ## An overview of mainnet 6 | 7 | [Mainnet](https://ethereum.org/en/glossary/#mainnet), short for "main network" is the one real public Ethereum blockchain. Applications that are deployed to the mainnet can exchange and use information and interact with one another. 8 | 9 | Once deployed, the applications can leverage the full potential of decentralized blockchain. There is no centralized authority and mainnet is fully decentralized. There can be different types of tokens and applications deployed to mainnnet. Once deployed on the mainnet, transactions are immutable and cannot be changed. In addition, each transaction has real costs associated with it which requires actual Ether (ETH). All blocks on the Ethereum mainnet can be viewed using [Etherscan](https://etherscan.io/) which shows the latest mined blocks and transactions. All blocks can be inspected. 10 | 11 | :::image type="content" source="media\etherscan.png" alt-text="Screenshot showing the homepage of Etherscan"::: 12 | 13 | ## Ethereum testnets 14 | 15 | There are four public testnets, each with a different deployment method and process. They are used to stage and test applications in a live public environment prior to deploying to the mainnet. 16 | 17 | Testnets use either [Proof of Work (PoW)](https://www.investopedia.com/terms/p/proof-work.asp?azure-portal=true) or [Proof of Authority (PoA)](https://academy.binance.com/en/articles/proof-of-authority-explained/?azure-portal=true) consensus protocols to determine how new blocks of transactions are added to the network. A quick overview of each protocol: 18 | 19 | - **PoW**: A mining rig solves a cryptographic hashing problem in order to mine a new block and decide which transactions are part of that block. 20 | - **PoA**: Block validators verify their identity on a network in order to decide which transactions become part of the next block in the chain. 21 | 22 | And testnets require **test ether** that is free and can be accessed from what are called *faucets*. You provide faucets with an account address to receive a certain amount of test ether. This has become the primary way to acquire test ether for a specific testnet. The community manages these public test networks for the benefit of developers and testing. Using a faucet protects the testnet from spam attacks since the ether is controlled by trusted parties. 23 | 24 | ## Testnet Comparison 25 | 26 | Let’s take a look at the different [Ethereum testnets](https://ethereum.org/en/developers/docs/networks/#testnets) and associated properties. 27 | 28 | ### [Ropsten](https://ropsten.etherscan.io/?azure-portal=true) 29 | 30 | Ropsten is a PoW consensus protocol, closest to mainnet in functionality. It is named after a Swedish subway station and has been around since 2016. It is said to have the best reproduction of the conditions on the the mainnet. 31 | 32 | - More details: 33 | - Supports: [Geth](https://geth.ethereum.org/?azure-portal=true) and [OpenEthereum](https://openethereum.github.io/?azure-portal=true) clients 34 | - Block time: 30 seconds or less 35 | - Faucet: [https://faucet.ropsten.be/](https://faucet.ropsten.be/?azure-portal=true) 36 | - Explorer: [https://ropsten.etherscan.io/](https://ropsten.etherscan.io/?azure-portal=true) 37 | - GitHub: [https://github.com/ethereum/ropsten](https://github.com/ethereum/ropsten/?azure-portal=true) 38 | 39 | ### [Kovan](https://kovan-testnet.github.io/website/?azure-portal=true) 40 | 41 | This PoA testnet is named after a subway station in Singapore. It's Ether has to be requested from the faucet and is controlled by trusted parties. Because of this property, it is immune to spam attacks. 42 | 43 | - More details: 44 | - Supports: OpenEthereum clients 45 | - Block time: 4 seconds 46 | - Faucet: [https://faucet.kovan.network/](https://faucet.kovan.network/?azure-portal=true) 47 | - Explorer: [https://kovan.etherscan.io/](https://kovan.etherscan.io/?azure-portal=true) 48 | - GitHub: [https://github.com/kovan-testnet/proposal](https://github.com/kovan-testnet/proposal/?azure-portal=true) 49 | - Website: [https://kovan-testnet.github.io/website/](https://kovan-testnet.github.io/website/?azure-portal=true) 50 | 51 | ### [Rinkeby](https://www.rinkeby.io/?azure-portal=true) 52 | 53 | PoA testnet started by the Ethereum team in April 2017 is named after a metro station in Stockholm. 54 | 55 | - More details: 56 | - Supports Geth client 57 | - Block time: 15 seconds 58 | - Faucet: [https://faucet.rinkeby.io/](https://faucet.rinkeby.io/?azure-portal=true) 59 | - Explorer: [https://rinkeby.etherscan.io/](https://rinkeby.etherscan.io/?azure-portal=true) 60 | - GitHub: [https://github.com/ethereum/EIPs/issues/225](https://github.com/ethereum/EIPs/issues/225/?azure-portal=true) 61 | - Website: [https://www.rinkeby.io](https://www.rinkeby.io/?azure-portal=true) 62 | 63 | ### [Görli](https://goerli.net/?azure-portal=true) 64 | 65 | PoA cross-client testnet and named after a Berlin subway station. This testnet has the goal of being both widely usable across various clients. It is robust enough to guarantee consistent availability and was started by the Goerli Initiative in 2018. 66 | 67 | - More details: 68 | - Supports: Most clients including Geth, OpenEthereum, and [Nethermind](https://nethermind.io/?azure-portal=true) 69 | - Block time: 15 seconds on average 70 | - Faucet: [https://faucet.goerli.mudit.blog/](https://faucet.goerli.mudit.blog/?azure-portal=true) 71 | - Status Dashboard: [https://stats.goerli.net/](https://stats.goerli.net/?azure-portal=true) 72 | - Explorer: [https://goerli.etherscan.io/](https://goerli.etherscan.io/?azure-portal=true) 73 | - GitHub: [https://github.com/goerli/testnet](https://github.com/goerli/testnet/?azure-portal=true) 74 | - Website: [https://www.goerli.net](https://www.goerli.net/?azure-portal=true) 75 | 76 | Ropsten is said to be the testnet that is as similar to mainnet and was historically the first major testnet. Kovan, Goerli and Rinkeby are stable and have increased usage. Prior to deploying to mainnet, it’s advised to deploy to and test on multiple testnets. 77 | 78 | ## Clients and API's for deploying to **Testnets** and **Mainnet** 79 | 80 | Ethereum is designed to offer different clients, developed by different teams using different programming languages. This makes the network stronger and more diverse. The ideal goal is to achieve diversity without any client dominating to reduce any single points of failure. 81 | 82 | ### Clients 83 | 84 | Below is a summary of some common [Ethereum clients](https://ethereum.org/en/developers/docs/nodes-and-clients/#clients): 85 | 86 | [**Geth Client**](https://geth.ethereum.org/?azure-portal=true) 87 | 88 | Go Ethereum (Geth for short) is one of the original implementations of the Ethereum protocol. Currently, it is the most widespread client with the biggest user base and variety of tooling for users and developers. It is written in Go, fully open source and licensed under the GNU LGPL v3. 89 | 90 | [**OpenEthereum**](https://openethereum.github.io/?azure-portal=true) 91 | 92 | OpenEthereum's goal is to be the fastest, lightest, and most secure Ethereum client. We are developing OpenEthereum using the Rust programming language. OpenEthereum is licensed under the GPLv3 and can be used for all your Ethereum needs. 93 | 94 | [Nethermind](https://nethermind.io/?azure-portal=true) 95 | 96 | Nethermind provides the world's fastest .NET Ethereum Client and P2P Data Marketplace, along with consulting services for those looking to build Ethereum blockchain solutions. 97 | 98 | ### APIs 99 | 100 | [Infura](https://infura.io/?azure-portal=true) 101 | 102 | The Infura API suite provides instant access over HTTPS and WebSockets to the Ethereum and IPFS networks. It provides a simple, easy to use interface for connecting to the endpoints of all testnets. Infura supports both **Truffle Suite** and the **VS Code Blockchain Development Kit for Ethereum.** 103 | 104 | [MetaMask](https://metamask.io/?azure-portal=true) 105 | 106 | When deploying to either a testnet or mainnet , the MetaMask client provides a robust interface and wallet for connecting to and interacting with Ethereum blockchains. 107 | 108 | Using MetaMask to send Ether and tokens on a testnet is straightforward. As we've seen in previous tutorials, the client provides an easy interface to select and use different Ethereum networks. For interacting with development networks, it's simple with MetaMask to connect to Localhost 8545 or Custom RPC to connect with Ganache and Truffle. Similarly, MetaMask has predefined connections to the public testnets and mainnet. If connecting to mainnet, be careful to secure your private key since real Ether is being used. 109 | -------------------------------------------------------------------------------- /ethereum-networks/includes/3-private-networks.md: -------------------------------------------------------------------------------- 1 | # Learn about private Ethereum networks 2 | 3 | An Ethereum network is private if its nodes are isolated and not connected to a public network such as mainnet or a testnet. Private networks include development networks, or consortium networks. 4 | 5 | ## Development networks 6 | 7 | When developing an Ethereum application, you'll start by running it on a private network to see how it works before deploying it. Similar to how you create a local server on your computer for web development, you can create a local blockchain instance to test your blockchain solution. 8 | 9 | On your development network, you can create, test, and iterate changes to your solution very quickly. You can make changes to your solution in development much more seamlessly and quickly than with a public testnet. Tools such as [Ganache](https://www.trufflesuite.com/ganache) and [Hardhat](https://hardhat.org/) are most commonly used to run personal Ethereum development networks. 10 | 11 | ## Solutions for consortium networks 12 | 13 | There are multiple options for consortiums. Consortiums are permissioned and require an invite to participate. They ensure security, privacy, compliance, and performance. There are many options for consortium blockchains, including Hyperledger Besu, R3 Corda and Quorum. Let's explore two popular options for consortium blockchains. 14 | 15 | ### Hyperledger Besu 16 | 17 | [Hyperledger Besu](https://besu.hyperledger.org/en/stable/?azure-portal=true) is an open-source Ethereum client developed under the Apache 2.0 license and written in Java. 18 | 19 | Besu is used to develop enterprise applications requiring secure, high-performance transaction processing in a private network. Besu has a command line interface and JSON-RPC API for running, maintaining, debugging, and monitoring nodes in an Ethereum network. The API supports typical Ethereum functionalities such as: 20 | 21 | - Ether mining 22 | - Smart contract development 23 | - Decentralized application (Dapp) development. 24 | 25 | Hyperledger Besu is a popular Ethereum client that is unique in that it offers a client that can be used in either public networks, as well as private, consortium based networks. It can be deployed a variety of [ways](https://besu.hyperledger.org/en/stable/HowTo/Get-Started/Installation-Options/Install-Binaries/), and recently a preview has been made available in [Azure](https://azuremarketplace.microsoft.com/marketplace/apps/consensys.hyperledger-besu-quickstart?tab=Overview). 26 | 27 | More information about configuring and deploying can be found on the [Hyperledger Besu website.](https://besu.hyperledger.org/en/latest/Tutorials/Examples/Private-Network-Example/) 28 | 29 | ### R3 Corda 30 | 31 | The [Corda Platform](https://www.r3.com/corda-platform/?azure-portal=true) is a private, permissioned blockchain focused on supporting trusted communication, interactions and transactions between entities. [**Corda Enterprise**](https://www.r3.com/corda-enterprise/) offers the core attributes of **Corda** open source along with additional business requirements enterprises expect when licensing software. The **Corda** protocol is built on a strong identity model, where every node's identity must be proven to have been properly on boarded. 32 | 33 | Signing identities only exist on the **Corda** nodes. Client applications in a **Corda** based solution are simply triggering the workflow that has already been registered on the target **Corda** node, and monitoring the progression of the flow. This is very different from Ethereum, where client applications play a critical role in the transaction lifecycle, by holding the signing keys and signing transactions before they are submitted to the nodes. Essentially, **Corda** applications, or [**CorDapps**](https://docs.corda.net/docs/corda-os/4.7/cordapp-overview.html) for short, completely live on the **Corda** nodes. 34 | 35 | There is a [Corda VSCode extension](https://github.com/corda/vscode-corda) which supports **Corda** development. From **VSCode**, go to the extensions icon, click on the icon and enter “Corda” to install the extension. 36 | -------------------------------------------------------------------------------- /ethereum-networks/includes/4-prepare-for-mainnet.md: -------------------------------------------------------------------------------- 1 | # Prepare for deployment to mainnet 2 | 3 | Prior to deploying to the Ethereum mainnet, it's necessary to fully test and audit your code. Working mainnet requires real Ether which costs real money and can add up quickly! 4 | 5 | After developing, testing and auditing your code and running the project on at least one testnet without any problems, most projects follow a substantial auditing, testing, security and governance process before deploying to mainnet. This is done to minimize the risks and costs of things going wrong in mainnet. 6 | 7 | The process for preparing for mainnet and deploying to mainnet requires a series of steps. The basic steps for deploying to the Ethereum mainnet include: auditing smart contracts, verifying source code, managing keys, and handling project governance. The sections below describes these steps in more detail. 8 | 9 | ## [Perform a smart contract audit](https://docs.openzeppelin.com/learn/preparing-for-mainnet#auditing-and-security) 10 | 11 | Auditing and assessing the security of smart contracts is imperative prior to deploying to a public network. Once a smart contract is deployed, anyone on the network can send a transaction directly to the contracts with any payload. All of the code and the state of the contract is publicly available. Since transactions on blockchains are immutable, once committed, the transactions are permanent and can result in funds being stolen and other malicious activity. It is imperative to audit smart contracts prior to deployment. 12 | 13 | ## [Verify source code](https://docs.openzeppelin.com/learn/preparing-for-mainnet#verify-source-code) 14 | 15 | Before deploying to mainnet, the smart contract source code should be verified by submitting the Solidity code to a third-party. Public services, which as [Etherscan](https://etherscan.io/verifyContract), will compile it and verify that it matches the deployed assembly. This allows any user to view your contract code in a block explorer, and know that it corresponds to the assembly actually running at that address. 16 | 17 | Steps for Verifying and Publishing your Solidity Source Code: 18 | 19 | - Enter Contract Source Code. 20 | - If the Bytecode generated matches the existing Creation Address Bytecode, the contract is then verified. 21 | - Contract Source Code is published and publicly verifiable by anyone. 22 | 23 | ## [Manage keys securely](https://docs.openzeppelin.com/learn/preparing-for-mainnet#key-management) 24 | 25 | It’s imperative to securely manage private keys when deploying to the **mainnet**. Securing private keys and managing them so they cannot be compromised, lost or stolen requires heavy precautions. There have been several major thefts and losses as a result of keys being mismanaged, lost or stolen. The accounts used to deploy and interact with smart contracts hold real Ether and are targets for hackers. [Hardware wallets](https://docs.ethhub.io/using-ethereum/wallets/hardware/) and [cold storage](https://www.investopedia.com/terms/c/cold-storage.asp#:~:text=Key%20Takeaways&text=Cold%20storage%20is%20a%20way,their%20holdings%20via%20traditional%20means.) (computers never connected to any network) are common ways to store private keys securely. 26 | 27 | ## [Handle project governance](https://docs.openzeppelin.com/learn/preparing-for-mainnet#project-governance) 28 | 29 | There are different ways that decentralized projects are managed depending on community and user base. Often organizations are created to determine how updates, and other aspects of the running decentralized system are managed. There are a number of options of how project governance can be managed, from a small group of trusted administrators, to public voting of all project stakeholders. There is no right answer here, it comes down to what solution you're building and who your community and users are. 30 | -------------------------------------------------------------------------------- /ethereum-networks/includes/5-develop-deploy-development.md: -------------------------------------------------------------------------------- 1 | # Exercise - Develop a todo list and deploy to development 2 | 3 | In this exercise, you'll be developing a simple task manager and utilize it to connect and deploy on the **Ropsten** test networks. 4 | 5 | In the first part of this exercise, let's focus on creating the project, adding a smart contract, and then deploying to a development network. 6 | 7 | For this tutorial, we'll use: 8 | 9 | - Visual Studio Code to create our project. 10 | - [Truffle](https://www.trufflesuite.com/truffle) to compile and deploy. 11 | - [Ganache CLI](https://github.com/trufflesuite/ganache-cli) as the blockchain development server. 12 | 13 | ## Create a new Truffle project 14 | 15 | 1. Open a terminal or command prompt window and create a new directory called *todolist* by typing: **mkdir todolist**. 16 | 17 | 2. Navigate to the newly created directory by typing: **cd todolist**. 18 | 19 | 3. Initialize the directory as a Truffle project by typing: **truffle init**. 20 | 21 | 4. Open the *todolist* folder in Visual Studio Code. 22 | 23 | 5. From within VS Code, create a file in the contracts directory named **TodoList.sol** and copy in the following code: 24 | 25 | ```solidity 26 | // SPDX-License-Identifier: MIT 27 | pragma solidity >=0.4.22 <0.8.0; 28 | 29 | contract TodoList { 30 | uint public taskCount = 0; 31 | 32 | struct Task { 33 | uint id; 34 | string taskname; 35 | bool status; 36 | } 37 | 38 | mapping(uint => Task) public tasks; 39 | 40 | event TaskCreated( 41 | uint id, 42 | string taskname, 43 | bool status 44 | ); 45 | 46 | event TaskStatus( 47 | uint id, 48 | bool status 49 | ); 50 | 51 | constructor() public { 52 | createTask("Todo List Tutorial"); 53 | } 54 | 55 | function createTask(string memory _taskname) public { 56 | taskCount ++; 57 | tasks[taskCount] = Task(taskCount, _taskname, false); 58 | emit TaskCreated(taskCount, _taskname, false); 59 | } 60 | 61 | function toggleStatus(uint _id) public { 62 | Task memory _task = tasks[_id]; 63 | _task.status = !_task.status; 64 | tasks[_id] = _task; 65 | emit TaskStatus(_id, _task.status); 66 | } 67 | 68 | } 69 | ``` 70 | 71 | ## Migrate and deploy to development 72 | 73 | 1. Create a migration for *TodoList.sol* in the **migrations/** folder by creating a new file called **2_deploy_contracts.js** and copy in the following code into that file to deploy the TodoList smart contract: 74 | 75 | ```javascript 76 | var TodoList = artifacts.require("./TodoList.sol";); 77 | 78 | module.exports = function(deployer) { 79 | deployer.deploy(TodoList); 80 | }; 81 | ``` 82 | 83 | 2. In the main project directory, open **./truffle-config.js** and un-comment the code to deploy on the development network which will be deployed to localhost port **8545**. Your code should look as follows: 84 | 85 | ```javascript 86 | networks: { 87 | development: { 88 | host: "127.0.0.1", 89 | port: 8545, 90 | network_id: "*" // Match any network id 91 | } 92 | }, 93 | ``` 94 | 95 | 3. Open a terminal window within VS COde and start up a development blockchain using ganache-cli by typing: **ganache-cli**. 96 | 97 | 4. In Visual Studio Code, open a terminal window to compile and migrate the TodoList contract to the development network by running the following: 98 | 99 | - `truffle compile` 100 | - `truffle migrate --reset` 101 | 102 | This will deploy the smart contracts to the development network. At this point, test your contract using the truffle console, inspect and modify the smart contracts. Below we can see that we created a single task when initializing the task list. Using **truffle console**, you can continue to interact with the contract, creating and setting tasks and toggling their status. 103 | -------------------------------------------------------------------------------- /ethereum-networks/includes/6-deploy-ropsten-network.md: -------------------------------------------------------------------------------- 1 | # Exercise - Deploy to the Ropsten test network 2 | 3 | Now that we have a smart contract, and have successfully deployed it to our development network, we will focus this exercise on deploying to the Ropsten test network. 4 | 5 | ## Exercise overview 6 | 7 | For this tutorial, we will deploy to **Ropsten** using **MetaMask** with test ether. The process for deploying requires setting up an [Infura](http://www.infura.io/) account to connect and deploy to the Ropsten testnet. Once deployed, we can use the [Ropsten Testnet Explorer](https://ropsten.etherscan.io/) to inspect the blocks which have been deployed to the testnet. 8 | 9 | ## Exercise setup 10 | 11 | ### Set up Metamask 12 | 13 | If you haven’t done so already, install and set up Metamask by visiting [www.metamask.io](www.metamask.io) and following the prompts. Once you are signed into your account in the browser, you can move on to the next step. 14 | 15 | ### Add ether to Metatmask Ropsten test network 16 | 17 | Using your Metamask account, connect to the Ropsten test network. You can get some test ether from the [Ropsten Test Faucet](https://faucet.ropsten.be) by following the steps below: 18 | 19 | 1. Open MetaMask 20 | 2. Connect to Ropsten 21 | 3. Copy the address of your account to the clipboard 22 | 23 | :::image type="content" source="media\Metamask_0_Eth_Connect.png" alt-text="Screenshot showing the Metamask browser extension to copy the account address"::: 24 | 25 | 4. Open a browser window or tab, and navigate to: [https://faucet.ropsten.be/](https://faucet.ropsten.be/) 26 | 5. Request ether by entering your testnet account address and clicking on the button “Send me test Ether”. 27 | 28 | :::image type="content" source="media\Ropsten_Test_Faucet_Request_Ether.png" alt-text="Screenshot showing how to request test ether on the Ropsten faucet"::: 29 | 30 | 6. Go back to **Metamask** and verify that you now have Ether in your account. 31 | 32 | :::image type="content" source="media\Metamask_Ropsten_Test_with_1_Ether.png" alt-text="Screenshot showing the Metamask browser extension with 1 Ether"::: 33 | 34 | ### Install HDWalletProvider and fs 35 | 36 | You'll need [HDWalletProvider](https://www.npmjs.com/package/@truffle/hdwallet-provider) as a wallet enabled web3 provider to provide your secret mnemonic and connection network address and [fs](https://www.npmjs.com/package/fs) to read from your filesystem. 37 | 38 | To install both of those, focus your attention back to the *todolist* project in Visual Studio Code. Open the terminal window and run the following commands: 39 | 40 | 1. npm init 41 | 2. npm install fs 42 | 3. npm install @truffle/hdwallet-provider 43 | 44 | Wait for the installations of fs and HDWalletProvider to complete. You may see a number of warnings but unless there are errors, they can be ignored. 45 | 46 | ### Set up Infura and link the endpoints to the Ropsten Test Network 47 | 48 | [Infura](https://infura.io/) development suite provides instant, scalable **API** access to the Ethereum networks. Infura is a hosted Ethereum node cluster which gives users the ability to run an application on a public network. Infura gives users the ability to deploy and interact with public networks. 49 | 50 | Setting up an account is easy and has no cost. Go to the [Infura website](http://www.infura.io/) and do the following: 51 | 52 | 1. Set up an account and confirm your email address 53 | 1. Select *Ethereum* and then *Create new project* and name the project **TodoList**. 54 | 1. Under the *Keys* section, change the endpoint to *Ropsten* using the dropdown. 55 | 56 | It should look similar to the Test Project below. 57 | 58 | :::image type="content" source="media\Infura_Test_Project.png" alt-text="Screenshot showing the process of creating an Infura project."::: 59 | 60 | ## Connect to Ropsten 61 | 62 | Focus your attention back on the *todolist* project folder in Visual Studio Code. 63 | 64 | In the Truffle configuration file, *./truffle-config.js*, un-comment the lines for **HDWallet Provider**, **InfruaKey**, **fs** and **mnemonic**: 65 | 66 | ```javascript 67 | const HDWalletProvider = require('@truffle/hdwallet-provider'); 68 | const infuraKey = "fj4jll3k....."; 69 | 70 | const fs = require('fs'); 71 | const mnemonic = fs.readFileSync(".secret").toString().trim(); 72 | ``` 73 | 74 | Go to your Infura account to get the *infuraKey*. In Infura, this is called the *Project ID* and also visible as part of the Ropsten endpoint. 75 | 76 | :::image type="content" source="media\Infurakey.png" alt-text="Screenshot focused on the Ropsten endpoint to copy."::: 77 | 78 | Press the clipboard icon next to *Project ID* to copy and head back to the **./truffle-config.js** to paste in the *infuraKey*. Below is a sample of what this looks like, but note, your key will be different: 79 | 80 | ```javascript 81 | const infuraKey = "f6bfe21890a84b9fa27def74bafb0b1b"; 82 | ``` 83 | 84 | Create a file called **.secret** and copy your mnemonic to that file. To get your mnemonic, go to MetaMask and navigate to *Settings* and then *Security & Privacy*. Select to **Reveal Seed Phrase**. Enter your Metamask password to verify and then select to *Copy to clipboard*. 85 | 86 | >Note 87 | >do not share this with anyone or they will be able to access your account! If you are using **git**, make sure to include **.secret** in your **.gitignore** file. 88 | 89 | :::image type="content" source="media\Reveal_Metamask_Seed_Phrase.png" alt-text="Screenshot to show how to reveal seed phrase in Metamask."::: 90 | 91 | The code below will read the seed phrase from the file **.secret** and trim all the white spaces: 92 | 93 | ```javascript 94 | const mnemonic = fs.readFileSync(".secret").toString().trim(); 95 | ``` 96 | 97 | Now define the network by un-commenting the *Ropsten* network settings in **truffle-config.js**. Make sure that your configuration looks like the following: 98 | 99 | ```javascript 100 | ropsten: { 101 | provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/${infuraKey}`), 102 | network_id: 3, // Ropsten's id 103 | gas: 5500000, // Ropsten has a lower block limit than mainnet 104 | confirmations: 2, // # of confs to wait between deployments. (default: 0) 105 | timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50) 106 | skipDryRun: true // Skip dry run before migrations? (default: false for public nets ) 107 | }, 108 | ``` 109 | 110 | ## Deploy to Ropsten 111 | 112 | To deploy to Ropsten run the following command from the Visual Studio Code terminal: **truffle migrate --network ropsten** 113 | 114 | If your connection is successful, you will see the following output: 115 | 116 | ```output 117 | Compiling your contracts... 118 | =========================== 119 | > Everything is up to date, there is nothing to compile. 120 | 121 | Warning: Both truffle-config.js and truffle.js were found. Using truffle-config.js. 122 | 123 | Compiling your contracts... 124 | =========================== 125 | > Everything is up to date, there is nothing to compile. 126 | 127 | 128 | Starting migrations... 129 | ====================== 130 | > Network name: 'ropsten' 131 | > Network id: 3 132 | > Block gas limit: 8000029 (0x7a121d) 133 | 134 | 135 | 1_initial_migration.js 136 | ====================== 137 | 138 | Deploying 'Migrations' 139 | ---------------------- 140 | > transaction hash: 0x2f456acc5f842ddf0eb151742e47dd6e8ec5e48d73b1f150e2908cb56e0bf174 141 | > Blocks: 1 Seconds: 29 142 | > contract address: 0x789101d0B0Ffa4f8f87E67AF8ff8F84bD519752D 143 | > block number: 9398701 144 | > block timestamp: 1609784599 145 | > account: 0x896587D82C895F30433cade401068C2791A6936F 146 | > balance: 0.99616138 147 | > gas used: 191931 (0x2edbb) 148 | > gas price: 20 gwei 149 | > value sent: 0 ETH 150 | > total cost: 0.00383862 ETH 151 | 152 | Pausing for 2 confirmations... 153 | ------------------------------ 154 | > confirmation number: 1 (block: 9398702) 155 | > confirmation number: 2 (block: 9398703) 156 | 157 | > Saving migration to chain. 158 | > Saving artifacts 159 | ------------------------------------- 160 | > Total cost: 0.00383862 ETH 161 | 162 | 163 | 2_deploy_contracts.js 164 | ===================== 165 | 166 | Deploying 'TodoList' 167 | -------------------- 168 | > transaction hash: 0xad8066308e9cc8503400c86a43674d856a71e02696e2c21b3e55f566df5afc36 169 | > Blocks: 0 Seconds: 8 170 | > contract address: 0x48112BE8d0E6e7bA892aFa2d4Ab58e9c43dd37De 171 | > block number: 9398706 172 | > block timestamp: 1609784870 173 | > account: 0x896587D82C895F30433cade401068C2791A6936F 174 | > balance: 0.98513544 175 | > gas used: 508959 (0x7c41f) 176 | > gas price: 20 gwei 177 | > value sent: 0 ETH 178 | > total cost: 0.01017918 ETH 179 | 180 | Pausing for 2 confirmations... 181 | ------------------------------ 182 | > confirmation number: 1 (block: 9398707) 183 | > confirmation number: 2 (block: 9398708) 184 | 185 | > Saving migration to chain. 186 | > Saving artifacts 187 | ------------------------------------- 188 | > Total cost: 0.01017918 ETH 189 | 190 | 191 | Summary 192 | ======= 193 | > Total deployments: 2 194 | > Final cost: 0.0140178 ETH 195 | ``` 196 | 197 | ## Verify deployment of contract 198 | 199 | ## On Metamask 200 | 201 | Inspect Metamask to verify that the ether used to deploy the contract 202 | 203 | source="media\Metamask_balance_after_deploying_to Ropsten.png" alt-text="Screenshot showing the Metamask balance after deploying to Ropsten"::: 204 | 205 | ## On Ropsten Etherscan 206 | 207 | Go to [ropsten.etherscan.io](ropsten.etherscan.io), enter in the contract address and inspect your contract. 208 | 209 | :::image type="content" source="media\Ropsten_Etherscan_with_deployed_contract.png" alt-text="Screenshot showing the contract deployed in Etherscan ."::: 210 | 211 | You can also open a new terminal window within Visual Studio Code and similar to interacting with your contract on the ganache development blockchain, you can interact with your contract with the **truffle console**. The sample code below displays two networks which are active. Continue to interact with and inspect transactions using *truffle console* and *Ropsten Etherscan*. 212 | -------------------------------------------------------------------------------- /ethereum-networks/includes/7-knowledge-check.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/ethereum-networks/includes/7-knowledge-check.md -------------------------------------------------------------------------------- /ethereum-networks/includes/8-summary.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | In this module, you learned about the networks that are part of Ethereum. You read an overview of the different public and private networks, learned about what is needed to prepare your solution for mainnet, and deployed an application to the Ropsten test network. 4 | -------------------------------------------------------------------------------- /ethereum-networks/index.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:Module 2 | uid: learn.reactors.blockchain- 3 | metadata: 4 | title: Connect and deploy to Ethereum networks 5 | description: Learn about and use multiple networks that Ethereum has available for development, testing, and production. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Connect and deploy to Ethereum networks 12 | summary: Learn about and use multiple networks that Ethereum has available for development, testing, and production. 13 | abstract: | 14 | By the end of this module, you will be able to: 15 | 16 | - Identify the public and private networks available in Ethereum. 17 | - Explain what is required to prepare a solution for the mainnet 18 | - Know how to use Metamask with Infura to connect a solution to networks 19 | prerequisites: | 20 | - [Fundamental knowledge about blockchain](https://docs.microsoft.com/learn/modules/intro-to-blockchain/?azure-portal=true) 21 | - [Solidity programming knowledge](https://docs.microsoft.com/learn/modules/blockchain-learning-solidity/?azure-portal=true) 22 | - [Ethereum smart contract knowledge](https://docs.microsoft.com/learn/modules/blockchain-solidity-ethereum-smart-contracts/?azure-portal=true) 23 | - Previous experience with a programming language like C, Python, or JavaScript 24 | - Basic knowledge of programming concepts 25 | - Familiarity with the command line to create new directories and install programs 26 | - Node.js installed 27 | - Truffle and Ganache CLI installed 28 | - Visual Studio Code installed 29 | - Blockchain Development Kit for Ethereum installed 30 | iconUrl: /learn/achievements/generic-badge.svg # TODO change 31 | levels: 32 | - beginner 33 | roles: 34 | - developer 35 | - student 36 | products: 37 | - azure 38 | units: 39 | - learn.reactors.blockchain-.1-introduction 40 | - learn.reactors.blockchain-.2-public-networks 41 | - learn.reactors.blockchain-.3-private-networks 42 | - learn.reactors.blockchain-.4-prepare-for-mainnet 43 | - learn.reactors.blockchain-.5-develop-deploy-development 44 | - learn.reactors.blockchain-.6-deploy-ropsten-network 45 | - learn.reactors.blockchain-.8-summary 46 | badge: 47 | uid: learn.reactors.blockchain-.badge 48 | -------------------------------------------------------------------------------- /ethereum-networks/media/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/ethereum-networks/media/.DS_Store -------------------------------------------------------------------------------- /ethereum-networks/media/Infura_Test_Project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/ethereum-networks/media/Infura_Test_Project.png -------------------------------------------------------------------------------- /ethereum-networks/media/Infurakey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/ethereum-networks/media/Infurakey.png -------------------------------------------------------------------------------- /ethereum-networks/media/Metamask_0_Eth_Connect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/ethereum-networks/media/Metamask_0_Eth_Connect.png -------------------------------------------------------------------------------- /ethereum-networks/media/Metamask_Ropsten_Test_with_1_Ether.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/ethereum-networks/media/Metamask_Ropsten_Test_with_1_Ether.png -------------------------------------------------------------------------------- /ethereum-networks/media/Metamask_balance_after_deploying_to Ropsten.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/ethereum-networks/media/Metamask_balance_after_deploying_to Ropsten.png -------------------------------------------------------------------------------- /ethereum-networks/media/Reveal_Metamask_Seed_Phrase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/ethereum-networks/media/Reveal_Metamask_Seed_Phrase.png -------------------------------------------------------------------------------- /ethereum-networks/media/Ropsten_Etherscan_with_deployed_contract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/ethereum-networks/media/Ropsten_Etherscan_with_deployed_contract.png -------------------------------------------------------------------------------- /ethereum-networks/media/Ropsten_Test_Faucet_Request_Ether.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/ethereum-networks/media/Ropsten_Test_Faucet_Request_Ether.png -------------------------------------------------------------------------------- /ethereum-networks/media/etherscan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/ethereum-networks/media/etherscan.png -------------------------------------------------------------------------------- /smart-contracts/1-introduction.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Introduction 5 | description: Introduction 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Introduction 12 | durationInMinutes: 1 13 | content: | 14 | [!include[](includes/1-introduction.md)] -------------------------------------------------------------------------------- /smart-contracts/2-smart-contracts.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Learn what smart contracts are 5 | description: Learn what smart contracts are 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Learn what smart contracts are 12 | durationInMinutes: 4 13 | content: | 14 | [!include[](includes/2-smart-contracts.md)] -------------------------------------------------------------------------------- /smart-contracts/3-dev-kit-dependencies.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Exercise - Install dependencies needed for the Blockchain Development Kit for Ethereum 5 | description: Install dependencies needed for the Blockchain Development Kit for Ethereum 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Exercise - Install dependencies needed for the Blockchain Development Kit for Ethereum 12 | durationInMinutes: 8 13 | content: | 14 | [!include[](includes/3-dev-kit-dependencies.md)] -------------------------------------------------------------------------------- /smart-contracts/4-blockchain-dev-kit.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Exercise - Install the Blockchain Development Kit for Ethereum 5 | description: Install the Blockchain Development Kit for Ethereum 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Exercise - Install the Blockchain Development Kit for Ethereum 12 | durationInMinutes: 8 13 | content: | 14 | [!include[](includes/4-blockchain-dev-kit.md)] -------------------------------------------------------------------------------- /smart-contracts/5-truffle.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Exercise - Install Truffle 5 | description: Install Truffle 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Exercise - Install Truffle 12 | durationInMinutes: 8 13 | content: | 14 | [!include[](includes/5-truffle.md)] -------------------------------------------------------------------------------- /smart-contracts/6-write-contract.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Exercise - Write a smart contract with the Blockchain Development Kit for Ethereum 5 | description: Write a smart contract with the Blockchain Development Kit for Ethereum 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Exercise - Write a smart contract with the Blockchain Development Kit for Ethereum 12 | durationInMinutes: 10 13 | content: | 14 | [!include[](includes/6-write-contract.md)] -------------------------------------------------------------------------------- /smart-contracts/7-test-contract.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Exercise - Test your smart contract 5 | description: Test your smart contract 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Exercise - Test your smart contract 12 | durationInMinutes: 8 13 | content: | 14 | [!include[](includes/7-test-contract.md)] -------------------------------------------------------------------------------- /smart-contracts/8-knowledge-check.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Knowledge check 5 | description: Knowledge check 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Knowledge check 12 | durationInMinutes: 1 13 | content: | 14 | [!include[](includes/8-knowledge-check.md)] -------------------------------------------------------------------------------- /smart-contracts/9-summary.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Summary 5 | description: Summary 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Summary 12 | durationInMinutes: 1 13 | content: | 14 | [!include[](includes/9-summary.md)] 15 | quiz: 16 | title: Check your knowledge 17 | questions: 18 | - content: "What are smart contracts?" 19 | choices: 20 | - content: "Programs to send cryptocurrency." 21 | isCorrect: false 22 | explanation: "They are often used for much more than cryptocurrency." 23 | - content: "Programs that generate and send tokens" 24 | isCorrect: false 25 | explanation: "Tokens are often associated with smart contracts but are focused on more than just that aspect." 26 | - content: "Programs stored inside of a blockchain that represent an agreement between parties sending digital assets" 27 | isCorrect: true 28 | explanation: "Correct! Smart contracts are stored in blockchains and can represent the transfer of any digital asset." 29 | - content: "Programs stored external to a blockchain that must be signed by participants" 30 | isCorrect: false 31 | explanation: "Almost there. But smart contracts are stored inside blockchains not externally." 32 | - content: "When you create a new project with the Blockchain Development Kit for Ethereum, what is automatically generated in the project folder?" 33 | choices: 34 | - content: "A contracts directory" 35 | isCorrect: false 36 | explanation: "A contracts directory with a couple contracts is generated, but that's not all." 37 | - content: "A tests directory" 38 | isCorrect: false 39 | explanation: "There is a contracts directory and tests that are generated, but there's more to it than that" 40 | - content: "A migrations directory" 41 | isCorrect: false 42 | explanation: "A migrations directory is created with two migrations. Migrations must exist with a contract, so there must be a contract that exists as well." 43 | - content: "All of the above" 44 | isCorrect: true 45 | explanation: "Correct! A new project generates contracts, migrations, and tests. That way you can build off these examples to create your own smart contract projects." 46 | - content: "What option that best completes this sentence: Truffle is ______ ?" 47 | choices: 48 | - content: "A command line utility to create smart contracts" 49 | isCorrect: false 50 | explanation: "Not quite. This describes one part of what Truffle helps with, but it provides many more utilities other than creating smart contracts and is typically not described as a command line utility." 51 | - content: "A development environment, testing framework, and asset pipeline for blockchains" 52 | isCorrect: true 53 | explanation: "Truffle is described as a development framework which makes it easy manage smart contracts from creation to testing to deployment." 54 | - content: "A personal blockchain Ethereum development tool to deploy contracts" 55 | isCorrect: false 56 | explanation: "This best describes Ganache, a tool in the Truffle Suite to view the activities happening in your blockchain." 57 | - content: "A library to make it easier to write blockchain applications" 58 | isCorrect: false 59 | explanation: "this best describes Drizzle, a tool in the Truffle Suite to help easily create decentralized applications." -------------------------------------------------------------------------------- /smart-contracts/includes/1-introduction.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | The use of smart contracts is growing as blockchain continues to evolve. In this phase of blockchain, there are vast use cases revolve around building smart contracts and business applications. 4 | 5 | It's an exciting time as we are starting to see more real-world applications of blockchain in nearly every industry imaginable. 6 | 7 | As developers are more drawn to blockchain and want to create their own applications, it's necessary that they know how to use Solidity to create and test smart contracts. It's also useful if developers are aware of the great, and free development tools available to manage blockchain applications. 8 | 9 | ## Learning Objectives 10 | 11 | By the end of this module, you will be able to: 12 | 13 | - Explain what smart contracts are 14 | - Know common use cases for smart contracts 15 | - Know how to install the Blockchain Development Kit 16 | - Know how to install Truffle 17 | - Write a smart contract with the help of the Blockchain Development Kit 18 | - Test a smart contract with Truffle 19 | 20 | ## Prerequisites 21 | 22 | - Blockchain fundamentals knowledge 23 | - Ethereum platform knowledge 24 | - Familiarity with Solidity programming language 25 | - Visual Studio Code installed 26 | - Knowledge of how to download programs from the internet 27 | - Knowledge of how to use the command line 28 | - An Azure account 29 | -------------------------------------------------------------------------------- /smart-contracts/includes/2-smart-contracts.md: -------------------------------------------------------------------------------- 1 | # Learn what smart contracts are 2 | 3 | ## About 4 | 5 | A smart contract is a program stored inside of a blockchain. Smart contracts extend blockchain from data to code. They represent an agreement between parties. The agreement is coded and when an action happens, the code is executed and provides a response. 6 | 7 | All of the terms and conditions of the contracts are programmatically defined. The definition specifies the rules, requirements and rewards for those who participate in the blockchain, and how digital assets are transferred between parties. Each smart contract is assigned a 20 byte address that is used to uniquely identify it. 8 | 9 | They execute on their own, send events, call functions and more. They are perfect for blockchain technology because they allow parties that do not know one another to conduct business in a securely specified way without the use of a middleman. 10 | 11 | The most prominent use for smart contracts is with Ethereum, the worlds first programmable blockchain, that allows for smart contracts to be defined to help facilitate the transfer of digital assets like Ether. 12 | 13 | The language to write contracts in is Solidity. Solidity is Turing complete which means you can write complicated contracts that are defined and coded in a clear way. 14 | 15 | Since every state transition is logged and immutable it is imperative that you thoroughly test the contract before going to production, because bug fixes can be very costly and even cause critical damage to the system. 16 | 17 | The key properties and advantages of smart contracts are that they are: 18 | 19 | - **Transparent**: It is publicly readable by others on the blockchain and accessible via APIs 20 | - **Immutable**: Once a smart contract is created it cannot be changed again. 21 | - **Distributed**: Output of the contract is validated and verified by nodes on the network. Contract states can be publicly visible, and in some cases even “private” variables are visible. 22 | 23 | ## Use cases 24 | 25 | - **Insurance**: Smart contracts can simplify and streamline the claims process by automatically triggering a claim when certain events occur. Claim details can be recorded on the blockchain in order to determine the amount of compensation. This would reduce processing times and human errors. 26 | - **Voting**: Smart contracts can be used to make voting automatic and transparent. Each contract can serve as one ballot which represents a voter's identity. Since a blockchain is immutable, it can ensure that votes have not been tampered with and that there is no voting fraud. 27 | - **Supply chain**. Smart contracts can record ownership rights as items move through the supply chain confirming who is responsible for the product at any given time. At any step of the process, the smart contract can be used to find out exactly where the products should be. If any party involved failed to deliver on time, then every other party will see this. 28 | - **Protected copyright content**. Smart contracts can help ensure that the owner of the content can receive royalties in a fair and distributed way. 29 | - **Record keeping**. Many industries will be able to use smart contracts to help improve the speed and security of record keeping. Blockchain technology can allow records to all be digitized and securely encrypted and stored. Plus, access can be gated so that only allowed individuals can access the records. 30 | - **Property ownership**. Smart contracts can be used to record who owns property. This is a much faster and cost-efficient way to record ownership. Smart contracts can also help to facilitate the transfer of ownership. 31 | 32 | ## Tools for working with smart contracts 33 | 34 | There are numerous tools available to help you more effectively develop smart contracts. 35 | 36 | ### Integrated Development Environments 37 | 38 | - [Visual Studio Code](https://code.visualstudio.com/): Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. This module will use Visual Studio Code for all exercises. 39 | - [Remix](https://remix.ethereum.org/): Remix is a browser-based compiler and IDE that enables users to build Ethereum contracts with Solidity language and to debug transactions. Remix is a great option to explore sample contracts, and write, test, and deploy your own contracts. We won't be using Remix in this module, but it's an option available for you to try out the contract exercises. 40 | 41 | ### Extensions 42 | 43 | - [Blockchain Development Kit for Ethereum](https://marketplace.visualstudio.com/items?itemName=AzBlockchain.azure-blockchain): The Blockchain Development Kit extension simplifies how you create, build and deploy smart contracts on Ethereum ledgers. This module will use the help of the Blockchain Development Kit to help write, and test smart contracts. 44 | 45 | ### Frameworks 46 | 47 | - [Truffle Suite](https://www.trufflesuite.com): The Truffle tool suite is used to test Ethereum contracts before they are deployed to public ledgers and incur real costs. You want to develop locally and make your life as a developer easier. The suite includes: Truffle, Ganache, and Drizzle. In this module, we will be using Truffle. 48 | - [OpenZeppelin](https://openzeppelin.com/): OpenZeppelin provides tools to write, deploy and operate decentralized applications. There are two different products that OpenZeppelin provides- the contracts library and the SDK. We will not be using OpenZeppelin in this module, but it's good to know that this is an option available that can help write secure blockchain applications in the future. 49 | -------------------------------------------------------------------------------- /smart-contracts/includes/3-dev-kit-dependencies.md: -------------------------------------------------------------------------------- 1 | # Exercise: Install dependencies needed for the Blockchain Development Kit for Ethereum 2 | 3 | ## Dependencies to install 4 | 5 | To use the Blockchain Development Kit, you will need to make sure you have the following installed: 6 | 7 | ### Python 8 | 9 | - Need version 2.7.15 or greater 10 | - Please note, you must have Python installed in your `PATH` variable. 11 | - Note: Most computers will come with Python pre-installed, however it might not be up-to-date. To check if you do have Python installed, open up a terminal and type `python` 12 | - If installed, it will print out the version of Python that you have on your computer 13 | - To install Python, visit[the Python downloads page](https://www.python.org/downloads/) and click on the **Download Python X.X.X** button. Note that the image shows the download option for a Mac computer. If you have a Linux or Windows computer you will be presented with that download option. 14 | 15 | :::image type="content" source="media\python-download.png" alt-text="Download Python"::: 16 | 17 | - Follow the prompts to download Python, and make sure to select the option to **Add Python to PATH** if that's presented to you. 18 | 19 | ### Node 20 | 21 | - Need version 10.15.x or greater 22 | - To install Node, visit the [Node.js downloads page](https://nodejs.org/download/). Select the installer for your platform 23 | 24 | :::image type="content" source="media\node-download.png" alt-text="Download Node"::: 25 | 26 | - To confirm Node.js is installed, open your terminal and type: `node`. If installed successfully, the terminal will return the version of Node.js installed. You can also confirm that npm is installed by typing `npm` in the terminal. 27 | 28 | ### Git 29 | 30 | - Need version 2.10.x or greater 31 | - Visit the [Git downloads page](https://git-scm.com/downloads) and select your platform. Follow the instructions to download Git. 32 | 33 | :::image type="content" source="media\git-download.png" alt-text="Download Git"::: 34 | 35 | - Note that the image shows the download option for a Mac computer. If you have a Linux or Windows computer you will be presented with that download option. 36 | - Once installed, open your terminal and type `git`. If installed successfully, the terminal will return a list of git commands available. -------------------------------------------------------------------------------- /smart-contracts/includes/4-blockchain-dev-kit.md: -------------------------------------------------------------------------------- 1 | # Exercise: Install and get started with the Blockchain Development Kit for Ethereum 2 | 3 | ## Install the extension 4 | 5 | [Blockchain Development Kit for Ethereum](https://marketplace.visualstudio.com/items?itemName=AzBlockchain.azure-blockchain) is an extension you can use in Visual Studio Code. The extension makes it easy to create, build, and deploy smart contracts on Ethereum ledgers. 6 | 7 | Simply go to **Extensions** and search for **Blockchain Development Kit** and install it. 8 | 9 | :::image type="content" source="media\bdk-install.png" alt-text="Install Blockchain Development Kit"::: 10 | 11 | ## Get started 12 | 13 | ### Create a New Solidity Project with the extension 14 | 15 | Once you have all the dependencies installed, you can now use the Blockchain Development Kit to create your first project. 16 | 17 | 1. Start by adding a new empty directory to your computer for the project. Note: You can open your terminal and type `mkdir newSolidityProject` to create a new directory. Keep note of where this new empty directory is, but you don't need it yet. 18 | 2. Open Visual Studio Code. 19 | 3. Go to View -> Command Palette. In the search box type: `Blockchain: New Solidity Project`. You'll notice that as you begin to type "Blockchain" a list of commands will be presented. 20 | 21 | :::image type="content" source="media\new-solidity-project-selection.png" alt-text="Select New Solidity project option"::: 22 | 23 | 4. For the type of solidity project, select **Create basic project**. 24 | 25 | :::image type="content" source="media\create-basic-project.png" alt-text="Create basic project"::: 26 | 27 | 5. Use the UI file explorer pop up to find the folder you created in step 1. Select the folder and in the bottom right-hand of the window you'll see **Creating new project** 28 | 6. Sit back and wait for your new Solidity project to be created. 29 | 30 | Once it is, open the Explorer and take a look at all the files that were created in the project. 31 | 32 | :::image type="content" source="media\new-solidity-project.png" alt-text="New workspace for solidity project"::: 33 | 34 | In this project, you will have a boiler plate of Solidity code that you can use. Notice that you have directories for: 35 | 36 | - **contracts:** Contains the **HelloBlockchain.sol** and **Migrations.sol** contracts 37 | - **migrations:** Contains an initial migration and a deploy contract. 38 | - **test:** Contains a test for the HelloBlockchain contract written in JavaScript 39 | 40 | You'll also have some other config files: 41 | 42 | - **package.json:** To define project details and dependencies 43 | - **truffle-config.json:**. To define dependencies and configuration for Truffle 44 | 45 | Go ahead and go to `File -> Save Workspace As...` and save the workspace with name **newsolidityproject**. 46 | 47 | Then focus your attention back to the project itself. For now we will only focus on the **contracts/** directory. 48 | 49 | ## Compile the contracts 50 | 51 | We will start by using the **HelloBlockchain.sol** smart contract inside of the contracts folder. 52 | 53 | 1. Go to contracts/HelloBlockchain.sol 54 | Right click HelloBlockchain.sol 55 | 2. Click on **Build Contracts** to compile the smart contract. Notice the window appear in the bottom right that says: "Building contracts" 56 | 3. Select View -> Output to see information about the compiled contract. Note: In the dropdown window you may need to select "Azure Blockchain" to see output from the extension 57 | 58 | :::image type="content" source="media\build-contracts.png" alt-text="Build contracts"::: 59 | 60 | In the output window (View -> Output) you can see information about the contracts compilation: 61 | 62 | :::image type="content" source="media\compile-output.png" alt-text="Build contracts output"::: 63 | 64 | ## Deploy contracts 65 | 66 | After the contract has compiled successfully, you can deploy the contract locally. This step requires you to sign into your Azure account. 67 | 68 | 1. Go to contracts/HelloBlockchain.sol 69 | 2. Right click HelloBlockchain.sol 70 | 3. Click on **Deploy Contracts** and select development in the window that appears. Here you will be prompted to sign in to Azure if you are not already. 71 | 72 | :::image type="content" source="media\deploy-contracts.png" alt-text="Deploy contracts"::: 73 | 74 | 4. In the output window (View -> Output) you can see information about the deployed migrations and contracts 75 | 76 | :::image type="content" source="media\deploy-details.png" alt-text="Deploy details in output window"::: 77 | 78 | Here you see some key information, or metadata about the contract you just deployed: 79 | 80 | - The address of the contract 81 | - Time stamp of the block that the contract creation transaction was a part of 82 | - The address of the account that deployed the contract 83 | - The balance (in Ether) that the account has after this transaction was made. The balance is 100 ETH (the starting default value) minus the `total cost` 84 | - The amount of gas used and the gas price. Gas refers to the fee, required to successfully conduct a transaction or execute a contract on the Ethereum blockchain platform. You can think of it of the gas you need to put into your car to drive places. 85 | - Note: Gas prices are denoted in gwei, with are worth 0.000000001 ETH. 86 | - Total cost = gas price * gas use 87 | -------------------------------------------------------------------------------- /smart-contracts/includes/5-truffle.md: -------------------------------------------------------------------------------- 1 | # Exercise: Install Truffle 2 | 3 | ## About Truffle 4 | 5 | Truffle is the most popular development framework for Ethereum. It can easily be installed with the help of the node package manager. 6 | 7 | With Truffle, you get some of the following benefits: 8 | 9 | - Smart contract building, compilation, deployment, testing and more 10 | - Network management for deploying to public & private networks 11 | - Package management for dependencies 12 | - Interactive console for direct contract communication 13 | - Configurable build pipeline 14 | 15 | ## Install Truffle 16 | 17 | From your terminal, you can install Truffle with the help of npm. Type: 18 | 19 | `npm install -g truffle` 20 | 21 | To confirm truffle is installed, type: 22 | 23 | `truffle` 24 | 25 | That will show the version installed and present the list of commands available to use Truffle with: 26 | 27 | :::image type="content" source="media\truffle.png" alt-text="Truffle options shown in terminal"::: 28 | 29 | ## Get started with using Truffle 30 | 31 | Now that Truffle is installed, let's use it to run the tests that were generated as part of our newSolidityProject. 32 | 33 | You can find the test file in test/HelloBlockchain.js. Take a look through the test file to try to understand what's being tested. 34 | 35 | 1. In Visual Studio Code, go to Terminal -> New Terminal 36 | 1. In the terminal run `truffle compile`. Wait for the source files to compile successfully. 37 | 1. Then run `truffle migrate`. Wait for the migrations to finish 38 | 39 | ### Test the contract 40 | 41 | Let's use it to run the tests that were generated as part of our newSolidityProject. 42 | 43 | You can find the test file in test/HelloBlockchain.js. Take a look through the test file to try to understand what's being tested. 44 | 45 | From the terminal type: `truffle test`. 46 | 47 | Notice that the tests fail due to the following. 48 | 49 | ```markdown 50 | Could not connect to your Ethereum client with the following parameters: 51 | - host > 127.0.0.1 52 | - port > 8545 53 | - network_id > * 54 | Please check that your Ethereum client: 55 | - is running 56 | - is accepting RPC connections (i.e., "--rpc" option is used in geth) 57 | - is accessible over the network 58 | - is properly configured in your Truffle configuration file (truffle-config.js) 59 | ``` 60 | 61 | And this indicates that I need a local Ethereum blockchain client running for the tests to access. 62 | 63 | ### Ganache-cli 64 | 65 | The most popular local Ethereum blockchain is Ganache. We're going to use the [CLI](https://github.com/trufflesuite/ganache-cli) version to interact with it directly from the terminal. Ganache CLI is commonly used for development and testing. To install it on your project, focus your attention to the terminal. Right-click and select `New Terminal`. Once the new terminal window opens run: 66 | `npm install -g ganache-cli` 67 | 68 | Once Ganache CLI installs successfully, run: 69 | `ganache-cli` 70 | 71 | :::image type="content" source="media\start-ganache.png" alt-text="Start ganache-cli from the terminal"::: 72 | 73 | Notice that there are 10 accounts generated on this blockchain that each receive 100 test Ether to use. Each account also has a corresponding private key. And there is also a mnemonic, which is a unique twelve world phrase to access the wallet and allows transactions to be made from these accounts. 74 | 75 | And lastly, it displays its address, which we’ll use to connect to it. By default, this will be 127.0.0.1:8545. 76 | 77 | Now run `truffle test`. 78 | 79 | In the terminal you will now see that all tests have passed. 80 | 81 | :::image type="content" source="media\truffle-test.png" alt-text="Run truffle test from the terminal"::: -------------------------------------------------------------------------------- /smart-contracts/includes/6-write-contract.md: -------------------------------------------------------------------------------- 1 | # Exercise: Write a smart contract for tracking an item's status 2 | 3 | In this unit, we'll add a new smart contract to the newSolidityProject we previously created. 4 | 5 | ## Create a shipping contract 6 | 7 | The smart contract you will be creating is for tracking the status of items purchased from an online marketplace. When the contract is created, the shipping status will be set to `Pending`. Once shipped, the shipping status will be set to `Shipped` an event will be emitted. And once delivered, the shipping status is set to `Delivered` and another event will be emitted. 8 | 9 | 1. To get started with with this exercise, in the project you created earlier, under the **contracts/** directory, right-click on the folder and select to create a new file called **ShippingStatus.sol**. 10 | 2. Copy over the contents of this contract below into the file: 11 | 12 | ```solidity 13 | pragma solidity >=0.5.12<=0.7.0; 14 | 15 | contract ShippingStatus 16 | { 17 | // Our predefined values for shipping listed as enums 18 | enum ShippingStatus { Pending, Shipped, Delivered } 19 | 20 | // Save enum ShippingStatus in variable status 21 | ShippingStatus private status; 22 | 23 | // Event to launch when package has arrived 24 | event LogNewAlert(string description); 25 | 26 | // This initializes our contract state (sets enum to Pending once the program starts) 27 | constructor() public { 28 | status = ShippingStatus.Pending; 29 | } 30 | // Function to change to Shipped 31 | function Shipped() public { 32 | status = ShippingStatus.Shipped; 33 | emit LogNewAlert("Your package has been shipped"); 34 | } 35 | 36 | // Function to change to Delivered 37 | function Delivered() public { 38 | status = ShippingStatus.Delivered; 39 | emit LogNewAlert("Your package has arrived"); 40 | } 41 | 42 | // Function to get the status of the shipping 43 | function getStatus(ShippingStatus _status) internal pure returns (string memory) { 44 | // Check the current status and return the correct name 45 | if (ShippingStatus.Pending == _status) return "Pending"; 46 | if (ShippingStatus.Shipped == _status) return "Shipped"; 47 | if (ShippingStatus.Delivered == _status) return "Delivered"; 48 | } 49 | 50 | // Get status of your shipped item 51 | function Status() public view returns (string memory) { 52 | ShippingStatus _status = status; 53 | return getStatus(_status); 54 | } 55 | 56 | } 57 | ``` 58 | 59 | 3. Take a look through the contract to get familiar with what's happening here. 60 | 4. Confirm that you can successfully build the contract. Right click on the contract name in the file explorer and select **Build Contracts** to compile the smart contract. 61 | 62 | ## Add a migration 63 | 64 | Now let's add a migration so that we will be able to deploy the contract. To be able to deploy our smart contract to the Ethereum network we need to add another Migration file. 65 | 66 | 1. In the file explorer, hover over the **migrations/** folder and create a New File called **3_deploy_contracts.js**. 67 | 2. Add this code to the file: 68 | 69 | ```javascript 70 | const Shipping = artifacts.require("ShippingStatus"); 71 | module.exports = function (deployer) { 72 | deployer.deploy(ShippingStatus); 73 | }; 74 | ``` 75 | 76 | ## Deploy 77 | 78 | Next, make sure that you can deploy the contract successfully before moving on. Right-click on the contract name and select to **Deploy Contracts**. Select development in the window that appears and wait for the deployment to complete. 79 | 80 | Observe the information that is displayed in the output window. Look for a deployment of **3_deploy_contracts.js**. 81 | 82 | :::image type="content" source="media\shipping-status-migration.png" alt-text="Shipping status migration"::: 83 | -------------------------------------------------------------------------------- /smart-contracts/includes/7-test-contract.md: -------------------------------------------------------------------------------- 1 | # Exercise: Test a smart contract with Truffle 2 | 3 | In this unit, we will write a new test for our shipping contract in JavaScript. We could also use Solidity to write tests, but JavaScript is what's used most commonly. To test our smart contract we will use **Truffle**. 4 | 5 | ## Let the testing begin 6 | 7 | 1. Let’s create our first test by creating a new test file. Go to Terminal -> New Terminal. 8 | 1. One the terminal is opened, type: `truffle create test ShippingStatus`. In our folder test a JavaScript file has been created called ShippingStatus.js. Remove the code in the file and replace it with: 9 | 10 | ```javascript 11 | const ShippingStatus = artifacts.require("ShippingStatus"); 12 | contract('ShippingStatus', () => { 13 | 14 | it("should return the status Pending", async ()=> { 15 | // Instance of our deployed contract 16 | const instance = await ShippingStatus.deployed(); 17 | // Checking the initial status in our contract 18 | const status = await instance.Status(); 19 | // Checking if the status is initially Pending as set in the constructor 20 | assert.equal(status, "Pending"); 21 | }); 22 | it("should return the status Shipped", async ()=> { 23 | // Instance of our deployed contract 24 | const instance = await ShippingStatus.deployed(); 25 | 26 | // Calling the Shipped() function 27 | await instance.Shipped(); 28 | 29 | // Checking the initial status in our contract 30 | const status = await instance.Status(); 31 | 32 | // Checking if the status is Shipped 33 | assert.equal(status, "Shipped"); 34 | }); 35 | 36 | it("should return the status Delivered", async ()=> { 37 | 38 | // Instance of our deployed contract 39 | const instance = await ShippingStatus.deployed(); 40 | 41 | // Calling the Shipped() function 42 | await instance.Delivered(); 43 | 44 | // Checking the initial status in our contract 45 | const status = await instance.Status(); 46 | 47 | // Checking if the status is Delivered 48 | assert.equal(status, "Delivered"); 49 | }); 50 | }); 51 | ``` 52 | 53 | ### Event test 54 | 55 | We will use the package truffle-assertions to help us test our events. By using this package we can assert that our events are emitted during the transaction. 56 | 57 | 1. Go back to the terminal and install the library by typing: `npm install truffle-assertions` 58 | 2. Add this to the top of the test file on line 2 after requiring the ShippingStatus contract: 59 | ```javascript 60 | const truffleAssert = require('truffle-assertions'); 61 | ``` 62 | 3. And then add a test to confirm the event returns the expected description. Place this test after the last test in the file, in a new line, right before the last line (set of closing braces). 63 | 64 | ```javascript 65 | it('should return correct event description', async()=>{ 66 | 67 | // Instance of our deployed contract 68 | const instance = await ShippingStatus.deployed(); 69 | 70 | // Calling the Delivered() function 71 | const delivered = await instance.Delivered(); 72 | 73 | // Check event description is correct 74 | truffleAssert.eventEmitted(delivered, 'LogNewAlert', (event) =>{ 75 | return event.description == 'Your package has arrived'; 76 | }); 77 | }); 78 | 79 | ``` 80 | 81 | #### Using async/await 82 | 83 | The **.deployed()** function returns a promise. Because of this we use `await` in front of this, and also `async` in front of the test code. This means until the promise if fulfilled when the contract is deployed, we will not move forward with our test. This pattern is very commonly used in tests since almost all smart contract transactions are asynchronous. This is because transactions need to be validated, or mined before they are added to the blockchain ledger. 84 | 85 | Overall you should at least aim for 100% test coverage for your contract especially if you plan to deploy to the main Ethereum network, or main net. 86 | 87 | ## Run the test 88 | 89 | From the terminal type: `truffle test` 90 | 91 | You should see all tests successfully passing: 92 | 93 | ```nodejs 94 | Contract: HelloBlockchain 95 | ✓ testing ResponseMessage of HelloBlockchain 96 | ✓ testing Responder of HelloBlockchain 97 | ✓ testing RequestMessage of HelloBlockchain 98 | ✓ testing State of HelloBlockchain 99 | ✓ testing Requestor of HelloBlockchain 100 | ✓ testing SendRequest of HelloBlockchain (51ms) 101 | ✓ testing SendResponse of HelloBlockchain (46ms) 102 | 103 | Contract: ShippingStatus 104 | ✓ should return the status Pending 105 | ✓ should return the status Pending 106 | ✓ should return the status Shipped (59ms) 107 | ✓ should return the status Delivered (58ms) 108 | ✓ should return correct event description (39ms) 109 | ``` 110 | -------------------------------------------------------------------------------- /smart-contracts/includes/8-knowledge-check.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | - What are smart contracts? 4 | - Programs to send cryptocurrency 5 | - Programs stored inside of a blockchain that represent an agreement between parties 6 | - Programs that generate tokens 7 | - 8 | 9 | - True //incorrect. This can happen through the use of smart contracts, but that is not the primary purpose 10 | - False // correct. Smart contracts help to facilitate the transfer of digital assets. Some type of currency or coin is typically involved in transfer of assets, but not all smart contracts need include currency. 11 | 12 | - When you create a new project with the Blockchain Development Kit for Ethereum, what is automatically generated in the project folder? 13 | - Sample contract, migration, a test, and a truffle config file. 14 | - An initial contract file written in Solidity. 15 | - A build directory and files to compile and deploy the Solidity project. 16 | - Folders for contracts, migrations, and tests. 17 | 18 | 19 | - Select the option that best completes this sentence: Truffle is: 20 | 21 | - A command line utility to create smart contracts // incorrect. This describes one part of what Truffle helps with, but it provides many more utilities other than creating smart contracts and is typically not described as a command line utility. 22 | - A development environment, testing framework, and asset pipeline for blockchains // correct. Truffle is described as a development framework which makes it easy manage smart contracts from creation to testing to deployment. 23 | - A personal blockchain Ethereum development tool to deploy contracts //incorrect. This best describes Ganache, a tool in the Truffle Suite to view the activities happening in your blockchain. 24 | - A library to make it easier to write blockchain applications //incorrect. this best describes Drizzle, a tool in the Truffle Suite to help easily create decentralized applications. 25 | -------------------------------------------------------------------------------- /smart-contracts/includes/9-summary.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | In this module, you learned about some popular use cases for smart contracts. You also learned about and installed tools to help write and test smart contracts, including the Blockchain Development Kit for Ethereum and Truffle. 4 | -------------------------------------------------------------------------------- /smart-contracts/index.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:Module 2 | uid: "" 3 | metadata: 4 | title: Use Solidity to write Ethereum smart contracts 5 | description: Install and use tools that help make smart contract development easier. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Use Solidity to write Ethereum smart contracts 12 | summary: Install and use tools that help make smart contract development easier. 13 | abstract: | 14 | By the end of this module you will be able to: 15 | - Explain what smart contracts are 16 | - Know common use cases for smart contracts 17 | - Know how to install the Blockchain Development Kit 18 | - Know how to install Truffle 19 | - Write a smart contract with the help of the Blockchain Development Kit 20 | - Test a smart contract with Truffle 21 | prerequisites: | 22 | - Blockchain fundamentals knowledge 23 | - Ethereum platform knowledge 24 | - Familiarity with Solidity programming language 25 | - Visual Studio Code installed 26 | - Knowledge of how to download programs from the internet 27 | - Knowledge of how to use the command line 28 | - An Azure account 29 | iconUrl: /learn/achievements/generic-badge.svg # TODO change 30 | levels: 31 | - beginner 32 | roles: 33 | - developer 34 | - student 35 | products: 36 | - azure 37 | units: 38 | - "" 39 | badge: 40 | uid: "" 41 | -------------------------------------------------------------------------------- /smart-contracts/media/bdk-install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/bdk-install.png -------------------------------------------------------------------------------- /smart-contracts/media/build-contracts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/build-contracts.png -------------------------------------------------------------------------------- /smart-contracts/media/compile-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/compile-output.png -------------------------------------------------------------------------------- /smart-contracts/media/create-basic-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/create-basic-project.png -------------------------------------------------------------------------------- /smart-contracts/media/deploy-contracts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/deploy-contracts.png -------------------------------------------------------------------------------- /smart-contracts/media/deploy-details.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/deploy-details.png -------------------------------------------------------------------------------- /smart-contracts/media/git-download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/git-download.png -------------------------------------------------------------------------------- /smart-contracts/media/new-solidity-project-selection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/new-solidity-project-selection.png -------------------------------------------------------------------------------- /smart-contracts/media/new-solidity-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/new-solidity-project.png -------------------------------------------------------------------------------- /smart-contracts/media/node-download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/node-download.png -------------------------------------------------------------------------------- /smart-contracts/media/python-download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/python-download.png -------------------------------------------------------------------------------- /smart-contracts/media/shipping-status-migration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/shipping-status-migration.png -------------------------------------------------------------------------------- /smart-contracts/media/start-ganache.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/start-ganache.png -------------------------------------------------------------------------------- /smart-contracts/media/truffle-test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/truffle-test.png -------------------------------------------------------------------------------- /smart-contracts/media/truffle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/smart-contracts/media/truffle.png -------------------------------------------------------------------------------- /solidity/1-introduction.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Introduction 5 | description: Introduction 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Introduction 12 | durationInMinutes: 1 13 | content: | 14 | [!include[](includes/1-introduction.md)] -------------------------------------------------------------------------------- /solidity/2-what-is-solidity.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Learn about Solidity 5 | description: Learn what Solidity is all about 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: What is Solidity 12 | durationInMinutes: 2 13 | content: | 14 | [!include[](includes/2-what-is-solidity.md)] -------------------------------------------------------------------------------- /solidity/3-language-basics.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Understand the language basics 5 | description: Learn the fundamentals of using Solidity in a smart contract 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Understand the language basics 12 | durationInMinutes: 5 13 | content: | 14 | [!include[](includes/3-language-basics.md)] -------------------------------------------------------------------------------- /solidity/4-value-types.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Explore value types 5 | description: Learn about the primary value types you will use when working with Solidity. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Explore value types 12 | durationInMinutes: 4 13 | content: | 14 | [!include[](includes/4-value-types.md)] -------------------------------------------------------------------------------- /solidity/5-reference-types.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Explore reference types 5 | description: Learn about the reference types available in Solidity. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Explore reference types 12 | durationInMinutes: 4 13 | content: | 14 | [!include[](includes/5-reference-types.md)] -------------------------------------------------------------------------------- /solidity/6-exercise-write-your-first-contract.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Exercise - Write your first contract 5 | description: Put together what you've learned so far about Solidity and write your first smart contract. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Exercise - Write your first contract 12 | durationInMinutes: 7 13 | content: | 14 | [!include[](includes/6-write-your-first-contract.md)] -------------------------------------------------------------------------------- /solidity/7-knowledge-check.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Knowledge check 5 | description: 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Knowledge check 12 | durationInMinutes: 1 13 | content: | 14 | [!include[](includes/7-knowledge-check.md)] -------------------------------------------------------------------------------- /solidity/8-summary.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: 3 | metadata: 4 | title: Summary 5 | description: Summary 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Summary 12 | durationInMinutes: 1 13 | content: | 14 | [!include[](includes/9-summary.md)] 15 | quiz: 16 | title: Check your knowledge 17 | questions: 18 | - content: "Solidity smart contracts are run on what?" 19 | choices: 20 | - content: "Ethereum blockchain" 21 | isCorrect: false 22 | explanation: "This is the name of the platform Solidity targets, but not what test are run on." 23 | - content: "The Ethereum virtual machine" 24 | isCorrect: true 25 | explanation: "Correct! Solidity runs contracts on what's called the Ethereum virtual machine which is a sandboxed environment to self-contain all the transaction history for the contracts." 26 | - content: "A virtual machine" 27 | isCorrect: false 28 | explanation: "Partly correct. A virtual machine is an option to run tests in, but a specific kind of virtual machine is used for Solidity smart contracts" 29 | - content: "A sandbox environment" 30 | isCorrect: false 31 | explanation: "The Ethereum virtual machine is a sandboxed and isolated environment, but that is just a feature of the virtual machine, and not the main focus." 32 | - content: "Events in contracts describe actions that are taken in the contract. What is the correct syntax to define an event?" 33 | choices: 34 | - content: "event PurchasedItem;" 35 | isCorrect: false 36 | explanation: "Not quite. The event must be called like a function with a set of parenthesis at the end like `event PurchasedItem()` and include any arguments inside of the parenthesis." 37 | - content: "PurchasedItem(address buyer, uint price);" 38 | isCorrect: false 39 | explanation: "this would be the syntax to call a function that's previously been defined, not an event." 40 | - content: "emit PurchasedItem(address buyer, uint price);" 41 | isCorrect: false 42 | explanation: "this is the syntax to call the event and create an entry in the transactions log." 43 | - content: "event PurchasedItem(address buyer, uint price);" 44 | isCorrect: true 45 | explanation: "Correct! to define an event you used the keyword `event` and then give the event a name and describe which arguments, if any, must be included inside parenthesis." 46 | - content: "What is an example of a user-defined type in Solidity?" 47 | choices: 48 | - content: "Structs" 49 | isCorrect: true 50 | explanation: "Structs are user-defined because you can define the collection of items within a struct." 51 | - content: "State variables" 52 | isCorrect: false 53 | explanation: "State variables use defined types like uint, int, bool, and addresses to hold values that are used in contracts." 54 | - content: "Addresses" 55 | isCorrect: false 56 | explanation: "Addresses are 20 byte value types that represent an Ethereum user account. A value is specified for a given address type." 57 | - content: "Arrays" 58 | isCorrect: false 59 | explanation: "Arrays use defined types to store a collection of similar items of same type in a data structure." 60 | - content: "What is typically the first line of a smart contract source file?" 61 | choices: 62 | - content: "A pragma directive" 63 | isCorrect: true 64 | explanation: "Pragma is the keyword that you use to ask the compiler to check whether its version of Solidity matches the one required." 65 | - content: "A contract definition" 66 | isCorrect: false 67 | explanation: "The contract definition is required as part of the source file, but it is not the first line." 68 | - content: "A solidity version" 69 | isCorrect: false 70 | explanation: "A solidity version is part of the pragma directive, but does not include the keyword for the compiler to check." 71 | - content: "An event" 72 | isCorrect: false 73 | explanation: "Events are typically part of ever smart contract, but are not required, and exist inside the contract definition." -------------------------------------------------------------------------------- /solidity/includes/1-introduction.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | The first major use case for blockchain technology has been centered around cryptocurrencies, like Bitcoin and Ethereum. But what about when you want to use blockchain to transfer some digital asset other than currency? Suppose you use a supply chain which handles the transportation and delivery of goods. Or you have an online marketplace and want to use blockchain technology to help facilitate the buying, selling, and transferring of products. 4 | 5 | In that case, you can use a programming language called [Solidity](https://solidity.readthedocs.io/) to code how your supply chain, online marketplace, or other use case operates and what actions participants can take. By programming these actions allowed on the network, you can create your own blockchains that are secure and transparent for all participants involved. 6 | 7 | In this module, you will have explore the fundamentals of the Solidity language, and learn how to program smart contracts along the way. 8 | 9 | ## Learning objectives 10 | 11 | By the end of this module, you will be able to: 12 | 13 | - Explain what Solidity is and how the features of the language work 14 | - Understand the components of a smart contract 15 | - Create a basic smart contract with Solidity 16 | 17 | ## Prerequisites 18 | 19 | - Blockchain fundamentals knowledge 20 | - Ethereum platform knowledge 21 | - Previous experience with any programming language like C, Python, or JavaScript 22 | - Basic knowledge of programming concepts 23 | - Familiarity with the command line to create new directories 24 | -------------------------------------------------------------------------------- /solidity/includes/2-what-is-solidity.md: -------------------------------------------------------------------------------- 1 | # Learn about Solidity 2 | 3 | Solidity is an object-oriented language for writing smart contracts. And smart contracts are code that specify the rules and behavior of how to transfer digital assets. You use Solidity to program smart contracts for the [Ethereum blockchain platform](https://ethereum.org/). Smart contracts contain state and programmable logic. Transactions instantiate smart contracts and execute functions that change state. Therefore, smart contracts enable you to create a business workflow. 4 | 5 | ## An overview 6 | 7 | Solidity is the most popular programming language for the Ethereum blockchain. 8 | 9 | Solidity is a high-level language that is based off of other programming languages before it, including C++, Python, and JavaScript. That means that if you're familiar with any of those languages, looking at Solidity code will feel very familiar. 10 | 11 | Solidity is statically typed, which means that type checking happens at compile-time as opposed to run-time as happens with dynamically typed languages. With a statically typed language, the type of each variable needs to be specified. Python and JavaScript are dynamically-typed languages, whereas C++ is statically typed. 12 | 13 | It supports inheritance so that functions, variables, and other properties from a contract class can be used in another. And it also supports complex user-defined types like structs and enums, which will be covered in a later unit. 14 | 15 | Solidity is an open-source programming language. You can learn more about the project and how to contribute in their [GitHub repository](https://github.com/ethereum/solidity). 16 | 17 | ## What is Ethereum 18 | 19 | Before we go any further, you should also familiarize yourself with Ethereum. 20 | 21 | [Ethereum](https://ethereum.org/) is one of the most popular blockchain platforms out there, right behind Bitcoin. It is a community built technology and has its own cryptocurrency called Ether (ETH) that you can buy and sell. 22 | 23 | What makes Ethereum unique is that it is the "world's programmable blockchain", which means you can code contract definitions, referred to as smart contracts, that are used to describe how blockchain participants transfer digital assets. Solidity is the primary programming language used to develop on the Ethereum platform, and it it built and maintained by Ethereum developers. 24 | 25 | ## The Ethereum Virtual Machine 26 | 27 | Solidity contracts run on the Ethereum Virtual Machine or EVM for short. It is a sandbox environment that is completely isolated so that it does not access anything else on the network besides the contracts it executes. You don't need to know much more about the EVM for now, but just remember that Solidity smart contracts will be deployed to and run in a virtual machine. -------------------------------------------------------------------------------- /solidity/includes/3-language-basics.md: -------------------------------------------------------------------------------- 1 | # Understand the language basics 2 | 3 | All Solidity contracts usually include: 4 | 5 | - Pragma directives 6 | - State Variables 7 | - Functions 8 | - Events 9 | 10 | There is of course, more than that you need to know to program production level smart contracts, but these are the four things that will get you off on the right foot. 11 | 12 | If you have an understanding of these concepts, you can get started writing smart contracts right away! 13 | 14 | ## Pragma directives 15 | 16 | **Pragma** is the keyword that you use to ask the compiler to check whether its version of Solidity matches the one required. If it matches that means your source file can run successfully, if not then the compiler will error. 17 | 18 | You should always make sure to include the latest version of Solidity in your contract definition. To find the current version of Solidity, visit the [Solidity website](https://solidity.readthedocs.io/). Then you can use that version in your source file. 19 | 20 | A version pragma directive looks like: 21 | `pragma solidity ^0.7.0;` 22 | 23 | This line means that the source file will compile with a compiler greater than the version `0.7.0`, up until `0.7.9`. Starting in version `0.8.0` there will likely be breaking changes introduced that the source file cannot compile successfully. 24 | 25 | ## State variables 26 | 27 | State variables are key to any Solidity source file. They are variables whose values are permanently stored in contract storage. 28 | 29 | ```solidity 30 | pragma solidity >0.7.0 <0.8.0; 31 | 32 | contract Marketplace { 33 | uint price; // State variable 34 | ``` 35 | 36 | > [!NOTE] 37 | > Contract source files always start with the definition **contract _ContractName_**. 38 | 39 | In this example, the state variable is named `price` with type **uint**. The integer type uint indicates that this variable is an unsigned integer with 256 bits. That means it can store positive numbers in the range of 0 to 2^256 -1. 40 | 41 | For all variable definitions you must specify the type as well as the variable name. 42 | 43 | Additionally, you can specify the visibility of a state variable as: 44 | 45 | - **public:** part of the contract interface and can be accessed from other contracts 46 | - **internal:** only accessed internally from the current contract 47 | - **private:** only visible for the contract they are defined in 48 | 49 | ## Functions 50 | 51 | Functions are executable units of code within a contract. Functions describe a single action to take to achieve one task. They are reusable and can also be called from other source files like libraries. They behave very similarly to functions in other programming languages. 52 | 53 | A simple example to define a function is this: 54 | 55 | ```solidity 56 | pragma solidity >0.7.0 <0.8.0; 57 | 58 | contract Marketplace { 59 | function buy() public { 60 | // ... 61 | } 62 | } 63 | ``` 64 | 65 | This shows a function with that name `buy` that has a public visibility, meaning that it can be accessed by other contracts. Functions can use one of the following visibility specifiers: **public**, **private**, **internal** and **external**. 66 | 67 | A function can be called internally or externally from another contract. Functions can accept parameters and return variables to pass parameters and values between them. Here is an example of a function that both accepts a parameter, which is an integer called `price` and returns an integer: 68 | 69 | ```solidity 70 | pragma solidity >0.7.0 <0.8.0; 71 | 72 | contract Marketplace { 73 | function buy(uint price) public returns (uint) { 74 | // ... 75 | } 76 | } 77 | ``` 78 | 79 | ### Function modifiers 80 | 81 | Function modifiers can be used to change the behavior of functions. They work by checking a condition before the function executes. For example, checking that only a user designated as a seller can list an item for sale. 82 | 83 | ```solidity 84 | pragma solidity >0.7.0 <0.8.0; 85 | 86 | contract Marketplace { 87 | address public seller; 88 | 89 | modifier onlySeller() { 90 | require( 91 | msg.sender == seller, 92 | "Only seller can put an item up for sale." 93 | ); 94 | _; 95 | } 96 | 97 | function listItem() public view onlySeller { 98 | // ... 99 | } 100 | } 101 | ``` 102 | 103 | This example introduces a couple new things: 104 | 105 | - A variable with a type **address** which will store the 20 byte Ethereum address of the seller user (we will explain this more in a following unit) 106 | - A modifier called `onlySeller` which describes that only a seller can list an item 107 | - A special symbol `_;` to indicate where the function body gets inserted 108 | - A function definition that uses the modifier `onlySeller` 109 | 110 | Additional function modifiers that can be used in the function definition are: 111 | 112 | - **pure** to describe functions that don't allow modifications or access of state 113 | - **view** to describe functions that don't allow modifications of state 114 | - **payable** to describe functions that can receive Ether 115 | 116 | ## Events 117 | 118 | Events describe actions that are taken in the contract. Events have parameters like functions do that need to be specified when the event is called. 119 | 120 | To call an event, you must use the keyword **emit** with the event name and it's parameters. 121 | 122 | ```solidity 123 | pragma solidity >0.7.0 <0.8.0; 124 | 125 | contract Marketplace { 126 | event PurchasedItem(address buyer, uint price); 127 | 128 | function buy() public { 129 | // ... 130 | emit PurchasedItem(msg.sender, msg.value); 131 | } 132 | } 133 | ``` 134 | 135 | When you call an event, the event is captured as a transaction in the transaction log, which is a special data structure in the blockchain. These logs are associated with the address of the contract, are incorporated into the blockchain, and stay there forever. The log and its event data is not accessible from within contracts, and cannot be modified. 136 | -------------------------------------------------------------------------------- /solidity/includes/4-value-types.md: -------------------------------------------------------------------------------- 1 | # Value Types 2 | 3 | In this unit you'll learn about the main value types in Solidity. They are called value types because they will always be passed by value, which means they are copied when they are used. This unit covers the primary value types that you will be exposed to when writing contracts. 4 | 5 | ## Integers 6 | 7 | Integers are used in every Solidity source file. They represent whole numbers and can either be signed or unsigned and range from 8 up to 256 bits that they can store. 8 | 9 | - Signed: Include negative and positive numbers. Can represent as **int** 10 | - Unsigned: Includes positive numbers only. Can represent as **uint** 11 | 12 | If a number of bits is not specified, the default value is 256 bits. 13 | 14 | The following operations can be applied to integers: 15 | 16 | - Comparisons: `<=`, `<`, `==`, `!=`, `>=`, `>` 17 | - Bit operators: `& (and)`, `| (or)`, `^ (bitwise exclusive)`, `~ (bitwise negation)` 18 | - Arithmetic operators" `+ (addition)`,`- (subtraction)`, `* (multiplication)`, `/ (division)`, `% (modulo)`, `** (exponential)` 19 | 20 | Here are some examples of integer definitions: 21 | 22 | ```solidity 23 | int32 price = 25; // signed 32 bit integer 24 | int256 balance = 1000; // signed 256 bit integer 25 | 26 | balance - price; // 975 27 | 2 * price; // 50 28 | price % 2; // 0 29 | ``` 30 | 31 | ## Booleans 32 | 33 | Booleans are defined using the keyword **bool** and always have the values `true` or `false`. 34 | 35 | They can be defined as: 36 | 37 | ```solidity 38 | bool forSale; //true if an item is for sale 39 | bool purchased; //true if an item has been purchased 40 | ``` 41 | 42 | Booleans are commonly used in comparison statements. For example: 43 | 44 | ```solidity 45 | if(balance > 0 & balance > price) { 46 | return true; 47 | } 48 | 49 | if(price > balance) { 50 | return false; 51 | } 52 | ``` 53 | 54 | And booleans can also be used in function parameters and return types. 55 | 56 | ```solidity 57 | function buy(int price) returns (bool success) { 58 | // ... 59 | } 60 | ``` 61 | 62 | ## String literals 63 | 64 | String literals are also used in most contract files. They are characters or words surrounded by either double or single-quotes. 65 | 66 | ```solidity 67 | String shipped = "shipped"; // shipped 68 | String delivered = 'delivered'; // delivered 69 | String newItem = "new" "Item"; // newItem 70 | ``` 71 | 72 | Additionally, the following escape characters can be used with string literals: 73 | 74 | - `\ escapes a new line 75 | - `\n` new line 76 | - `\r` carriage return 77 | - `\t` tab 78 | 79 | ## Address 80 | 81 | An address is a type with a 20 byte value that represents an Ethereum user account. This type can either be a regular **address** or an **address payable**. 82 | 83 | The difference between the two is that an **address payable** type is an address that you can send Ether to, and it contains the additional members `transfer` and `send`. 84 | 85 | ```solidity 86 | address payable public seller; // account for the seller 87 | address payable public buyer; // account for the user 88 | 89 | function transfer(address buyer, uint price) { 90 | buyer.transfer(price); // the transfer member transfers the price of the item 91 | } 92 | ``` 93 | 94 | ## Enums 95 | 96 | Enums allow you to create a user-defined type in Solidity. It's called user-defined, because the person creating the contract decides the values to include. They present a number of choices that can be selected and require at least one selection. 97 | 98 | An example of an **enum** is having different statuses for an item. You can think of these as representing multiple choice answers, where all the values are pre-defined and you have to select one. Enums can be declared in contract or library definitions. 99 | 100 | ```solidity 101 | enum StateType { 102 | ItemAvailable, 103 | ItemBought 104 | } 105 | 106 | StateType public State; 107 | 108 | constructor() public { 109 | State = StateType.ItemAvailable; 110 | } 111 | ``` 112 | 113 | ```solidity 114 | enum Status { Pending, Shipped, Delivered } 115 | Status public status; 116 | 117 | constructor() public { 118 | status = Status.Pending; 119 | } 120 | } 121 | ``` 122 | -------------------------------------------------------------------------------- /solidity/includes/5-reference-types.md: -------------------------------------------------------------------------------- 1 | # Reference types 2 | 3 | Another common type you'll deal with when writing contracts are reference types. Values of reference types can be modified through multiple different names. 4 | 5 | While value types are alway pass an independent copy of the value, reference types provide a data location to the value. The three reference types are: **structs**, **arrays**, and **mappings**. 6 | 7 | When using a reference type, you must explicitly provide the data area where the type is stored in a data location. 8 | 9 | ## Data location 10 | 11 | Every reference type specifies a data location to where the data is stored. The three options for specifying the data area where the type is stored are: 12 | 13 | - **memory:** 14 | - The location where contains function arguments are stored 15 | - Has a lifetime limited to external function call 16 | - **storage:** 17 | - The location where state variables are stored 18 | - Has a lifetime limited to the contract lifetime 19 | - **calldata:** 20 | - The location where contains function arguments are stored 21 | - It is required for parameters of external functions but can also be used for other variables 22 | - Has a lifetime limited to external function call 23 | 24 | The reference type always create an independent copy of the data. 25 | 26 | Example: 27 | 28 | ```solidity 29 | contract C { 30 | 31 | uint[] x; 32 | // the data location of values is memory 33 | function buy(unit[] memory values) public { 34 | x = value; // copies array to storage 35 | uint[] storage y = x; //data location of y is storage 36 | g(x); // calls g, handing over reference to x 37 | h(x); // calls h, and creates a temporary copy in memory 38 | } 39 | 40 | function g(uint[] storage) internal pure {} 41 | function h(uint[] memory) public pure {} 42 | } 43 | ``` 44 | 45 | ## Arrays 46 | 47 | Arrays are a way to store similar data in a set data structure. They can either have a fixed or dynamic size. Their indices start at 0. 48 | 49 | The type of an array of fixed size `k` and element type `T` is written as `T[k]`, and an array of dynamic size as `T[]`. 50 | 51 | Array elements can be of any type like **uint**, **memory**, or **bytes**, and can also include **mappings** or **structs**. 52 | 53 | Examples: 54 | 55 | ```solidity 56 | uint[] itemIds; // Declare a dynamic sized array called itemIds 57 | uint[3] prices = [1, 2, 3]; // initialize a fixed size array called prices, with prices 1, 2, and 3 58 | uint[] prices = [1, 2, 3]; // same as above 59 | ``` 60 | 61 | ### Array members 62 | 63 | The following members are available to get information about and manipulate arrays: 64 | 65 | - **length**: Get the length of an array 66 | - **push()**: Append an element at the end of the array 67 | - **pop**: Remove an element from the end of an array 68 | 69 | Examples: 70 | 71 | ```solidity 72 | // Create a dynamic byte array 73 | bytes32[] itemNames; 74 | itemNames.push(bytes32("computer")); // adds "computer" to the array 75 | itemNames.length; // 1 76 | ``` 77 | 78 | ## Structs 79 | 80 | Structs are custom types that a user can define to represent real world objects. These are typically used as schema or represent records. 81 | 82 | Examples: 83 | 84 | ```solidity 85 | 86 | struct Items_Schema { 87 | uint256 _id: 88 | uint256 _price: 89 | string _name; 90 | string _description; 91 | } 92 | ``` 93 | 94 | ## Mapping types 95 | 96 | Mappings are key value pairs that are encapsulated, or packaged together. These are closest to dictionaries or Objects in JavaScript. We typically use mappings to model real-world objects and do faster lookups of data. The values could take on various types, including complex types like structs, making this type flexible and human readable to work with. 97 | 98 | Here is a code example that uses the struct Items_Schema and saves a list of items represented by the Items_Schema as a dictionary. This somewhat mimics a database. 99 | 100 | Notice the mapping signature `uint256 => Items_Schema`. This indicates that the keys are of type unsigned integer and the values are Items_Schema struct. 101 | 102 | ```solidity 103 | contract Items { 104 | uint256 item_id = 0; 105 | 106 | mapping(uint256 => Items_Schema) public items; 107 | 108 | struct Items_Schema { 109 | uint256 _id: 110 | uint256 _price: 111 | string _name; 112 | } 113 | 114 | function listItem(uint 256 memory _price, string memory _name) public { 115 | item_id += 1; 116 | item[vehicle_id] = Items_Schema(item_id, _price, _name); 117 | } 118 | } 119 | ``` 120 | -------------------------------------------------------------------------------- /solidity/includes/6-write-your-first-contract.md: -------------------------------------------------------------------------------- 1 | # Write your first contract 2 | 3 | Now let's put together what we've learned into a complete smart contract example. 4 | 5 | In this example, we have a marketplace. So far, you can list an item for sale and you can buy an item. The two roles involved are a seller and a buyer. 6 | 7 | ## Simple Marketplace example 8 | 9 | ```solidity 10 | pragma solidity >0.7.0 <0.8.0; 11 | 12 | contract Marketplace { 13 | address public seller; 14 | address public buyer; 15 | mapping (address => uint) public balances; 16 | 17 | event ListItem(address seller, uint price); 18 | event PurchasedItem(address seller, address buyer, uint price); 19 | 20 | enum StateType { 21 | ItemAvailable, 22 | ItemPurchased 23 | } 24 | 25 | StateType public State; 26 | 27 | constructor() public { 28 | seller = msg.sender; 29 | State = StateType.ItemAvailable; 30 | } 31 | 32 | function buy(address seller, address buyer, uint price) public { 33 | require(price <= balances[buyer], "Insufficient balance"); 34 | State = StateType.ItemPurchased; 35 | balances[buyer] -= price; 36 | balances[seller] += price; 37 | 38 | emit PurchasedItem(msg.seller, buyer, msg.value); 39 | } 40 | ``` 41 | 42 | Let's dig into the main components of this smart contract: 43 | 44 | - There are 3 state variables: buyer, seller, and balances 45 | - There are 2 events: `ListItem` and `PurchasedItem` 46 | - There is an enum with 2 values: `ItemAvailable` and `ItemPurchased` 47 | - The constructor will assign the seller user as msg.sender, and set the initial state to ItemAvailable. This constructor is called when the contract is created. 48 | - The `buy` function takes 3 parameters: `seller`, `buyer`, and `price`. It has a requirement that the buyer has enough money for the purchase. Then it transfers money from the buyer to the seller, and finally a message is emitted. 49 | 50 | ## Challenge 51 | 52 | Go to [Remix IDE](https://remix.ethereum.org/) to explore more smart contract examples in Solidity. Remix is an in-browser IDE that is instant to get started without having to create an account or sign in. You can immediately write, test, compile, and deploy contracts. 53 | 54 | I encourage you to explore the pre-built contracts available in Remix and then to copy this smart contract over in a new file named `Marketplace.sol`. 55 | -------------------------------------------------------------------------------- /solidity/includes/7-knowledge-check.md: -------------------------------------------------------------------------------- 1 | # Knowledge check 2 | 3 | - Solidity smart contracts are run on: 4 | 5 | - Ethereum blockchain // incorrect. this is the name of the platform Solidity targets, but not what test are run on 6 | - The Ethereum virtual machine // correct. Solidity runs contracts on what's called the Ethereum virtual machine which is a sandboxed environment to self-contain all the transaction history for the contracts. 7 | - A virtual machine // incorrect. a virtual machine is an option to run tests in, but a specific kind of virtual machine is used for Solidity smart contracts. 8 | - A sandbox environment // incorrect. The Ethereum virtual machine is a sandboxed and isolated environment, but that is just a feature of the virtual machine, and not the main focus. 9 | 10 | - Events in contracts describe actions that are taken in the contract. What is the correct syntax to define an event? 11 | - event PurchasedItem; //incorrect. the event must be called like a function with a set of parenthesis at the end like `event PurchasedItem()` and include any arguments inside of the parenthesis. 12 | - event PurchasedItem(address buyer, uint price); //correct. to define an event you used the keyword `event` and then give the event a name and describe which arguments, if any, must be included inside parenthesis. 13 | - emit PurchasedItem(address buyer, uint price); //incorrect. this is the syntax to call the event and create an entry in the transactions log. 14 | - PurchasedItem(address buyer, uint price); //incorrect. this would be the syntax to call a function that's previously been defined, not an event. 15 | 16 | - What is an example of a user-defined type in Solidity? 17 | 18 | - Structs // correct. Structs are user-defined because you can define the collection of items within a struct. 19 | - State variables // incorrect. State variables use defined types like uint, int, bool, and addresses to hold values that are used in contracts. 20 | - Addresses // incorrect. Addresses are 20 byte value types that represent an Ethereum user account. A value is specified for a given address type. 21 | - Arrays //incorrect. Arrays use defined types to store a collection of similar items of same type in a data structure. 22 | 23 | - What is typically the first line of a smart contract source file? 24 | 25 | - A contract definition // incorrect. The contract definition is required as part of the source file, but it is not the first line. 26 | - A pragma directive // correct. Pragma is the keyword that you use to ask the compiler to check whether its version of Solidity matches the one required. 27 | - A solidity version // incorrect. A solidity version is part of the pragma directive, but does not include the keyword for the compiler to check. 28 | - An event // incorrect. Events are typically part of ever smart contract, but are not required, and exist inside the contract definition. 29 | -------------------------------------------------------------------------------- /solidity/includes/8-summary.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | In this module, you learned how to use Solidity to get started writing your own smart contracts. You should have a better understanding of the language components needed and types available. 4 | 5 | ## Resources 6 | 7 | For continued learning, you can refer to: 8 | 9 | - [Solidity website](https://solidity.readthedocs.io/) 10 | - [Solidity GitHub](https://github.com/ethereum/solidity) 11 | 12 | ## Complete the course 13 | 14 | Take a survey and let us know who you liked this module. Then you can continue learning about blockchain development for Ethereum in the next module. 15 | -------------------------------------------------------------------------------- /solidity/index.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:Module 2 | uid: "" 3 | metadata: 4 | title: Learn how to use Solidity 5 | description: Discover how Solidity can make it easy to program smart contracts for the Ethereum blockchain platform. 6 | ms.date: 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Learn how to use Solidity 12 | summary: Discover how Solidity can make it easy to program smart contracts for the Ethereum blockchain platform. 13 | abstract: | 14 | In this module you will learn how to: 15 | - Explain what Solidity is and how the features of the language work 16 | - Understand the components of a smart contract 17 | - Create a basic smart contract with Solidity 18 | prerequisites: | 19 | - Blockchain fundamentals knowledge 20 | - Ethereum platform knowledge 21 | - Previous experience with any programming language like C, Python, or JavaScript 22 | - Basic knowledge of programming concepts 23 | - Familiarity with the command line to create new directories 24 | iconUrl: /learn/achievements/generic-badge.svg # TODO change 25 | levels: 26 | - beginner 27 | roles: 28 | - developer 29 | - student 30 | products: 31 | - azure 32 | units: 33 | - "" 34 | badge: 35 | uid: "" 36 | -------------------------------------------------------------------------------- /tokens/1-introduction.yml: -------------------------------------------------------------------------------- 1 | uid: learn.reactors.blockchain-tokens.1-introduction 2 | metadata: 3 | title: Introduction 4 | description: Introduction to blockchain tokens. 5 | ms.date: 10/16/2020 6 | author: meaghanlewis 7 | ms.author: shanama 8 | ms.topic: interactive-tutorial 9 | ms.prod: learning-azure 10 | title: Introduction 11 | durationInMinutes: 1 12 | content: | 13 | [!include[](includes/1-introduction.md)] -------------------------------------------------------------------------------- /tokens/2-what-are-tokens.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: learn.reactors.blockchain-tokens.2-what-are-tokens 3 | metadata: 4 | title: What is a token? 5 | description: Learn about blockchain tokens 6 | ms.date: 10/16/2020 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: What is a token? 12 | durationInMinutes: 4 13 | content: | 14 | [!include[](includes/2-what-are-tokens.md)] -------------------------------------------------------------------------------- /tokens/3-token-types.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: learn.reactors.blockchain-tokens.3-token-types 3 | metadata: 4 | title: Learn about contract standards 5 | description: Learn about the four primary token standards. 6 | ms.date: 10/16/2020 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Learn about contract standards 12 | durationInMinutes: 4 13 | content: | 14 | [!include[](includes/3-token-types.md)] -------------------------------------------------------------------------------- /tokens/4-open-zeppelin.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: learn.reactors.blockchain-tokens.4-learn-open-zeppelin 3 | metadata: 4 | title: Learn about OpenZeppelin 5 | description: Understand what OpenZeppelin is and what services is provides. 6 | ms.date: 10/16/2020 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Learn about OpenZeppelin 12 | durationInMinutes: 4 13 | content: | 14 | [!include[](includes/4-learn-open-zeppelin.md)] -------------------------------------------------------------------------------- /tokens/5-setup-project.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: learn.reactors.blockchain-tokens.5-setup-project 3 | metadata: 4 | title: Setup a new project and integrate OpenZeppelin 5 | description: Create a new project with Truffle and integrate the OpenZeppelin conracts library 6 | ms.date: 10/16/2020 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Learn about OpenZeppelin 12 | durationInMinutes: 8 13 | content: | 14 | [!include[](includes/5-setup-project.md)] -------------------------------------------------------------------------------- /tokens/6-write-token-contract.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: learn.reactors.blockchain-tokens.6-write-token-project 3 | metadata: 4 | title: Write an ERC20 token contract 5 | description: Add a new token smart contract to the Truffle project. 6 | ms.date: 10/16/2020 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Learn about OpenZeppelin 12 | durationInMinutes: 8 13 | content: | 14 | [!include[](includes/6-write-token-project.md)] -------------------------------------------------------------------------------- /tokens/7-knowledge-check.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: learn.reactors.blockchain-tokens.8-knowledge-check 3 | metadata: 4 | title: Knowledge check 5 | description: Knowledge check 6 | ms.date: 10/16/2020 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Knowledge check 12 | durationInMinutes: 1 13 | content: | 14 | quiz: 15 | questions: 16 | - content: "What is the most complete definition of blockchain tokens?" 17 | choices: 18 | - content: "They represent currency that can be tradable." 19 | isCorrect: false 20 | explanation: "Tokens are tradable but often represent much more than currency. They can also represent ownership, access, or be traded for a service in return." 21 | - content: "They represent digital assets that have some value and are tradable." 22 | isCorrect: true 23 | explanation: "Correct. Tokens have some value and represent either virtual or real-world, tangible objects." 24 | - content: "They are physical tokens that can be used to trade on a blockchain network." 25 | isCorrect: false 26 | explanation: "Tokens are digital, however they can represent virtual or physical objects." 27 | - content: "They are unique assets that identify ownership." 28 | isCorrect: false 29 | explanation: "While tokens can identify ownership, say in the example of property, tokens can also represent many other digital objects." 30 | 31 | - content: "What type of token is most commonly used solely for nun-fungible assets?" 32 | choices: 33 | - content: "ERC20." 34 | isCorrect: false 35 | explanation: "This type of token is used for fungible assets." 36 | - content: "ERC777." 37 | isCorrect: false 38 | explanation: "This type of token is for fungible assets." 39 | - content: "ERC1155." 40 | isCorrect: false 41 | explanation: "This type of token is for both fungible and non-fungible assets." 42 | - content: "ERC721." 43 | isCorrect: true 44 | explanation: "Correct. This type of token is solely for non-fungible assets." 45 | 46 | - content: "What modular and reusable tool does OpenZeppelin provide to make it easier to write secure contracts?" 47 | choices: 48 | - content: "CLI." 49 | isCorrect: false 50 | explanation: "The CLI, often referred to as the SDK, is used to develop, deploy, and manage smart contract projects." 51 | - content: "SDK." 52 | isCorrect: false 53 | explanation: "The SDK, is used to develop, deploy, and manage smart contract projects." 54 | - content: "Contracts." 55 | isCorrect: true 56 | explanation: "Correct. The contracts library provides a set of modular and reusable contracts to integrate into new and existing blockchain projects." 57 | - content: "Test helpers." 58 | isCorrect: false 59 | explanation: "The test helpers is an assertion library for Ethereum smart contract testing." 60 | -------------------------------------------------------------------------------- /tokens/8-summary.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:ModuleUnit 2 | uid: learn.reactors.blockchain-tokens.9-summary 3 | metadata: 4 | title: Summary 5 | description: Summary 6 | ms.date: 10/16/2020 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Summary 12 | durationInMinutes: 1 13 | content: | 14 | [!include[](includes/8-summary.md)] -------------------------------------------------------------------------------- /tokens/includes/1-introduction.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | A digital asset, whether it be Bitcoin, or Ether, or any other cryptocurrency, represents an amount of value. Another example of a digital asset that represents value is a token. However with tokens, the value might not always be monetary, but can represent things like time, services, property, or goods that are tradeable with others. 4 | 5 | In this module, you will learn about the significance of tokens, and how they are used in blockchain. 6 | 7 | ## Learning objectives 8 | 9 | By the end of this module, you will be able to: 10 | 11 | - Explain what tokens are 12 | - Identify the primary types of token standards 13 | - Learn about the contract library OpenZeppelin 14 | - Create a token smart contract 15 | 16 | ## Prerequisites 17 | 18 | - Blockchain fundamentals knowledge 19 | - Ethereum platform knowledge 20 | - Solidity programming knowledge 21 | - Previous experience with any programming language like C, Python, or JavaScript 22 | - Basic knowledge of programming concepts 23 | - Familiarity with the command line to create new directories and install programs 24 | - Node.js installed 25 | - Truffle and Ganache CLI installed 26 | - Visual Studio Code installed 27 | -------------------------------------------------------------------------------- /tokens/includes/2-what-are-tokens.md: -------------------------------------------------------------------------------- 1 | # Learn about tokens 2 | 3 | The token is one of blockchain's most powerful and often most misunderstood tools. It's typically misunderstood, because a blockchain token can represent almost anything that we want to assign a value to whether that's something virtual or a real-world, tangible object. 4 | 5 | A token can grant users special permissions on a platform, exclusive access to a service, or show ownership. Tokens could also represent cryptocurrencies with monetary value. Let's dive into the history of tokens and explore various use cases to demonstrate what exactly a token is and what you can do with them. 6 | 7 | ## History of tokens 8 | 9 | Tokens are not a new thing and have existed since long before the emergence of blockchain. 10 | 11 | Tokens have represented any form of economic value. Shells and beads were probably the earliest types of tokens used to trade goods with. Present-day types of tokens include casinos chips, vouchers, airline points, stock certificates, concert entry tokens, dinner reservations, ID cards, or club memberships. Really, the list of possible token uses can go on and on somewhat endlessly. 12 | 13 | Even our typical fiat currency, which includes cash and coins, is a type of token. The point is, you can build up tokens and trade them in to get something of value or some service in return. 14 | 15 | In computing, tokens are used to allow a right to perform some operation or manage access rights. 16 | 17 | A web browser, for example, sends tokens to websites when we surf the internet that contain information about our computers, like the browser and IP address. Another examples of computer tokens are QR codes. QR codes are scanned and then redirect us to a web page or some service. 18 | 19 | ## Blockchain tokens 20 | 21 | Blockchain tokens combine concepts of more general tokens: ownership rights to some property, service access, or monetary value. This property or service can be public, like an Ethereum network that anyone can join and participate in. Or the property or service can be private, like a house that is purchased by an owner, or points on your account that you trade in to purchase items. 22 | 23 | Blockchain tokens represent a set of rules which are programmed in a smart contract. Every token belongs to a blockchain address which identifies it uniquely. These tokens are accessible with a [crypto wallet](https://ethereum.org/en/wallets/) so that only the person who has the private key for that address can access those tokens. 24 | 25 | The Ethereum blockchain platform is based on the use of tokens, which can be bought, sold, and traded. Tokens are like Ether (ETH) but may have different design decisions, purposes and help operate different decentralized apps (DAPPS) and facilitate crypto-economics of different Blockchain ecosystems. 26 | 27 | Take for example, Augur. [Augur](https://www.augur.net/) is a network that functions as a prediction market - you can think of it as a betting platform. Augur has its own token named REP. This is no different than you using tokens perhaps to take public transport. We have fiat or local currency, for example the Canadian dollar (CAD), which sometimes also comes in coins, and also Toronto Transit Commission (TTC) tokens. Each TTC token allows you to take 1 subway ride. You can purchase TTC tokens using CAD (just like you can purchase REP using ETH) but they are not the same thing. TTC tokens are specifically for the ecosystem of Toronto Transit, and the REP tokens are for the Augur ecosystem. 28 | 29 | ## Two categories of blockchain tokens 30 | 31 | There are different kinds of tokens available and they usually fall into two categories: 32 | 33 | - **fungible:** 34 | - equivalent 35 | - exchangeable 36 | - It matters how much you have 37 | - **non-fungible** 38 | - unique 39 | - distinct 40 | - It matters which ones you have 41 | 42 | When you break it down, blockchain tokens are essentially smart contracts that make use of the Ethereum blockchain. Everything in Ethereum can be represented as a smart contract, and there are no rules restricting what smart contracts do, so the community has developed standards to document how a token contract can operate with other contracts. The standards also describe the implementation details of each token type. 43 | -------------------------------------------------------------------------------- /tokens/includes/3-token-types.md: -------------------------------------------------------------------------------- 1 | # Explore token standards 2 | 3 | [Ethereum Improvement Proposals](https://eips.ethereum.org/) (EIPs) describe standards for the Ethereum platform, including core protocol specifications, client APIs, and contract standards. What this means is that community members can make proposals of new standards for every part of the platform. 4 | 5 | Token standards in particular are defined in what's called [Ethereum Request for Comments](https://eips.ethereum.org/erc) or ERC for short. While new standards are continuously being proposed and accepted, there are primary ERC types that have been adopted widely. 6 | 7 | Those four token standards are: 8 | 9 | - **ERC20** 10 | - **ERC721** 11 | - **ERC777** 12 | - **ERC1155** 13 | 14 | Let's explore each type of token, taking a moment to understand what makes each one significant and unique. 15 | 16 | ## ERC20 17 | 18 | The most widely known and used token is the [ERC20](https://eips.ethereum.org/EIPS/eip-20). ERC20 is the technical standard used for smart contracts on the Ethereum blockchain for token implementation. It has a simple interface for basic tokens. 19 | 20 | An ERC20 token contract keeps track of fungible tokens: any one token is exactly equal to any other token; no tokens have special rights or behavior associated with them. This makes ERC20 tokens useful for things like: currency exchange, voting rights, or staking. 21 | 22 | ## ERC721 23 | 24 | [ERC721](https://eips.ethereum.org/EIPS/eip-721) is the top solution for non-fungible tokens, often referred to as NFTs for short. Like all other tokens, NFTs represent ownership of both virtual and physical assets. These assets might likely include the following: 25 | 26 | - Collectible items like antiques, cards, or art 27 | - Physical assets like houses or cars 28 | - Negative value assets like loans 29 | 30 | Each token is unique and has ownership and status which must be tracked. 31 | 32 | The ERC721 token is a more complex standard than ERC20. Where the core functions have some similarities, each one has function arguments that specify the token ID. 33 | 34 | ## ERC777 35 | 36 | [ERC777](https://eips.ethereum.org/EIPS/eip-777) is a richer standard for fungible tokens, enabling new use cases and building on learnings from previous token standards. It is backwards compatible with ERC20, which means that you can interact with these tokens as if they were ERC20. ERC777 allows more complex interactions when trading tokens. 37 | 38 | ## ERC1155 39 | 40 | [ERC1155](https://eips.ethereum.org/EIPS/eip-1155) is a standard for managing multi-token types, allowing for a single contract to represent multiple fungible and non-fungible tokens. 41 | 42 | ERC1155 draws on ideas from ERC20, ERC721, and ERC777. 43 | 44 | The design of this token type allow for massive gas savings for a couple different reasons. First, because you can use this token contract for multiple tokens, this means less deployments with less complexity. It also has batched operations which means a single function call can be simpler and less gas-intensive. 45 | -------------------------------------------------------------------------------- /tokens/includes/4-learn-open-zeppelin.md: -------------------------------------------------------------------------------- 1 | # Learn about OpenZeppelin 2 | 3 | ## What is it 4 | 5 | [OpenZeppelin](https://openzeppelin.com/) provides tools to write, deploy and manage decentralized applications. It is an open-source tool that provides reliability and security with the products it provides. 6 | 7 | There are two different products that OpenZeppelin provides- the contracts library and the SDK. 8 | 9 | :::image type="content" source="../media/open-zeppelin.png" alt-text="Visit OpenZeppelin to find out about the two products it provides."::: 10 | 11 | ## Contracts 12 | 13 | With the [contracts library](https://openzeppelin.com/contracts), you can access a robust set of modular and reusable smart contracts for the Ethereum network, written in Solidity. The benefits of using these contracts is that they have been thoroughly tested, audited and community reviewed. 14 | 15 | OpenZeppelin is the most popular library source in the industry for smart contracts, and it’s open-sourced. Using these contracts will allow you to learn the best practices for developing smart contracts. There are a variety of contract types available such as: 16 | 17 | - **Access Control**: decide who can perform actions 18 | - **Tokens**: create tradable assets 19 | - **Gas station Network**: let your users use contracts without having to pay for the gas 20 | - **Utilities**: generic useful tools 21 | 22 | While we will only be using the token contracts in this module, it's good to be aware of the other contract resources available. 23 | 24 | ## SDK 25 | 26 | The other product that OpenZeppelin provides is the [SDK](https://openzeppelin.com/sdk/), which makes it easier to manage smart contract development with the command line interface (CLI). You can save hours of development time by using the CLI to compile, upgrade, and deploy smart contracts. The CLI provides support for Ethereum and other Ethereum Virtual Machine powered blockchains. The commands are intuitive and interactive to help guide you along the development process. 27 | 28 | For this module, we will not be using the SDK, however this is a tool you can consider exploring on your own and using for future blockchain development. 29 | -------------------------------------------------------------------------------- /tokens/includes/5-setup-project.md: -------------------------------------------------------------------------------- 1 | # Exercise: Setup a new project and integrate OpenZeppelin 2 | 3 | Now let’s look at how to incorporate an ERC20 token in our contracts. 4 | 5 | ## Create a new project 6 | 7 | First, we're going to create a new blockchain project with the help of OpenZeppelin. 8 | 9 | Make sure that you already have [Truffle](https://www.trufflesuite.com/truffle) and [Ganache CLI](https://github.com/trufflesuite/ganache-cli) installed. 10 | 11 | 1. Open your terminal and create a new folder called **Token20**. To do that you can type: `mkdir Token20`. I typically do this inside a folder called **Projects** where I store all my other development projects. 12 | 1. Navigate to the Token20 folder. To do that you can type: `cd Token20`. 13 | 1. Type `truffle init` to initialize a new project 14 | 1. Wait for your project to be initialized, and then open it in Visual Studio Code. 15 | 16 | You should see the following after initializing the project with Truffle. 17 | 18 | ```output 19 | $ mkdir Token20 20 | $ cd Token20/ 21 | $ truffle init 22 | ✔ Preparing to download box 23 | ✔ Downloading 24 | ✔ cleaning up temporary files 25 | ✔ Setting up box 26 | $ ls 27 | contracts migrations test truffle-config.js 28 | ``` 29 | 30 | ## Setup the project 31 | 32 | Once the project has been created and opened in the editor, take a look around the contents. 33 | 34 | Next, you'll want to confirm that you have Node.js installed. If you don't, you can visit the [Node](https://nodejs.org/) website for instructions about how to download it for your platform. To confirm that you have Node.js installed, open the terminal and type: `node`. This will return the version that you have installed on your machine. 35 | 36 | Node.js comes with the node package manager (npm) installed as well. This will help you manage other JavaScript built packages and applications. 37 | 38 | Going to your terminal, type: 39 | `npm init` 40 | 41 | That will open a utility that walks you through the process to create a package.json file which describes the project and stores dependencies that are used in the project. Follow the steps in the utility to easily create a package.json, noting that you can press enter at each prompt to use the default value. 42 | 43 | ## Setup OpenZeppelin 44 | 45 | :::image type="content" source="../media/contract-library.png" alt-text="Visit OpenZeppelin to find out how to install the contracts library"::: 46 | 47 | Now we want to integrate with the OpenZeppelin contracts library. 48 | 49 | To do that go to the terminal window and type: 50 | `npm install @openzeppelin/contracts` 51 | 52 | Wait for the package to install to your project successfully. You should see the following in your terminal window: 53 | 54 | ```output 55 | + @openzeppelin/contracts@3.2.0 56 | added 1 package from 1 contributor and audited 1 package in 0.589s 57 | found 0 vulnerabilities 58 | ``` 59 | 60 | Notice that a couple things happened: 61 | 62 | 1. The package was added as a dependency in the **package.json** file 63 | 1. There is a **node_modules** folder that has imported all of the available contracts from OpenZeppelin under **@openzeppelin/contracts**. 64 | 65 | ```output 66 | $ ls node_modules/@openzeppelin/contracts 67 | GSN build math presets utils 68 | README.md cryptography package.json proxy 69 | access introspection payment token 70 | ``` 71 | 72 | Take some time to look through the available contract source files now available to your project, paying special attention to the **token** contracts. Get a better understanding of the implementation of each contract and which functions are typically made available. 73 | -------------------------------------------------------------------------------- /tokens/includes/6-write-token-contract.md: -------------------------------------------------------------------------------- 1 | # Exercise: Write an ERC20 token contract 2 | 3 | Now, let's add a new token smart contract to the project. 4 | 5 | ## Create the new token contract 6 | 7 | We're going to create a token contract to reward miner's for creating new blocks in the blockchain. 8 | 9 | To begin with open up the **Token20** project in Visual Studio Code. Once open, hover over the contracts folder in the Explorer, right-click and select the New File option. Save the file name as: `ERC20MinerReward.sol`. Copy the contents from below to that contract. 10 | 11 | ```solidity 12 | // SPDX-License-Identifier: MIT 13 | pragma solidity >=0.4.22 <0.8.0; 14 | 15 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 16 | 17 | contract ERC20MinerReward is ERC20 { 18 | 19 | event LogNewAlert(string description, address indexed _from, uint256 _n); 20 | 21 | constructor() public ERC20("MinerReward", "MRW") {} 22 | 23 | function _reward() public { 24 | _mint(block.coinbase, 20); 25 | emit LogNewAlert('_rewarded', block.coinbase, block.number); 26 | } 27 | } 28 | ``` 29 | 30 | ## What this all means 31 | 32 | Now, let's walk through the parts of this contract. 33 | 34 | First, we begin with importing the contract from OpenZeppelin that we want to use on line 3 after the pragma directive. This notation allows the contract to find the ERC20 contract definition we'll use in our own contract. 35 | 36 | Then we define an event called **LogNewAlert** which will be emitted or called later on in the contract. 37 | 38 | The constructor defines the token name as **MinerReward** and the symbol or **MRW**. 39 | 40 | When the reward function is called, the current block's miner **block.coinbase** will receive 20 MRW tokens, and an event gets emitted. 41 | 42 | ## Build the contract 43 | 44 | After saving the contract file, you are now ready to build the contract. To build, we'll be using Ganache CLI and Truffle. 45 | 46 | 1. First, open up the file **truffle-config.js** and search for the line **solc**. 47 | 1. In that section, uncomment the version by removing the `//` and replace the version listed with `0.6.3`. Note, that this is required since the OpenZeppelin contracts specify the pragma directive as **pragma solidity ^0.6.2;**. Then save the file. 48 | 1. Open up a terminal window in VS Code, by going to **Terminal > New Terminal** 49 | 1. Start up Ganache CLI, by typing: `ganche-cli` 50 | 1. Right-click in the terminal window and select **New Terminal** 51 | 1. In that new terminal window, type: `truffle build`. 52 | 53 | You should see the following output in your terminal window 54 | 55 | ```output 56 | $ truffle build 57 | No build configuration found. Preparing to compile contracts. 58 | 59 | Compiling your contracts... 60 | =========================== 61 | > Compiling ./contracts/ERC20MinerReward.sol 62 | > Compiling ./contracts/Migrations.sol 63 | > Compiling @openzeppelin/contracts/GSN/Context.sol 64 | > Compiling @openzeppelin/contracts/math/SafeMath.sol 65 | > Compiling @openzeppelin/contracts/token/ERC20/ERC20.sol 66 | > Compiling @openzeppelin/contracts/token/ERC20/IERC20.sol 67 | > Compiling @openzeppelin/contracts/utils/Address.sol 68 | > Artifacts written to /Users/meaghanlewis/Projects/Token20/build/contracts 69 | > Compiled successfully using: 70 | - solc: 0.6.3+commit.8dda9521.Emscripten.clang 71 | ``` 72 | 73 | Notice that in addition to the contracts defined in the contracts folder, the contracts in @openzeppelin/contracts are also compiled. Make sure that the build completes successfully before you move on. 74 | 75 | ## Wrap up 76 | 77 | This example above is a pretty straightforward implementation of An ERC20 token. You can see how easy it is to write your own token contracts which inherit functions and events from a defined ERC token standard. 78 | 79 | The important thing to remember is that the term “token” is simply a metaphor. It refers to assets and/or access rights that are collectively managed by a network of computers, or a blockchain network. 80 | 81 | Tokens are an important part to incorporate into your blockchain network. 82 | 83 | To get more familiar with tokens, explore the other token contracts available from OpenZeppelin and try out creating your own token contracts. 84 | -------------------------------------------------------------------------------- /tokens/includes/7-knowledge-check.md: -------------------------------------------------------------------------------- 1 | What is the most complete definition of blockchain tokens? 2 | 3 | - They represent digital assets that have some value and are tradable. Correct! 4 | - They represent currency that can be tradable. 5 | - They are physical tokens that can be used to trade on a blockchain network. 6 | - They are unique assets that identify ownership. 7 | 8 | What type of token is most commonly used solely for nun-fungible assets? 9 | 10 | - ERC20 11 | - ERC777 12 | - ERC1155 13 | - ERC721 Correct! 14 | 15 | What modular and reusable tool does OpenZeppelin provide to make it easier to write secure contracts? 16 | 17 | - CLI 18 | - SDK 19 | - Contracts Correct! 20 | - Test helpers 21 | -------------------------------------------------------------------------------- /tokens/includes/8-summary.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | In this module, you learned about what contracts are and how you can write token contracts by using OpenZeppelin. You should now have an understanding of why you would want to use token contracts, and ideas about other types of contracts you can write that use tokens. 4 | 5 | ## Resources 6 | 7 | For continued learning, you can refer to the [OpenZeppelin token documentation](https://docs.openzeppelin.com/contracts/3.x/tokens). There you can find more examples of other contract standards and explore writing more contract tokens on your own. 8 | 9 | ## Complete the course 10 | 11 | Take a survey and let us know who you liked this module. Then you can continue learning about blockchain development for Ethereum in the next module. 12 | -------------------------------------------------------------------------------- /tokens/index.yml: -------------------------------------------------------------------------------- 1 | ### YamlMime:Module 2 | uid: learn.reactors.blockchain-tokens 3 | metadata: 4 | title: Create tokens using OpenZeppelin 5 | description: Learn about the significance of tokens, and how they are used in blockchain. 6 | ms.date: 10/16/2020 7 | author: meaghanlewis 8 | ms.author: shanama 9 | ms.topic: interactive-tutorial 10 | ms.prod: learning-azure 11 | title: Create tokens using OpenZeppelin 12 | summary: Learn about the significance of tokens, and how they are used in blockchain. 13 | abstract: | 14 | By the end of this module, you will be able to: 15 | 16 | - Explain what tokens are 17 | - Identify the different types of tokens 18 | - Learn about the contract library OpenZeppelin 19 | - Create a token smart contract 20 | prerequisites: | 21 | - Blockchain fundamentals knowledge 22 | - Ethereum platform knowledge 23 | - Solidity programming knowledge 24 | - Previous experience with any programming language like C, Python, or JavaScript 25 | - Basic knowledge of programming concepts 26 | - Familiarity with the command line to create new directories and install programs 27 | - Node.js installed 28 | - Truffle and Ganache CLI installed 29 | - Visual Studio Code installed 30 | iconUrl: /learn/achievements/generic-badge.svg # TODO change 31 | levels: 32 | - beginner 33 | roles: 34 | - developer 35 | - student 36 | products: 37 | - azure 38 | units: 39 | - learn.reactors.blockchain-tokens.1-introduction 40 | - learn.reactors.blockchain-tokens.2-what-are-tokens 41 | - learn.reactors.blockchain-tokens.3-token-types 42 | - learn.reactors.blockchain-tokens.4-open-zeppelin 43 | - learn.reactors.blockchain-tokens.5-setup-project 44 | - learn.reactors.blockchain-tokens.6-write-token-contract 45 | - learn.reactors.blockchain-tokens.7-knowledge-check 46 | - learn.reactors.blockchain-tokens.8-summary 47 | badge: 48 | uid: learn.reactors.blockchain-tokens.badge 49 | -------------------------------------------------------------------------------- /tokens/media/contract-library.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/tokens/media/contract-library.png -------------------------------------------------------------------------------- /tokens/media/open-zeppelin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/aed-blockchain-learn-content/fccbe29d7a800adc9f689043b8b5dc8e2debfe60/tokens/media/open-zeppelin.png --------------------------------------------------------------------------------