Back to Blog

Submit your first private transaction on Hyperledger Besu using Orion

Getting started with Besu+Orion private transactions on Kaleido

Maybe you’re working on your first Enterprise Ethereum blockchain project to require private transactions, or maybe you’re an expert in Quorum trying out Besu for the first time.

Either way we’ve done the work in Kaleido to understand the differences and tooling options out there, and simplify things wherever possible.

If you use our REST API Gateway, you’ll find today we’ve abstracted the differences between the technologies wherever possible into the gateway itself. By default we use one-time keys for submitting the ordering transactions for Hyperledger Besu + Orion, allow you to specify the signing key for the private transactions, and automatically manage a single privacy group for each list of privateFor addresses.

We’ve also done the work in our kaleido-js sample based on web3js to give you Javascript sample code to submit private transactions directly to a node over JSON/RPC.

Submitting transactions using the kaleido-js package

We can use the kaleido-js package to deploy a private contract and submit private transactions in besu. This package comes handy when you want to deploy contract, send transactions, perform queries and also submit externally signed transaction. Go to https://github.com/kaleido-io/kaleido-js and clone or download the package to your local machine.

Once downloaded cd to the kaleido-js folder.

cd ~/kaleido-js/deploy-transact/

Install the required node packages

npm i

The first step is to deploy a private contract. The kaleido-js already has a Simple storage contract which we will use for this example. To deploy your own contract add your contract to the contracts folder. To deploy a private contract you will need:

  • The connection url of the node through which you want to deploy the contract
  • The orion address of the nodes, for which your need the contract to be deployed

Follow the below steps to get the connection URL and the orion address of the node:

  1. Navigate to the environment containing the nodes.
  2. Click on the node to navigate to the Node information page. The value displayed in PRIVATE TX PARTICIPANT is the orion address of the node.
  3. Click Connect Node button on the top right portion of the screen. In the Kaleido Connect page, click VIEW DETAILS under Native JSON/RPC
  4. You will be taken to the app creds page. Create new app creds or use your existing app creds. Here we will create New app creds.
  5. In the Kaleido Connect page, copy the value CONNECTION URL

Now, use the below command to deploy the contract. Here we deploy the private contract between nodes 1, 2 ad 3. The – -url is the connection url of node 1. The –privateFrom is the orion address of node 1 and –privateFor is the orion address of node 2 and node 3 separated by commas.

node test.js –url=https://zzop6ymmpf:B2QslYYRwzCNT48GMc5T-A4dIwu6ywmLhbTKijCTLwA@zzalhiud2y-zzvqa2weug-rpc.dev2.photic.io –deploy –besu_private –privateFrom=RReps2SdrlDI5v5cYRtziItNHZlw7lFjtNhs8amKwWc= –privateFor=WEb6fchCeCb/18YygqLjsmCBUB0qqxALhCsu7nfDExI=,ZWd0QyywLTNVusqi//JcUQYazt3dJJvxB3i1ldcKCm0=

You should see the response similar to as follows:

=> Connecting to target node: https://zzop6ymmpf:B2QslYYRwzCNT48GMc5T-A4dIwu6ywmLhbTKijCTLwA@zzalhiud2y-zzvqa2weug-rpc.dev2.photic.io

Found account in the target node: 0x158CC890d0E0b73Aba1238a3400029e5846DF81A

=> Deploying smart contract

Waiting for transaction to be mined …

Smart contract deployed, ready to take calls at “0xaea6b92b6dc737376a88d7738a0423f72f29aa7e”

Note down the contract address. This will be used in all further transactions.

Now let us invoke the set operation in simple storage. For this submit the transaction as follows:

node test.js –url=https://zzop6ymmpf:B2QslYYRwzCNT48GMc5T-A4dIwu6ywmLhbTKijCTLwA@zzalhiud2y-zzvqa2weug-rpc.dev2.photic.io –contract=0xaea6b92b6dc737376a88d7738a0423f72f29aa7e –set=7 –besu_private –privateFrom=RReps2SdrlDI5v5cYRtziItNHZlw7lFjtNhs8amKwWc= –privateFor=’WEb6fchCeCb/18YygqLjsmCBUB0qqxALhCsu7nfDExI=’,’ZWd0QyywLTNVusqi//JcUQYazt3dJJvxB3i1ldcKCm0=’

=> Connecting to target node: https://zzop6ymmpf:B2QslYYRwzCNT48GMc5T-A4dIwu6ywmLhbTKijCTLwA@zzalhiud2y-zzvqa2weug-rpc.dev2.photic.io

Found account in the target node: 0x158CC890d0E0b73Aba1238a3400029e5846DF81A

=> Setting state to new value

Waiting for transaction to be mined …

New value set to: 7

DONE!

We can query the contract to check the value. We will submit query through node 2, so now the privateFrom field contains the orion address of node 2 and the privateFor field contains the orion address of node1 and 3 seperated by commas.

node test.js –url=https://zzop6ymmpf:B2QslYYRwzCNT48GMc5T-A4dIwu6ywmLhbTKijCTLwA@zzalhiud2y-zzq5hjn2gb-rpc.dev2.photic.io –contract=0xaea6b92b6dc737376a88d7738a0423f72f29aa7e –query –besu_private –privateFrom=WEb6fchCeCb/18YygqLjsmCBUB0qqxALhCsu7nfDExI= –privateFor=RReps2SdrlDI5v5cYRtziItNHZlw7lFjtNhs8amKwWc=,ZWd0QyywLTNVusqi//JcUQYazt3dJJvxB3i1ldcKCm0=

=> Connecting to target node: https://zzop6ymmpf:B2QslYYRwzCNT48GMc5T-A4dIwu6ywmLhbTKijCTLwA@zzalhiud2y-zzq5hjn2gb-rpc.dev2.photic.io

Found account in the target node: 0x1025d27317086972cF76369976e09C059541c138

=> Calling smart contract at “0xaea6b92b6dc737376a88d7738a0423f72f29aa7e” for current state value

Waiting for transaction to be mined …

Smart contract current state: “0x0000000000000000000000000000000000000000000000000000000000000007”

DONE!

Since this contract is only deployed in the privacy group formed by nodes 1, 2 and 3, the value we set is completely shielded from node 4.

 

Prev Announcing General Availability and Production Support for Hyperledger Besu on Kaleido Next Permissions & Privacy: Core Elements of an Enterprise Blockchain