Skip to content
You are reading GoQuorum development version documentation and some displayed features may not be available in the stable release. You can switch to stable version using the version box at screen bottom.

Updated on September 15, 2021

web3js-quorum client library

The web3js-quorum library adds a property to your web3 instance by extending web3. Use the library to create and send RLP-encoded transactions using JSON-RPC.

The web3js-quorum library replaces the deprecated quorum.js and web3js-eea libraries, and includes all the features of both libraries.

Important

web3js-quorum supports GoQuorum JSON-RPC over HTTP only.

Only the enclave connection can be configured over TLS.

Information

If migrating to web3js-quorum, then update your Javascript code as indicated in the following examples.

Read the migration guide for more information about updating your code.

Prerequisites

Add web3js-quorum to project

npm install web3js-quorum

Initialize the web3js-quorum client

Initialize your client where:

  • <GoQuorum JSON-RPC HTTP endpoint> is the JSON-RPC HTTP endpoint of your GoQuorum node.
  • <Enclave IPC Path> is the enclave IPC Unix socket path.
  • <Enclave Private URL> is the enclave HTTP endpoint.
  • <enclave key file path> is the enclave public key file path (see Tessera keys documentation).
  • <enclave TLS cert file path> is the enclave TLS client certificate file path (see Tessera TLS documentation).
  • <enclave TLS CA cert file path> is the enclave TLS certification authority (CA) certificate file path (see Tessera TLS documentation).

Example connection

const Web3 = require("web3");
const Web3Quorum = require("web3js-quorum");
const fs = require('fs');

const isQuorum = true;
const keyFileBuffer = fs.readFileSync("<enclave key file path>");
const certFileBuffer = fs.readFileSync("<enclave TLS cert file path>");
const caCertFileBuffer = fs.readFileSync("<enclave TLS CA cert file path>");
const enclaveOptions = {
  ipcPath: "<Enclave IPC Path>",
  privateUrl: "<Enclave Private URL>",
  tlsSettings: {
    key: keyFileBuffer,
    clcert: certFileBuffer,
    cacert: caCertFileBuffer,
    allowInsecure: true | false
  }
};

const web3 = new Web3Quorum(new Web3("<GoQuorum JSON-RPC HTTP endpoint>"),
  enclaveOptions, isQuorum);

Important

IPC and HTTP are mutually exclusive. Choose one or the other depending on your needs.

const Web3 = require("web3");
const Web3Quorum = require("web3js-quorum");

const isQuorum = true;
const enclaveOptions = {
  ipcPath: "unix:/tmp/enclave.ipc"
};

const web3 = new Web3Quorum(new Web3("http://localhost:8545"),
  enclaveOptions, isQuorum);

Important

If IPC is enabled with ipcPath, then HTTP privateUrl and TLS options will be ignored.

const Web3 = require("web3");
const Web3Quorum = require("web3js-quorum");

const isQuorum = true;
const enclaveOptions = {
  privateUrl: "http://localhost:9081"
};

const web3 = new Web3Quorum(new Web3("http://localhost:8545"),
  enclaveOptions, isQuorum);

Important

If HTTP is enabled with privateUrl, then ipcPath options should not be used.

const Web3 = require("web3");
const Web3Quorum = require("web3js-quorum");
const fs = require('fs');

const isQuorum = true;
const keyFileBuffer = fs.readFileSync("./cert.key");
const certFileBuffer = fs.readFileSync("./cert.pem");
const caCertFileBuffer = fs.readFileSync("./ca-cert.pem");

const enclaveOptions = {
  privateUrl: "https://localhost:9081",
  tlsSettings: {
    key: keyFileBuffer,
    clcert: certFileBuffer,
    cacert: caCertFileBuffer,
    allowInsecure: false
  }
};

const web3 = new Web3Quorum(new Web3("http://localhost:8545"),
  enclaveOptions, isQuorum);

Important

  • allowInsecure: false forces the private transaction manager’s certificate to be verified.

    Setting allowInsecure: true disables the private transaction manager’s certificate verification and allows self-signed certificates.

  • If HTTPS is enabled with privateUrl and TLS options, then ipcPath options should not be used.

Deploying a contract with generateAndSendRawTransaction

To deploy a private contract, you need the contract binary. You can use Solidity to get the contract binary.

Deploying a contract with web3.priv.generateAndSendRawTransaction

const contractOptions = {
  data: `0x123`, // contract binary
  privateFrom: "tesseraNode1PublicKey",
  privateFor: ["tesseraNode3PublicKey"],
  privateKey: "goquorumNode1PrivateKey"
};
return web3.priv.generateAndSendRawTransaction(contractOptions);

web3.priv.generateAndSendRawTransaction(contractOptions) returns the transaction hash. To get the private transaction receipt, use web3.priv.waitForTransactionReceipt(txHash).

web3js-quorum methods

For more information about the web3js-quorum methods, see the web3js-quorum reference documentation.

ConsenSys has acquired Quorum from J.P. Morgan. Please read the FAQ.
Questions or feedback? You can discuss issues and obtain free support on GoQuorum Slack channel.
For paid professional support by ConsenSys, contact us at quorum@consensys.net.