• Complain

Manoj P R [Manoj P R] - Ethereum Cookbook

Here you can read online Manoj P R [Manoj P R] - Ethereum Cookbook full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2018, publisher: Packt Publishing, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Manoj P R [Manoj P R] Ethereum Cookbook
  • Book:
    Ethereum Cookbook
  • Author:
  • Publisher:
    Packt Publishing
  • Genre:
  • Year:
    2018
  • Rating:
    3 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 60
    • 1
    • 2
    • 3
    • 4
    • 5

Ethereum Cookbook: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Ethereum Cookbook" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

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. Youll learn about the security vulnerabilities, along with other protocols of Ethereum.

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

By the end of this book, youll 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.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Manoj P R [Manoj P R]: author's other books


Who wrote Ethereum Cookbook? Find out the surname, the name of the author of the book and a list of all author's works by series.

Ethereum Cookbook — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Ethereum Cookbook" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
There's more...

Eth-netstats is a visual interface for tracking an Ethereum network status. To access the public status page, go to https://ethstats.net/. Note that the portal does not represent the entire state of the Ethereum main net. This is because of the voluntary listing of nodes in the portal.

You can use netstats to visualize your private Ethereum network:

  1. Download the source code from the repository. Make sure to verify the license:
git clone https://github.com/cubedro/eth-netstats
  1. Install the dependencies:
sudo npm install -g grunt-cli
cd eth-netstats
npm install
  1. Build the project using grunt and use npm to run it:
grunt
npm start
Using MetaMask as an injected provider

MetaMask and the Mist browser can be used as a provider for the web3 object. These services expose the web3 API and allow your application to connect to an Ethereum node. In this recipe, you will learn to use Mist or MetaMask as an injected provider for your application, along with other options.

There's more...

In addition to the previously mentioned functions, ERC20 also implements some events for logging:

event Transfer ( address indexed from , address indexed to , uint tokens ); event Approval ( address indexed tokenOwner , address indexed spender , uint tokens );

These events can be listened to from your application to provide a seamless UI for the user. This can help notify the users of tokens received or approved:

tokenContract.events.Transfer({
filter: { },
fromBlock: 0
})
.on('data', function(event){
// ...
})
.on('changed', function(event){
// ...
})
.on('error',function(event){
// ...
});
How to do it...
  1. Use the unbox command to download and use a box. Boxes are directly integrated into the Truffle command line:
truffle unbox
  1. Each box downloads related files and libraries for you to work with. Let's start with a very basic example, MetaCoin:
truffle unbox metacoin

This contains a basic MetaCoin contract along with related migration and test scripts. You can use compile, test, and migrate scripts to do the respective tasks.

Earlier versions of Truffle used MetaCoin as the template during the truffle init command. Now, has been moved to a dedicated box and the init command creates a more basic template. It is recommended to use the MetaCoin box for creating a new project.

  1. Use the react box to create a barebones React app and related smart contracts. It also includes jest and webpack for testing and other tasks:
truffle unbox react

You can start the application using the npm start script. This will serve your application frontend on http://localhost:3000 with hot reloading. Make sure to compile and migrate your contract manually after each modification:

npm run start

Smart contract and application tests can be executed using the truffle and jest commands:

// Smart contract teststruffle test
// Application tests using jestnpm run test

You can build your application for production using webpack. You can find the output in the build_webpack folder:

npm run build
  1. Use the webpack box if you need a box with the basic build setup of webpack:
truffle unbox webpack
  1. Use the react-auth box to create an app with redux, react-router, and a smart contract-based authentication wrapper along with webpack and react:
truffle unbox react-auth

It includes a basic authentication smart contract, which stores the user details of those who signed up. You can customize the contract and the router to add features required for your application.

You can test, build, and run this box just like you did the previous one:

// Serves the application on localhost:3000
npm run start
// To run the smart contract test scripts
truffle test
// To run the jest based application tests
npm run test
// To build the application for production
npm run build
  1. If you need a UPort implementation, use the react-uport box, which is an extension of the react-auth box. UPort is an identity and authentication system for Ethereum. UPort allows users to register their own identity on Ethereum, send and request credentials, sign transactions, and securely manage keys and data:
truffle unbox react-uport
  1. Truffle also supports boxes built by the community, and there are some good options available for you to choose from. You can find examples that use AngularJS, ExpressJS, Vue.js, and many more. The complete list of boxes supported by Truffle is available at https://truffleframework.com/boxes.
How to do it...
  1. Consider the following contract as an example for this recipe. This is a simple token contract with a feature to transfer tokens and check the balance of each address. The contract is only for illustration purposes, so don't use it in your production application:
pragma solidity ^0.4.23;
contract TokenContract {
mapping (address => uint) balances;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
constructor() public {
balances[msg.sender] = 100000;
}
function sendToken(address receiver, uint amount) public returns(bool) {
require(balances[msg.sender] < amount);
balances[msg.sender] -= amount;
balances[receiver] += amount;
emit Transfer(msg.sender, receiver, amount);
return true;
}
function getBalance(address addr) public view returns(uint) {
return balances[addr];
}
}
  1. This contract contains a constructor, a state changing method called sendToken, and a read-only method, getBalance. The constructor will be executed during the contract deployment and other functions have to be called with either a transaction or a call.
  2. Truffle will create a JavaScript object for the contract. Use the deployed() function to interact with the deployed version of the contract:
TokenContract.deployed().then(function(instance) {
console.log(instance);
});

Make sure that you have migrated your contract before trying to interact with them. If you are using truffle console, use truffle migrate from the root of your project.

  1. The sendToken function will try to send some tokens from one account to another. This results in a state change, and we need to use a transaction for this.

  2. Call the function directly and it will result in a transaction by default, instead of a call:
TokenContract.sendToken();
  1. Pass the parameters that are required to execute the function. Use an object as the optional last parameter that lets you configure specific details about the transaction, such as from address, value, gas, and so on:
var from_address = "0xa...";
var to_address = "0xb...";
TokenContract.sendToken(to_address, 500, {
from: from_address
});
  1. Use the promise functionality to fire callbacks on success and failure. With this, you don't have to check the status of the transaction yourself:
TokenContract.sendToken(to_address, 500, {
from: from_address
}).then(function(result) {
console.log(result);
})
  1. The whole operation will look something as follows:
var from_address = "0xa...";
var to_address = "0xb...";
var tokenContract;
TokenContract.deployed().then(function(instance) {
tokenContract = instance;
return tokenContract.sendToken(to_address, 500, {
from: from_address
});
}).then(function(result) {
// Transaction successful!
console.log(result);
}).catch(function(e) {
// Transaction failed
console.log(e);
})
  1. The getBalance function is used for reading the balance of a specific address. Note that this does not modify any state. So, execute the function using the call method:
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Ethereum Cookbook»

Look at similar books to Ethereum Cookbook. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Ethereum Cookbook»

Discussion, reviews of the book Ethereum Cookbook and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.