title | description | sidebar_position | tags | |
---|---|---|---|---|
Use the web3js-quorum library |
web3js-quorum client library |
8 |
|
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
:::caution
Tessera-based privacy is deprecated in Besu version 24.12.0 and later. Please read this blog post for more context on the rationale behind this decision as well as alternative options.
:::
web3js-quorum is an Ethereum JavaScript library extending web3.js that adds support for Besu-specific JSON-RPC APIs and features. Use the library to create and send RLP-encoded transactions using JSON-RPC.
:::caution important web3js-quorum supports JSON-RPC over HTTP only. :::
:::note
web3js-quorum includes all quorum.js and web3js-eea features.
If migrating to web3js-quorum, update your JavaScript code as indicated in the following examples.
Read the migration guide for more information about updating your code.
:::
npm install web3js-quorum
Initialize your client where <JSON-RPC HTTP endpoint>
is the JSON-RPC HTTP endpoint of your
Besu node.
Specified by the --rpc-http-host
and --rpc-http-port
command
line options.
const { Web3 } = require("web3");
const Web3Quorum = require("web3js-quorum");
const web3 = new Web3Quorum(new Web3("<JSON-RPC HTTP endpoint>"));
const { Web3 } = require("web3");
const Web3Quorum = require("web3js-quorum");
const web3 = new Web3Quorum(new Web3("http://localhost:8545"));
:::note
When migrating from web3js-eea to web3js-quorum, use Web3Quorum
. The constructor doesn't require the chain ID anymore. Chain ID is automatically retrieved from the chain using the specified JSON-RPC HTTP endpoint.
:::
To deploy a private contract, you need the contract binary. You can use Solidity to get the contract binary.
const contractOptions = {
data: `0x123`, // contract binary
privateFrom: "tesseraNode1PublicKey",
privateFor: ["tesseraNode3PublicKey"],
privateKey: "besuNode1PrivateKey",
};
return web3.priv.generateAndSendRawTransaction(contractOptions);
web3.priv.generateAndSendRawTransaction(contractOptions)
returns the transaction hash. To get the private transaction receipt, use web3.priv.waitForTransactionReceipt(txHash)
.
For more information about the web3js-quorum methods, see the web3js-quorum reference documentation.