Web3 Quorum
Purpose¶
A helper layer over JP Morgan’s Quorum blockchain API: web3j-quorum
Methods¶
Binding name: p6.web3quorum
Value: ZERO_GAS_PROVIDER
This is a static value that can be used in various Web3j calls that require a ContractGasProvider
.
This value provider specifies zero gas price with a maximum gas of three million.
build¶
Build an instance of a Quorum object (extension of Web3j) using the supplied node URL to build an HttpService
connection.
Syntax
Quorum p6.web3quorum.build(String url)
Tip
You can use the core Web3j Quorum instance build methods using UnixIpcService
or WindowsIpcService
for a more efficient ‘same host’ connection.
Example
def quorum = p6.web3quorum.build('http://localhost:22000')
buildEnclave¶
Builds an instance of an Enclave object for the given Quorum instance. The URL and port parameters are used to connect to the Tessera transaction manager.
Syntax
Enclave p6.web3quorum.buildEnclave(final Quorum quorum, final String url, final int port, final String... tesseraIpcPath) throws P6Exception
Parameter: tesseraIpcPath
The optional tesseraIpcPath
parameter allows the specification of a Unix domain socket path for Tessera IPC.
Example
def quorum = p6.web3quorum.build('http://localhost:22000')
log.info 'Quorum node: ' + quorum.web3ClientVersion().send().getWeb3ClientVersion()
def enclave = p6.web3quorum.buildEnclave(quorum, 'http://localhost', 9081)
buildPrivateTransactionManager¶
Create a private transaction manager using the Quorum instance, Enclave and credentials given.
Syntax
QuorumTransactionManager p6.web3quorum.buildPrivateTransactionManager(final Quorum quorum, final Enclave enclave, final String originatorKey, final Credentials credentials, final String... recipientKeys) throws P6Exception
Info
The list of recipient keys are the public keys of the transaction recipients: privateFor-public-keys
.
Example
/**
* Quorum example requires their 7nodes example running locally
* plus a demo-app-smart-contract-x.x.jar deployed in P6_DATA/lib
* See: https://github.com/amalto/solidity-jar-builder for build instructions.
*
* @import _QuorumImports
*/
def TESSERA1_ENCLAVE_KEY = 'BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo='
def TESSERA7_ENCLAVE_KEY = 'ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc='
def quorum = p6.web3quorum.build('http://localhost:22000')
log.info 'Quorum node: ' + quorum.web3ClientVersion().send().getWeb3ClientVersion()
def enclave = p6.web3quorum.buildEnclave(quorum, 'http://localhost', 9081)
log.info 'Enclave is available'
// load the credentials from the 7nodes example filesystem
def credentials = WalletUtils.loadCredentials('', '/Users/user/Documents/quorum-examples/examples/7nodes/keys/key1')
log.info 'Read credentials: ' + credentials
// Create a quorum transaction manager
// This object (used by the generated code) does the following:
// 1. sends the raw payload to tessera and retrieves the txHash
// 2. replace the transaction payload with the received txHash
// 3. create and sign a raw transaction using the provided credentials
// 4. invoke the eth_SendRawPrivateTransaction API to send the transaction to quorum
def qrtxm = p6.web3quorum.buildPrivateTransactionManager(quorum, enclave, TESSERA1_ENCLAVE_KEY, credentials, TESSERA7_ENCLAVE_KEY)
Example¶
/**
* Quorum example requires their 7nodes example running locally
* plus a demo-app-smart-contract-x.x.jar deployed in P6_DATA/lib
* See: https://github.com/amalto/solidity-jar-builder for build instructions.
*
* @import _QuorumImports
*/
def TESSERA1_ENCLAVE_KEY = 'BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo='
def TESSERA7_ENCLAVE_KEY = 'ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc='
def quorum = p6.web3quorum.build('http://localhost:22000')
log.info 'Quorum node: ' + quorum.web3ClientVersion().send().getWeb3ClientVersion()
def enclave = p6.web3quorum.buildEnclave(quorum, 'http://localhost', 9081)
log.info 'Enclave is available'
// load the credentials from the 7nodes example filesystem
def credentials = WalletUtils.loadCredentials('', '/Users/user/Documents/quorum-examples/examples/7nodes/keys/key1')
log.info 'Read credentials: ' + credentials
// Create a quorum transaction manager
// This object (used by the generated code) does the following:
// 1. sends the raw payload to tessera and retrieves the txHash
// 2. replace the transaction payload with the received txHash
// 3. create and sign a raw transaction using the provided credentials
// 4. invoke the eth_SendRawPrivateTransaction API to send the transaction to quorum
def qrtxm = p6.web3quorum.buildPrivateTransactionManager(quorum, enclave, TESSERA1_ENCLAVE_KEY, credentials, TESSERA7_ENCLAVE_KEY)
log.info 'Transaction manager available'
// Deploy the contract giving initial value of 42!
def ssContract = SimpleStorage.deploy(quorum, qrtxm, p6.web3quorum.ZERO_GAS_PROVIDER, BigInteger.valueOf(42)).send()
log.info 'Contract deployed, address:' + ssContract.getContractAddress()
log.info ' Transaction hash: ' + ssContract.getTransactionReceipt().get().getTransactionHash()
QuorumImports
import org.web3j.protocol.core.methods.response.Web3ClientVersion
import org.web3j.crypto.WalletUtils
import io.platform6.demo.sc.SimpleStorage
log.debug '---Starting---'