Skip to Content
Technical Articles
Author's profile photo Michael Kunzmann

SAP Cloud Platform now supports Quorum in addition to Hyperledger Fabric and MultiChain

The service simplifies Quorum blockchain instance lifecycle management and is now available for SCP trial accounts.

What is Quorum?

Quorum is a code fork of Ethereum by JPMorgan Chase, available as an open source project on GitHub. Unlike Ethereum, Quorum enables private and permissioned blockchains. At a glance, Quorum offers:

  • Permissioned networks
    Quorum introduced a whitelist to prevent unwanted peers to connect to the blockchain network.
  • Private transactions
    Quorum introduced a privacy layer that allows to send private transactions between peers.
  • High throughput and instant transaction finality
    According to the Istanbul EIP, Quorum allows higher transaction throughputs than Ethereum as well as the prevention of forks.
  • Less energy consumption
    Traditional Proof of Work requires additional energy consumption that is not required for private blockchains in most cases. Quorum introduces two consensus mechanisms: Istanbul BFT and Raft. SAP Cloud Platform’s Quorum service only supports Istanbul BFT.
  • No Gas price
    While the concepts of Gas and Gas limits still exist in Quorum, the Gas is free.

Quorum on SAP Cloud Platform

SAP Cloud Platform now offers a free-of-charge “dev” service plan for developers to build with Quorum in a playground environment. The plan offers Quorum instances that are shared with other developers.

The playground environment allows developers to get familiar with Soliditysmart contracts and leverage Cloud Foundry to build blockchain applications. To use the “dev” plan, a free account on SAP Cloud Platform is required. To set up a “dev” instance, follow this link to the official documentation.

In the near future, there will be three more service plans in addition to the Dev plan:

  • Testnet: Instead of connecting to a shared instance, developers can create their own Quorum instance and connect it to one of the regional Quorum test networks. However, with this plan developers will not be able to connect external nodes.
  • Large: This is a productive instance that allows developers to start a new, internet-facing network and or connect to an existing network.
  • CYON: CYON means “Connect your own network”. In some cases developers might decide to not run a Quorum instance on SAP Cloud Platform but still want to use the integrations with other SAP systems.

Deploy an Ethereum smart contract to Quorum instance

Prerequisites:

  • Node.js & NPM
    SAP Cloud Platform supports various programming languages and frameworks. This example leverages Node.js, the standard Web3.js library and the Solc Solidity compiler.
  • Access to Quorum instance
    You need a Quorum instance running on SAP Cloud Platform.
  • Ethereum account address and password
    The account is used for deploying smart contracts

The following code snippet represents a Solidity smart contract that initializes an integer value. The contract also contains functionality to update the integer value and read the current value.


pragma solidity ^0.5.0;
contract SimpleStorage {
    uint public storedData;
    constructor (uint initVal) public {
        storedData = initVal;
    }
    
    function set(uint x) public {
        storedData = x;
    }
    
    function get() public view returns (uint retVal) {
        return storedData;
    }
}

This contract can be deployed using any existing Ethereum development tool that can connect to the instance’s RPC API, such as Truffle or Remix (a CORS browser plugin is required for Remix at this point). For learning purposes, the blog post demonstrates how to compile and deploy a smart contract using a few lines of code from scratch, using the web3 and solc NPM packages.

const Web3 = require('web3')
const solc = require('solc')

The following code connects to the Quorum instance’s RPC endpoint. The RPC URL can be obtained from the Quorum dashboard.

const rpc = 'paste RPC url from dashboard here'
const web3 = new Web3(new Web3.providers.HttpProvider(rpc))

Next, the contract needs to be compiled. You could also load the contract from a file and compile more than just one contract. For simplicity, the example puts everything in code:

