Ethereum cookbook over 100 recipes covering ethereum based tokens, games, wallets, smart contracts, protocols, and dapps

584 168 0
Ethereum cookbook over 100 recipes covering ethereum based tokens, games, wallets, smart contracts, protocols, and dapps

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Ethereum Cookbook Over 100 recipes covering Ethereum-based tokens, games, wallets, smart contracts, protocols, and Dapps Manoj P R BIRMINGHAM - MUMBAI Ethereum Cookbook Copyright © 2018 Packt Publishing All rights reserved No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews Every effort has been made in the preparation of this book to ensure the accuracy of the information presented However, the information contained in this book is sold without warranty, either express or implied Neither the author(s) nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book Packt Publishing has endeavoured to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals However, Packt Publishing cannot guarantee the accuracy of this information Commissioning Editor: Pravin Dhandre Acquisition Editor: Namrata Patil Content Development Editor: Eisha Dsouza Technical Editor: Ishita Vora Copy Editor: Safis Editing Project Coordinator: Namrata Swetta Proofreader: Safis Editing Indexer: Aishwarya Gangawane Graphics: Jisha Chirayil Production Coordinator: Nilesh M ohite First published: August 2018 Production reference: 1310818 Published by Packt Publishing Ltd Livery Place 35 Livery Street Birmingham B3 2PB, UK ISBN 978-1-78913-399-8 www.packtpub.com To my father – Manoj mapt.io Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career For more information, please visit our website Why subscribe? Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free eBook or video every month Mapt is fully searchable Copy and paste, print, and bookmark content Packt.com Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy Get in touch with us at customercare@packtpub.com for more details At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks Contributors Getting ready Doxity is a documentation generator that is built using JavaScript and is distributed through npm You need to have NodeJS (any recent version) installed on your machine to use this How to it First, install doxity in your system using npm You can either it globally or locally, based on your requirements: // Global installation npm install -g @digix/doxity // Local installation for a project npm install @digix/doxity Once you have installed doxity, you can use it to generate documentation based on the comments provided for each function It is recommended to follow the general comment pattern (natspec) for all functions, which explains each function's definition Consider the following function as an example of proper commenting: /** * @dev Technical explanation * @param Description of param1 * @param Description of param2 */ function functionName( params ) { } Since support for multiple return types has to be implemented, use JSON to specify it for documentation: /** * @dev Function to calculate the sum & difference of two numbers * @param _a First number * @param _b Second number * @return { * "_sum": "Sum of first and second number", * "_difference": "Difference between first and second number", * } */ function calc(uint _a, uint _b) { } To set up a doxity project, use the init command It will clone and initialize a boilerplate for your project: doxity init To generate the documentation for your contract, use the build command It will generate static HTML files and will save them to the docs folder in your project: doxity build If you had to change the code after generating the documentation, use the compile command to update it: doxity compile Doxity also provides a development server for editing the project Run the following command to start it: doxity develop 10 Finally, once you have finished your project, run the publish command to generate deployable documentation You can use the files in the docs folder of your project: doxity publish 11 The final documentation will look something like this It will have different tabs for each contract, and each tab will have all the details of that specific contract: Writing better code with the help of a linter It is very important to follow best practices while writing code This is more important when it comes to smart contracts, specifically solidity, because of the security issues that can arise It is easy for a new smart contract developer to miss minor details To avoid this, it is recommended to use a linter, which verifies your code against best practices This recipe will introduce you to the popular linters used in solidity to help you write better code This can improve the overall readability and security of your smart contracts Getting ready These linters are built using JavaScript and are distributed through npm You need to have NodeJS (any recent version) installed on your machine to step through this recipe How to it Solium is a popular linter used by many to validate their code against best practices Solium is distributed through npm and you can install it using the following command: npm install -g solium Run the following command to verify the installation It will return the details of the currently installed version: solium -V Use the init command to set up your project to support Solium linting: solium init This command will create two files (.soliumignore and soliumrc.json) in the project directory The soliumignore file contains the names of files and directories to ignore while linting and the soliumrc file contains configuration that includes rules, plugins, and shareable configs Once solium is set up, you can start linting your project by specifying a single file or a directory that contains multiple solidity contract files: // Lint a specific file solium -f fileName.sol // Lint files present in the folder solium -d contracts/ Solium also fixes recommendations automatically To this, add a fix flag while linting: solium -d contracts/ fix You can also run Solium in the background in watch mode It will watch the directory for any changes and will print the results immediately: solium watch dir contracts/ While linting, you can specify rules for each line through comments For example, you can instruct Solium to ignore a line/file or to ignore a specific recommendation: // Avoid linting for the next line /* solium-disable-next-line */ // Avoid the whole file /* solium-disable */ For more information about Solium, refer to its official documentation at http://solium.readthedocs io/ Sharing solidity code with others You might be required to share your contract files with someone at some point during development, or during any later phase A well-maintained project will have its own source control repository that can be shared with people There are some tools and services that you can use to quickly share small contract snippets with others quickly In this recipe, you will learn about those services, which will make your life easier while sharing code Getting ready This recipe introduces you to some browser-based tools It is required to have a recent browser (Chrome, Firefox, Edge, and so on) installed in your system to step through this recipe How to it To share/store small snippets of code, you can use gist The process is mostly manual and requires you to copy and paste the code and then share it with someone You can access gist from https://gist.github.com/ The Remix IDE ships with an option to publish your contract files directly to an anonymous public gist Click the publish to Gist option in the top-left panel of the Remix IDE Clicking it will publish all your contract code to a public gist Take extra care while doing this for your confidential files, as it will make everything public You can also use EthFiddle, which is a minimalistic IDE with code sharing features It is targeted at solidity smart contracts and you can access it from https://ethfiddle.com/, as shown in the following screenshot: Once you have the source code in place, you can share the code by clicking the share button on the top panel It will display a link that can be shared with others The tool also comes with a built-in solidity compiler, which can be used to compile your contract Click the Compile button in the top-right panel to so You can enable the autocompile checkbox to compile the contract in real time To change the compiler version, click on the dropdown next to the Compile button Click on the Compiler Errors tab in the bottom panel to check whether your code has any syntax errors Click on the Compiler Output tab to see the output of the successfully compiled code Once the contract compiles successfully, you can deploy the contract by clicking the Deploy button 10 You can change the from address, value, and gas, or proceed with the default values It will deploy the contract to the tool's built-in Ethereum network, as shown in the following screenshot: 11 To interact with the deployed contracts, use the contract panel on the right-hand side of the tool You can use it to read/write from the contract Click the Call button to perform transactions, and you can see the relevant details right below the button, shown as follows: 12 Apart from these features, EthFiddle also stores code shared recently You can access it by clicking the Recent Fiddles button in the bottom panel Other Books You May Enjoy If you enjoyed this book, you may be interested in these other books by Packt: Ethereum Projects for Beginners Kenny Vaneetvelde ISBN: 978-1-78953-740-6 Develop your ideas fast and efficiently using the Ethereum blockchain Make writing and deploying smart contracts easy and manageable Work with private data in blockchain applications Handle large files in blockchain applications Ensure your decentralized applications are safe Explore how Ethereum development frameworks work Create your own cryptocurrency or token on the Ethereum blockchain Make sure your cryptocurrency is ERC20-compliant to launch an ICO Ethereum Smart Contract Development Mayukh Mukhopadhyay ISBN: 978-1-78847-304-0 Know how to build your own smart contracts and cryptocurrencies Understand the Solidity language Find out about data types, control structure, functions, inheritance, mathematical operations, and much more See the various types of forks and discover how they are related to Ethereum Get to know the various concepts of web3.js and its APIs so you can build client-side apps Build a DAO from scratch and acquire basic knowledge of DApps on Ethercast Be guided through the project so you can optimize EVM for smart contracts Build your own decentralized applications (DApps) by taking a practical approach Leave a review - let other readers know what you think Please share your thoughts on this book with others by leaving a review on the site that you bought it from If you purchased the book from Amazon, please leave us an honest review on this book's Amazon page This is vital so that other potential readers can see and use your unbiased opinion to make purchasing decisions, we can understand what our customers think about our products, and our authors can see your feedback on the title that they have worked with Packt to create It will only take a few minutes of your time, but is valuable to other potential customers, our authors, and Packt Thank you! .. .Ethereum Cookbook Over 100 recipes covering Ethereum- based tokens, games, wallets, smart contracts, protocols, and Dapps Manoj P R BIRMINGHAM - MUMBAI Ethereum Cookbook Copyright... up Ethereum and connect to a network, write and deploy quality smart contracts, use Truffle and Ganache to manage your development, create your own Tokens and ICOs, build decentralized games and. .. concepts and knowledge of JavaScript and NodeJS What this book covers , Getting Started, covers the very basics of Ethereum and its tools You will find the steps required to set up and run a

Ngày đăng: 02/03/2020, 13:41

Từ khóa liên quan

Mục lục

  • Title Page

  • Copyright and Credits

    • Ethereum Cookbook

    • Dedication

    • Packt Upsell

      • Why subscribe?

      • Packt.com

      • Contributors

        • About the author

        • About the reviewer

        • Packt is searching for authors like you

        • Preface

          • Who this book is for

          • What this book covers

          • To get the most out of this book

            • Download the example code files

            • Download the color images

            • Conventions used

            • Get in touch

              • Reviews

              • Getting Started

                • Introduction

                • Choosing a client for Ethereum

                  • Getting ready

                  • How to do it...

                    • Geth

                    • Parity

                    • There's more...

                    • Setting up a node and participating in a network

                      • Getting ready

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan