Skip to main content

Create a privacy-enabled network using the Quorum Developer Quickstart

You can create a privacy-enabled network using the Quorum Developer Quickstart. It runs a private Hyperledger Besu network that uses Tessera as its private transaction manager.

You can use the Block Explorer, make JSON-RPC requests, and create transactions using MetaMask. This tutorial describes how to make private transactions between nodes, and perform read and write operations on private contracts.

important

This tutorial runs a private network suitable for education or demonstration purposes and is not intended for running production networks.

Prerequisites

To run this tutorial, you must have the following installed:

Create Docker-compose file

Usage

To create the docker-compose file and artifacts, run:

npx quorum-dev-quickstart

Follow the prompts displayed to run Hyperledger Besu, private transactions, and logging with ELK. Enter n for Codefi Orchestrate.

Start the network

caution

If running in Windows, please run commands from the GitBash shell

In the installation directory, start the network:

./run.sh

The script pulls the Docker images starts the network. Pulling the images takes a few minutes the first time. The network details display.

*************************************
Quorum Dev Quickstart
*************************************
Setting up the index patterns in kibana .................
----------------------------------
List endpoints and services
----------------------------------
JSON-RPC HTTP service endpoint : http://localhost:8545
JSON-RPC WebSocket service endpoint : ws://localhost:8546
Web block explorer address : http://localhost:25000/
Prometheus address : http://localhost:9090/graph
Grafana address : http://localhost:3000/d/XE4V0WGZz/besu-overview?orgId=1&refresh=10s&from=now-30m&to=now&var-system=All
Collated logs using Kibana endpoint : http://localhost:5601/app/kibana#/discover

For more information on the endpoints and services, refer to README.md in the installation directory.
****************************************************************

Deploy the private contract and interact with the nodes

To deploy a private contract to another privacy group member, use the web3js-quorum library and the eea_sendRawTransaction API call. You must use this API call instead of eth_sendTransaction because Hyperledger Besu keeps account management separate for stronger security.

This example uses the web3js library to make the API calls, the example creates three Besu nodes, with each node having a corresponding Tessera node for privacy. You can access the Besu member nodes for API calls on the following ports:

Member1Besu RPC: http://localhost:20000
Member1Tessera: http://localhost:9081

Member2Besu RPC: http://localhost:20002
Member2Tessera: http://localhost:9082

Member3Besu RPC: http://localhost:20004
Member3Tessera: http://localhost:9083

Navigate to the smart_contracts directory and deploy the private transaction:

cd smart_contracts
npm install
node scripts/private/private_tx.js

The script deploys the contract and sends an arbitrary value (47) from Member1 to Member3. Once done, it queries all three members (Tessera) to check the value at an address. Only Member1 & Member3 has this information as they were involved in the transaction, Member2 responds with a 0x to indicate it is unaware of the transaction.

node scripts/private/private_tx.js
Creating contract...
Getting contractAddress from txHash: 0xc1b57f6a7773fe887afb141a09a573d19cb0fdbb15e0f2b9ed0dfead6f5b5dbf
Waiting for transaction to be mined ...
Address of transaction: 0x8220ca987f7bb7f99815d0ef64e1d8a072a2c167
Use the smart contracts 'get' function to read the contract's constructor initialized value ..
Waiting for transaction to be mined ...
Member1 value from deployed contract is: 0x000000000000000000000000000000000000000000000000000000000000002f
Use the smart contracts 'set' function to update that value to 123 .. - from member1 to member3
Transaction hash: 0x387c6627fe87e235b0f2bbbe1b2003a11b54afc737dca8da4990d3de3197ac5f
Waiting for transaction to be mined ...
Verify the private transaction is private by reading the value from all three members ..
Waiting for transaction to be mined ...
Member1 value from deployed contract is: 0x000000000000000000000000000000000000000000000000000000000000007b
Waiting for transaction to be mined ...
Member2 value from deployed contract is: 0x
Waiting for transaction to be mined ...
Member3 value from deployed contract is: 0x000000000000000000000000000000000000000000000000000000000000007b

The general contract deployment flow is:

  1. Deploy a contract, which returns a transaction hash.

  2. Obtain the privacy transaction receipt from the transaction hash.

  3. Use the contract address in the privacy transaction receipt to interact with the contract from that point on.

Further examples

View the web3js-quorum client library example and view the sample code examples.

You can also test the erc20 token example by executing erc20.js which deploys a HumanStandardToken contract and transfers 1 token to Node2.

This can be verified from the data field of the logs which is 1.

Stop the network

Do one of the following to stop the network:

  • Stop the network:

    ./stop.sh
  • Stop the network and remove the containers and volumes:

    ./remove.sh