Ethereum Cookbook
eBook - ePub

Ethereum Cookbook

Over 100 recipes covering Ethereum-based tokens, games, wallets, smart contracts, protocols, and Dapps

  1. 404 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Ethereum Cookbook

Over 100 recipes covering Ethereum-based tokens, games, wallets, smart contracts, protocols, and Dapps

About this book

Mine Ether, deploy smart contracts, tokens, and ICOs, and manage security vulnerabilities of Ethereum

Key Features

  • Build end-to-end decentralized Ethereum apps using Truffle, Web3, and Solidity
  • Explore various solution-based recipes to build smart contracts and foolproof decentralized applications
  • Develop decentralized marketplaces from scratch, build wallets, and manage transactions

Book Description

Ethereum and Blockchain will change the way software is built for business transactions. Most industries have been looking to leverage these new technologies to gain efficiencies and create new business models and opportunities.

The Ethereum Cookbook covers various solutions such as setting up Ethereum, writing smart contracts, and creating tokens, among others. You'll learn about the security vulnerabilities, along with other protocols of Ethereum.

Once you have understood the basics, you'll move on to exploring various design decisions and tips to make your application scalable and secure. In addition to this, you'll work with various Ethereum packages such as Truffle, Web3, and Ganache.

By the end of this book, you'll have comprehensively grasped the Ethereum principles and ecosystem.

What you will learn

  • Efficiently write smart contracts in Ethereum
  • Build scalable distributed applications and deploy them
  • Use tools and frameworks to develop, deploy, and test your application
  • Use block explorers such as Etherscan to find a specific transaction
  • Create your own tokens, initial coin offerings (ICOs), and games
  • Understand various security flaws in smart contracts in order to avoid them

Who this book is for

The Ethereum Cookbook is for you if you are a software engineer, Blockchain developer, or research scientist who wants to build smart contracts, develop decentralized applications, and facilitate peer-to-peer transaction. It is assumed that you are familiar with Blockchain concepts and have sound knowledge of JavaScript.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Ethereum Cookbook by Manoj P R in PDF and/or ePUB format, as well as other popular books in Computer Science & Cryptography. We have over one million books available in our catalogue for you to explore.

Information

Interacting with the Contract

In this chapter, we will cover the following recipes:
  • Installing and configuring web3.js
  • Using MetaMask as an injected provider
  • Managing accounts and sending transactions
  • Compiling and deploying your smart contract
  • Reading data from smart contracts
  • Writing data into a smart contract
  • Watching events from your DApp
  • Sending a raw transaction
  • Batch requests using web3.js
  • Interacting with Ethereum using JSON-RPC
  • Other ways to interact with your contract

Introduction

We don't expect an end user to be interacting with the geth console to access the smart contract or other Ethereum properties. It generally happens through a user interface. So, there needs to be a way by which applications can interact with the Ethereum blockchain. Ethereum allows connections via RPC and IPC, using which an application or user can interact with the distributed ledger.
This chapter mainly focuses on several ways to interact with your smart contract, which is deployed on the Ethereum main network. You will learn about web3.js and other libraries that will help you to build a decentralized application.

Installing and configuring web3.js

Web3.js is a JavaScript library that implements the JSON RPC specification of Ethereum. This library allows you to interact with a local or remote Ethereum node, using an HTTP or IPC connection. The following recipe will guide you through installing and configuring web3.js, as well as provide examples to use in your Decentralized Application (DApp).

Getting ready

Since the library is written in JavaScript and distributed via npm, you will need Node.js installed on your machine to use the library. Bower and Meteor versions are also available and you need to have the respective tools to download them.
There are two web3.js releases in use: 0.2x.x, which is the current stable version, and 1.x.x, which is an upcoming release that is currently in beta. We will learn to install and configure both of these versions.

How to do it...

Here are the steps to install web3.js and then configure it:
  1. Install web3 using the npm install command:
npm install web3
This will download the latest package available in the npm directory. Specify the version along with the install command to download a different release. Try installing the 0.2x.x release by specifying its version:
npm install [email protected]
Run the following command to view the list of packages and select the one that suits your needs:
npm view web3 versions
  1. Use the library as a browser module by downloading the JavaScript version directly from the web3.js repository at github.com/ethereum/web3.js. Navigate to the dist folder to find the web3.js files. Once you have downloaded them, import them into the HTML with a regular script tag:
<script src="./dist/web3.min.js"></script>
  1. Import web3 into your application using the require function. If you are using it as a browser module, it will be available as a global object:
var Web3 = require("web3");
  1. If you are using web3.js 1.x.x, reference individual packages under web3 using their module names. For example, you can directly import we3.eth using ...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Dedication
  4. Packt Upsell
  5. Contributors
  6. Preface
  7. Getting Started
  8. Smart Contract Development
  9. Interacting with the Contract
  10. The Truffle Suite
  11. Tokens and ICOs
  12. Games and DAOs
  13. Advanced Solidity
  14. Smart Contract Security
  15. Design Decisions
  16. Other Protocols and Applications
  17. Miscellaneous
  18. Other Books You May Enjoy