Reader small image

You're reading from  Hyperledger Cookbook

Product typeBook
Published inApr 2019
Reading LevelBeginner
PublisherPackt
ISBN-139781789534887
Edition1st Edition
Languages
Concepts
Right arrow
Authors (3):
Xun (Brian) Wu
Xun (Brian) Wu
author image
Xun (Brian) Wu

Xun (Brian) Wu is a senior blockchain architect and consultant. With over 20 years of hands-on experience across various technologies, including Blockchain, big data, cloud, AI, systems, and infrastructure, Brian has worked on more than 50 projects in his career. He has authored nine books, which have been published by O'Reilly, Packt, and Apress, focusing on popular fields within the Blockchain industry. The titles of his books include: Learn Ethereum (First Edition), Learn Ethereum (Second Edition), Blockchain for Teens, Hands-On Smart Contract Development with Hyperledger Fabric V2, Hyperledger Cookbook, Blockchain Quick Start Guide, Security Tokens and Stablecoins Quick Start Guide, Blockchain by Example, and Seven NoSQL Databases in a Week.
Read more about Xun (Brian) Wu

Chuanfeng Zhang
Chuanfeng Zhang
author image
Chuanfeng Zhang

Chuanfeng Zhang is enthusiastic and passionate about technologies and trading and data analysis, with 20 years' experience in both the technology and finance sectors. He has worked at top investment banks and technology firms including Goldman Sachs, Credit Suisse, and IBM. He has led, designed, and successfully developed many enterprise-scale systems with diverse architectures for algorithmic trading, order management, risk management, business intelligence, and more.
Read more about Chuanfeng Zhang

Zhibin (Andrew) Zhang
Zhibin (Andrew) Zhang
author image
Zhibin (Andrew) Zhang

Andrew Zhang is an IBM Watson Cloud Advocate. He has many years of experience in cloud platforms, big data analytics, and machine learning. He works with start-ups and enterprise clients in the government, education, healthcare, and life science industries. His current interests are in embedding AI and blockchain open source technologies for consumer and enterprise applications. In his spare time, Andrew enjoys reading, traveling, and spending time with his family and friends.
Read more about Zhibin (Andrew) Zhang

View More author details
Right arrow

Operating an Ethereum Smart Contract with Hyperledger Burrow

Hyperledger Burrow is an enterprise blockchain network that provides a permissioned smart contract interpreter to execute business logic following the Ethereum Virtual Machine (EVM) specifications.

Hyperledger Seth is the Sawtooth-Ethereum integration project. It integrates the Hyperledger Burrow implementation of the EVM with Hyperledger Sawtooth to provide support for running Ethereum smart contracts on the Hyperledger Sawtooth platform.

In this chapter, we will cover several recipes regarding how to operate Ethereum smart contracts with Hyperledger Burrow and Seth:

  • Installing Hyperledger Burrow on AWS
  • Writing smart contracts with Solidity
  • Deploying and calling Ethereum smart contracts on Burrow
  • Installing Hyperledger Seth with Docker on AWS
  • Creating externally owned accounts and writing Solidity contracts on Seth...

Introduction

Ethereum is one of the most important public blockchain networks in terms of its impact and market cap. It is sometimes known as a world computer, as it is used to run decentralized applications (DApps) for everyone and has an open software platform powered by the global infrastructure. It allows different organizations and individuals to build and deploy DApps to execute smart contracts. Ethereum is the next generation of blockchain. It introduced the possibility for blockchain technology to develop from cryptocurrency cash systems to an open, flexible, and distributed global computing platform for a wide variety of applications.

The smart contract running on Ethereum is the application, which can be written in different programming languages to perform all sorts of business logic or fulfill predefined contracts when they are triggered. The EVM is the runtime environment...

Installing Hyperledger Burrow on AWS

In this recipe, we will learn how to install Hyperledger Burrow on the AWS Cloud platform.

Getting ready

To install and run the recipes in this chapter, you need an EC2 instance on AWS with the following configuration:

  • Operating system: Ubuntu 16.04.5 LTS
  • AWS EC2 instance type: m4.2xlarge or t2.mroc

How to do it...

Execute the following steps to install Hyperledger Burrow:

  1. Install Go version 1.10 or higher. The following commands can be used to install Go on an EC2 instance:
sudo apt update
sudo apt install golang-go

If you have...

Writing smart contracts with Solidity

Getting ready

In this smart contract, we will perform transactions to deposit coins, withdraw coins, and query the account balance. The smart contract looks as follows:

How to do it...

Deploying and calling the Ethereum smart contract on Burrow

We will deploy and run the sample contract on Burrow in this recipe.

Getting ready

In order to deploy the sample contract written with Solidity onto Burrow, the Solidity compiler needs to be installed on Linux:

  1. Install the Solidity compiler:
sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc
  1. Verify that the Solidity compiler, solc, is installed with the following command:
ubuntu@ip-172-31-90-67:~/go/src/hello$ solc --version
solc, the solidity compiler commandline interface
Version: 0.4.25+commit.59dbf8f1.Linux.g++

How to do it...

Installing Hyperledger Seth with Docker on AWS

Seth is packaged separately from the Hyperledger Sawtooth project. Seth provides Docker images to start up the Seth environment. In this recipe, we will install Docker on Ubuntu and start up the Seth Docker image.

How to do it...

  1. Install the Docker Community Edition (CE) by following the Docker documentation. Update the apt package index as follows:
sudo apt-get update
  1. Install the necessary packages to allow apt to use a repository over HTTPS:
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
  1. Add Docker's official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

  1. Set up...

Creating externally owned accounts and writing Solidity contracts on Seth

The easiest way to write Solidity contracts and check their grammar is to write them with Remix (https://github.com/ethereum/remix).

We will implement a similar smart contract as we did with Burrow to create an EOA account and perform transactions to deposit, withdraw, and query the account on the Sawtooth network via Seth.

How to do it...

  1. Create an externally owned account (EOA) with the Seth CLI. Start up shell in the seth-cli-go container:
sudo docker exec -it seth-cli-go bash
  1. In the container shell, generate a password-encrypted key file with OpenSSL:
openssl ecparam -genkey -name secp256k1 | openssl ec -out kevin.pem -aes128

  1. Generate another...

Deploying and calling Ethereum contracts with the Seth CLI and RPC

In this recipe, we will compile, deploy, and call Ethereum smart contracts on the Sawtooth platform with the Seth client CLI and the Seth-RPC.

How to do it...

  1. Compile the Solidity contract. To deploy a contract, the Seth client expects the contract to be passed in the form of a hex-encoded byte array. The Solidity compiler, solc, can be used to generate the byte codes. The command to generate the hex-encoded bytes for a contract is as follows:
ubuntu@ip-172-31-90-67:~/seth/example$ solc --bin SethContract.sol
======= SethContract.sol:SethContract =======
Binary:
608060405234801561001057600080fd5b5033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000808...

Permissioning Ethereum EOA and contract accounts on Seth

In this recipe, we will go through how to provision permission to both EOAs and contract accounts on Seth.

How to do it...

  1. Start the Seth Docker images with Docker-Compose:
sudo docker-compose up
  1. Execute bash on the seth-cli-go container:
sudo docker exec -it seth-cli-go bash
  1. Check the contract account permissions:
seth show account "da9fae99224516db78935d7cb91724e851c5b3fa"
Address: da9fae99224516db78935d7cb91724e851c5b3fa
Balance: 0
Nonce : 1
Perms : -root,+send,+call,-contract,-account
Storage:
0000000000000000000000000000000000000000000000000000000000000001 -> 000000000000000000000000da9fae99224516db78935d7cb91724e851c5b3fa
0000000000000000000000000000000000000000000000000000000000000000...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hyperledger Cookbook
Published in: Apr 2019Publisher: PacktISBN-13: 9781789534887
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Xun (Brian) Wu

Xun (Brian) Wu is a senior blockchain architect and consultant. With over 20 years of hands-on experience across various technologies, including Blockchain, big data, cloud, AI, systems, and infrastructure, Brian has worked on more than 50 projects in his career. He has authored nine books, which have been published by O'Reilly, Packt, and Apress, focusing on popular fields within the Blockchain industry. The titles of his books include: Learn Ethereum (First Edition), Learn Ethereum (Second Edition), Blockchain for Teens, Hands-On Smart Contract Development with Hyperledger Fabric V2, Hyperledger Cookbook, Blockchain Quick Start Guide, Security Tokens and Stablecoins Quick Start Guide, Blockchain by Example, and Seven NoSQL Databases in a Week.
Read more about Xun (Brian) Wu

author image
Chuanfeng Zhang

Chuanfeng Zhang is enthusiastic and passionate about technologies and trading and data analysis, with 20 years' experience in both the technology and finance sectors. He has worked at top investment banks and technology firms including Goldman Sachs, Credit Suisse, and IBM. He has led, designed, and successfully developed many enterprise-scale systems with diverse architectures for algorithmic trading, order management, risk management, business intelligence, and more.
Read more about Chuanfeng Zhang

author image
Zhibin (Andrew) Zhang

Andrew Zhang is an IBM Watson Cloud Advocate. He has many years of experience in cloud platforms, big data analytics, and machine learning. He works with start-ups and enterprise clients in the government, education, healthcare, and life science industries. His current interests are in embedding AI and blockchain open source technologies for consumer and enterprise applications. In his spare time, Andrew enjoys reading, traveling, and spending time with his family and friends.
Read more about Zhibin (Andrew) Zhang