Deprecated notice Consortium networks have been deprecated. This guide is for historical reference.
GoQuorum
To interact with your Quorum network, you must install a GoQuorum client.
Go installation To be able to install GoQuorum, you must install Go first. See Go: Getting Started .
Having installed Go, install GoQuorum .
With GoQuorum installed, you can connect to the Quorum nodes with the geth attach
command:
where ENDPOINT — your node HTTPS endpoint
See View node access details .
Example:
Key-protected
Password-protected
geth attach https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d
Invoke any methods from Web3 JavaScript API .
The example below demonstrates how to get the current block number:
> web3 . eth . blockNumber
518973
JSON-RPC API
Interact with your Quorum network using:
Use curl or Postman .
The example below demonstrates how to get basic network information:
Key-protected
Password-protected
$ curl -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":2}' \
https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d
{"jsonrpc":"2.0","id":2,"result":"0x4"}
Truffle
Configure Truffle Suite to deploy contracts to your Quorum network.
Install Truffle Suite and create a project
Recommended version Use Truffle >= 5.0.14 which has complete Quorum support with privacy features.
Install HDWalletProvider
HDWalletProvider is Truffle’s separate npm package used to sign transactions.
Run:
npm install @truffle/hdwallet-provider
Create a new environment in truffle-config.js
with:
HDWalletProvider
Your Quorum network running with Chainstack
const HDWalletProvider = require ( "@truffle/hdwallet-provider" );
const mnemonic = "word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12 word13 word14 word15" ;
module . exports = {
chainstack: {
provider : () => new HDWalletProvider ( mnemonic , "ENDPOINT" ),
network_id: "*" ,
gasPrice: 0 ,
gas: 4500000 ,
type: "quorum"
}
}
};
where
chainstack
— any network name that you will pass to the truffle migrate --network
command.
HDWalletProvider
— Truffle’s custom provider to sign transactions
mnemonic
— your mnemonic that generates your accounts. You can also generate a mnemonic online with Mnemonic Code Converter . Make sure you generate a 15 word mnemonic.
ENDPOINT — your Quorum node HTTPS endpoint. See View node access details .
network_id
— your Quorum network ID. See Default network ID . You can set it to *
for any.
gasPrice
— the setting must be 0
for the Quorum network.
gas
— the setting must be the default 4500000
for the Quorum network.
type
— the setting must be quorum
to instruct Truffle for the Quorum network deployment.
Example:
Key-protected
Password-protected
const HDWalletProvider = require("@truffle/hdwallet-provider");
const mnemonic = "word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12 word13 word14 word15";
module.exports = {
networks: {
chainstack: {
provider: () => new HDWalletProvider(mnemonic, "https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d"),
network_id: "*",
gasPrice: 0,
gas: 4500000,
type: "quorum"
}
}
};
Run truffle migrate --network chainstack
and Truffle will deploy using Chainstack
web3.js
Build DApps using web3.js and Quorum nodes deployed with Chainstack.
Install web3.js .
Use the HttpProvider
object to connect to your node HTTPS endpoint.
const Web3 = require ( 'web3' );
const web3 = new Web3 ( new Web3 . providers . HttpProvider ( 'ENDPOINT' ));
where
ENDPOINT — your node HTTPS endpoint
USERNAME — your Quorum node access username
PASSWORD — your Quorum node access password
Example to get the latest block number:
Key-protected
Password-protected
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider('https://nd-123-456- 789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d'));
web3.eth.getBlockNumber().then(console.log);
Build DApps using web3j and Quorum nodes deployed with Chainstack.
Use the HttpService
object to connect to your node HTTPS endpoint.
Example to get the latest block number:
package get L atest B lock;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.methods.response.EthBlock;
import org.web3j.protocol.exceptions.ClientConnectionException;
import org.web3j.protocol.http.HttpService;
import okhttp3.Authenticator;
import okhttp3.Credentials;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Route;
public final class App {
private static final String USERNAME = "USERNAME" ;
private static final String PASSWORD = "PASSWORD" ;
private static final String ENDPOINT = "ENDPOINT" ;
public static void main ( String [] args ) {
try {
OkHttpClient . Builder clientBuilder = new OkHttpClient. Builder ();
clientBuilder . authenticator ( new Authenticator () {
@ Override public Request authenticate ( Route route , Response response ) throws IOException {
String credential = Credentials . basic (USERNAME, PASSWORD);
return response . request (). newBuilder (). header ( "Authorization" , credential). build ();
}
});
HttpService service = new HttpService (ENDPOINT, clientBuilder . build (), false );
Web3j web3 = Web3j . build (service);
EthBlock . Block latestBlock = web3 . ethGetBlockByNumber ( DefaultBlockParameterName . LATEST , false ). send (). getBlock ();
System . out . println ( "Latest Block: #" + latestBlock . getNumber ());
} catch ( IOException | ClientConnectionException ex ) {
Logger . getLogger ( App . class . getName ()). log ( Level . SEVERE , null , ex);
}
}
}
where
ENDPOINT — your node HTTPS endpoint
USERNAME — your node access username
PASSWORD — your node access password
See also the full code on GitHub .