// Compile smart contract using the solc compiler
const sourceCode = `
pragma solidity ^0.5.0;
contract SimpleStorage {
    uint public storedData;
    
    constructor (uint initVal) public {
        storedData = initVal;
    }
    
    function set(uint x) public {
        storedData = x;
    }
    
    function get() public view returns (uint retVal) {
        return storedData;
    }
}
`
const input = {
  language: 'Solidity', 
  sources: { 'simplestorage.sol': { content: sourceCode } },
  settings: { outputSelection: { '*': { '*': [ '*' ] } } }
}
const compiled = JSON.parse(solc.compile(JSON.stringify(input)))
if (compiled.errors > 0) {
  console.error(compiled.errors)
  process.exit(1)
}
const compiledContracts = compiled.contracts['simplestorage.sol']
console.log('successfully compiled contract(s)')

The following code is wrapped in an async function and a try/catch block to make use of ECMAScript’s await keyword. The use of the await keyword makes the following snippets more readable.

;(async () => {
  try {
    The following code will be here
  } catch (err) {
    console.error(err)
  }
})()

Quorum on SAP Cloud Platform locks all accounts with a password by default. The following code unlocks the account for 10 seconds.

// Select account and unlock the account with your password
const accountAddress = ''
const accountPassword = ''
await web3.eth.personal.unlockAccount(accountAddress, accountPassword, 10)
console.log('account unlocked')

The following code deploys the byte code of the compiled contract and initializes the contract with value “1”. Note that a Gas limit is still required. Unlike Ethereum, Quorum does not subtract any transaction fees from the account. Once the contract deployment transaction is confirmed, the contract address can be used to interact with the contract.

// Deploy contract, initialize with value 1
const contract = await new web3.eth.Contract(compiledContracts.SimpleStorage.abi).deploy({
  data: '0x' + compiledContracts.SimpleStorage.evm.bytecode.object,
  arguments: [1]
}).send({
  from: accountAddress,
  gas: 300000
})
const contractAddress = contract.options.address
console.log('contract successfully deployed')

The following code snippet reads the value from the contract that was initialized earlier. At this point, the same “contract” object could be reused. Instead, this example demonstrates how a different Quorum instance can interact with the same contract, using the ABI and the address of the deployed contract.

// Retrieve contract using ABI and address and read from it. 
const newContract = new web3.eth.Contract(compiledContracts.SimpleStorage.abi, contractAddress)
let result = await newContract.methods.get().call()
console.log('successfully read from contract:', result)

The final snippet shows how to change the value to a different integer. This will cause another transaction. Similar to the contract deployment, the the specification of the account address is required.

// Change value from 1 to 42
await newContract.methods.set(42).send({ from: accountAddress })
result = await newContract.methods.get().call()
console.log('successfully wrote and read new value to contract:', result)

Next steps

In another post, I explain how to make use of rapid development using Truffle with Quorum on SAP Cloud Platform: https://blogs.sap.com/2019/01/08/using-truffle-with-quorum-on-sap-cloud-platform

Resources

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Michael,

      after setting up the Quorum cloud service in my trial account my understanding is that it should remain freely accessible for the duration or at least until the next account renewal. is this also true for any of tools like truffle or the future additional plans that would comprise of a larger network?

      while i'm not entirely convinced of the ethereum model, it has recently regained the second most valuable crypto position, is backed by EEA, and traces its origins to a major city retail/commercial/investment bank, which is too big to fail, it does have more credibility than 95% of other crypto projects that had mostly failed last year.

      thank you for making it available and accessible to the SAP Community.

      rgds,

      greg

      Author's profile photo Michael Kunzmann
      Michael Kunzmann
      Blog Post Author

      Hi Greg! Yes, it remains freely accessible for the trial duration. Truffle is a common 3rd party open source tool for Ethereum and remains accessible as long as the tool is maintained.
      The “dev” plan aims to help developers get started with Ethereum/Quorum development. As described in the post, there will be a “testnet” service plan (to connect own instances to a shared network) and a productive service plan (create blockchain instances and connect them to any network, even outside of SAP, as well as start new networks). In addition, there will also be a “cyon” plan (connect your own network, allows to build apps on top of quorum instances not hosted by SAP) Those offerings will be made available in the near future. Let me know if this answered your questions!
      Cheers, Michael