Overview

Skill Level: Intermediate

In this recipe, we will deploy and run the sample Ethereum smart contract that is built by Solidity programming language on Hyperledger Burrow. It shows you how to build and deploy Ethereum DApps in Hyperledger.

Ingredients

To follow and complete this recipe, you need to have good knowledge of blockchain, Hyperledger transactions, JavaScript as well as basic knowledge of Solidity and Linux.

Step-by-step

  1. Hyperledger Burrow Overview

    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.

    For those who are not familiar with Hyperledger project Intro to Hyperledger Family and Hyperledger Blockchain Ecosystem and Hyperledger Design Philosophy and Framework Architecture articles are strongly recommended.

    To better follow and understand this recipe, it is advisable to read Essential Hyperledger Sawtooth Features for Enterprise Blockchain Developers, Blockchain Developer Guide- How to Install and work with Hyperledger Sawtooth , Configuring Hyperledger Sawtooth Validator and REST API and Blockchain Developer Guide- How to Install Hyperledger Seth and Docker on AWS articles in advance.

    In our previous recipes, we reviewed i- Ethereum, Solidity and how to use Hyperledger Seth to build blockchain application with Ethereum and ii-How to install Hyperledger Burrow on AWS, and iii- How to write smart contracts with Solidity. We will deploy and run the sample contract on Burrow in this recipe.

  2. Build Solidity Compiler

    In order to deploy the sample contract written (in our previous recipe) 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

    2. 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++

  3. Deploy Smart Contracts on Hyperledger Burrow

    Execute the following steps to deploy and run smart contract:

    1. Define the Burrow deploy configuration file for the Solidity contract. The deploy file for the BasicContract.sol sample contract is the basiccontractdeploy.yaml file. It specifies the job as deploy and the Solidity contract file as follows:

    jobs:

    name: BasicContract deploy:

     

    contract: BasicContract.sol

    2. Deploy the Solidity contract. After both the BasicContract.sol contract file and the basiccontractdeploy.yaml deploy file are written, the contract can be deployed to the Burrow validator with the burrow deploy command:

    burrow deploy –address=54EF1517D97E7A653D5FA5B05060A82A8856515D -f basiccontractdeploy.yaml

    The output should be as follows:
    ubuntu@ip-172-31-90-67:~/burrow/example/basic$ burrow deploy — address=54EF1517D97E7A653D5FA5B05060A82A8856515D -f basiccontractdeploy.yaml
    *****Executing Job***
    Job Name => defaultAddr

    *****Executing Job***

    Job Name => BasicContract

    Deploying Contract name => BasicContract

    addr => 5486CD7F1453396A1C9E4B24CC07AA507C4CD88A

    Saving Binary =>

    /home/ubuntu/burrow/example/basic/bin/BasicContract.bin

    Writing [basiccontractdeploy.output.json] to current directory

    The deployed contract address is in the preceding output. For our contract, it’s 5486CD7F1453396A1C9E4B24CC07AA507C4CD88A, which will be used when calling this contract.

    3. Call the contract. To call the deposit function in the sample contract, specify the Burrow deploy configure file, basiccontractdeposit.yaml, as follows:

    jobs:

    name: deposit call:

     

    destination: 5486CD7F1453396A1C9E4B24CC07AA507C4CD88A

    function: deposit data:

    1000
     

    4. Run the Burrow CLI command:

    burrow deploy –address=54EF1517D97E7A653D5FA5B05060A82A8856515D -f basiccontractdeposit.yaml

    5. To call the withdraw function in the sample contract, specify the Burrow deploy configure file, basiccontractwithdraw.yaml, as follows:

    jobs:

    name: withdraw call:

     

    destination: 5486CD7F1453396A1C9E4B24CC07AA507C4CD88A

    function: withdraw data:

    200

    6. Run the Burrow CLI command:

    burrow deploy –address=54EF1517D97E7A653D5FA5B05060A82A8856515D -f basiccontractwithdraw.yaml

    7. To call the getBalance function in the sample contract, specify the Burrow deploy configure file, as follows:

    jobs:

    name: getBalance query-contract: 

    destination: 5486CD7F1453396A1C9E4B24CC07AA507C4CD88A

    function: getBalance

    name: getAddress query-contract: 

    destination: 5486CD7F1453396A1C9E4B24CC07AA507C4CD88A

    function: getAddress

    8. Run the Burrow CLI command:

    burrow deploy –address=54EF1517D97E7A653D5FA5B05060A82A8856515D -f basiccontractquery.yaml

    The output for the query should look as follows:

    ubuntu@ip-172-31-90-67:~/burrow/example/basic$ burrow deploy

    –address=54EF1517D97E7A653D5FA5B05060A82A8856515D -f

    basiccontractquery.yaml

    *****Executing Job***

    Job Name => defaultAddr

    *****Executing Job***

    Job Name => getBalance

    Return Value => 800

    *****Executing Job***

    Job Name => getAddress

    Return Value => 54EF1517D97E7A653D5FA5B05060A82A8856515D Writing [basiccontractquery.output.json] to current directory

  4. Put Things Together

    The Burrow blockchain is composed of validator peer nodes. Burrow provides CLI commands to interact with the network. The burrow deploy CLI command is used to deploy the smart contract and trigger transactions on the deployed contract account. Its main options are as follows:

    ubuntu@ip-172-31-90-67:~/burrow/example/basic$ burrow deploy –help Usage: burrow deploy [OPTIONS]

    Deploy and test contracts

    Options:

    -u, –chain-url chain-url to be used in IP:PORT format (default “127.0.0.1:10997”)

    -s, –keys IP:PORT of Burrow GRPC service which jobs should or otherwise transaction

    submitted unsigned for mempool signing in Burrow

    -f, –file path to package file which jobs should use. if also using the –dir flag, give the relative path to jobs file, which should be in the same directory (default “deploy.yaml”)

    -a, –address default address to use; operates the same way as the [account] job, only before the deploy file is ran

    To deploy and trigger transactions with the burrow deploy command, the validator address and the RPC URL (the default is 127.0.0.1:10997) will be used. These are defined in the generated Burrow validator configuration file, burrow.toml, as follows:
    [[GenesisDoc.Validators]]

    Address = “54EF1517D97E7A653D5FA5B05060A82A8856515D”

    PublicKey =

    “{\”CurveType\”:\”ed25519\”,\”PublicKey\”:\”FF4E4B9D3FB3B4CC0F113661E2E298C

    7DD7355A1207CA398496550BC162C04F3\”}”

    Amount = 9999999999

    Name = “Full_0”

    [RPC]

    [RPC.Info]

    Enabled = true

    ListenAddress = “tcp://127.0.0.1:26658”

    [RPC.Profiler]

    Enabled = false

    ListenAddress = “tcp://127.0.0.1:6060”

    [RPC.GRPC]

    Enabled = true

    ListenAddress = “127.0.0.1:10997”

     

    To deploy and test the contract, the deploy configure file should be provided as an option, indicated by -f. In the file, jobs are defined. To define a job, you need to provide the following:

    • A name: A user-friendly job name.
    • The job type: deploy, call, or query-contract. We used the three job types in this recipe to deploy contracts, call transactions to withdraw money, and query the balance of the account.
    • The destination: The contract account address.
    • The function: The name of the function in the Solidity contract.
    • The data: The parameters to call the function.

    This recipe is written in collaboration with Brian Wu who is a senior Hyperledger instructor at Coding Bootcamps school in Washington DC.

Join The Discussion