Skip to content

RawTransactionManager API

The RawTransactionManager module of quorum.js provides access to private transaction APIs that require a connection to a Privacy Manager.

Example

const Web3 = require("web3");
const quorumjs = require("quorum-js");

const web3 = new Web3("http://localhost:22000");

const tlsOptions = {
    key: fs.readFileSync("./cert.key"),
    clcert: fs.readFileSync("./cert.pem"),
    cacert: fs.readFileSync("./cacert.pem"),
    allowInsecure: false
};
const enclaveOptions = {
    privateUrl: "http://localhost:9081",
    tlsSettings: tlsOptions
};

const txnMngr = quorumjs.RawTransactionManager(web3, enclaveOptions);

txnMngr.sendRawTransaction(args);

Parameters

param type required description
web3 Object yes web3 instance
enclaveOptions Object yes Privacy Manager connection configuration - see enclaveOptions

enclaveOptions

param type required description
privateUrl String yes (unless ipcPath is provided) Tessera ThirdParty server url (if using the Constellation Privacy Manager use ipcPath instead)
ipcPath String no path to Privacy Manager .ipc socket file, privateUrl is preferred
tlsSettings Object no TLS configuration for HTTPS Privacy Manager connections - see tlsSettings

tlsSettings

param type required description
key String no client private key as byte string
clcert String no client certificate (signed/unsigned) as byte string
cacert String no CA certificate as byte string
allowInsecure boolean no do not verify the Privacy Manager’s certificate (can be used to allow self-signed certificates)

Methods

sendRawTransaction

If using Constellation

Constellation privacy managers do not support this method. Use sendRawTransactionViaSendAPI instead.

txnMngr.sendRawTransaction(txnParams);
Calls Tessera’s ThirdParty /storeraw API, replaces the data field in txnParams with the response (i.e. encrypted-payload hash), signs the transaction with the from account defined in txnParams, marks the transaction as private, RLP encodes the transaction in hex format, and submits the signed transaction to the blockchain with eth_sendRawPrivateTransaction.

Parameters

  1. txnParams - The transaction to sign and send
    • gasPrice: Number - Must always be 0 in Quorum networks
    • gasLimit: Number - The amount of gas to use for the transaction
    • to: String - (optional) The destination address of the message, left undefined for a contract-creation transaction
    • value: Number - (optional) The value transferred for the transaction
    • data: String - (optional) Either a byte string containing the associated data of the message, or the initialisation code (bytecode) in the case of a contract-creation transaction
    • from - Object: Decrypted account object
    • nonce: Number - (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce
    • privateFrom: String - When sending a private transaction, the sending party’s base64-encoded public key to use. If not present and passing privateFor, the default key as configured in the TransactionManager is used
    • privateFor: List<String> - When sending a private transaction, an array of the recipients’ base64-encoded public keys
    • isPrivate: boolean - Is the transaction private
  2. Function - (optional) If you pass a callback the HTTP request is made asynchronous.

Returns

A promise that resolves to the transaction receipt if the transaction was sent successfully, else rejects with an error.

sendRawTransactionViaSendAPI

If using Tessera

Tessera privacy managers support sendRawTransaction which should be used instead. sendRawTransactionViaSendAPI requires exposing the Q2T server to the js app. Ideally only the ThirdParty server should be exposed to such applications.

txnMngr.sendRawTransactionViaSendAPI(txnParams);

Calls Privacy Manager’s /send API to encrypt txn data and send to all participant Privacy Manager nodes, replaces data field in txnParams with response (i.e. encrypted-payload hash), signs the transaction with the from account defined in txnParams, marks the transaction as private, and submits the signed transaction to the blockchain with eth_sendRawTransaction.

Parameters

  1. txnParams - The transaction to sign and send
    • gasPrice: Number - Must always be 0 in Quorum networks
    • gasLimit: Number - The amount of gas to use for the transaction
    • to: String - (optional) The destination address of the message, left undefined for a contract-creation transaction
    • value: Number - (optional) The value transferred for the transaction
    • data: String - (optional) Either a byte string containing the associated data of the message, or the initialisation code (bytecode) in the case of a contract-creation transaction
    • from - Object: Decrypted account object
    • nonce: Number - (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce
    • privateFrom: String - When sending a private transaction, the sending party’s base64-encoded public key to use. If not present and passing privateFor, the default key as configured in the TransactionManager is used
    • privateFor: List<String> - When sending a private transaction, an array of the recipients’ base64-encoded public keys
    • isPrivate: boolean - Is the transaction private
  2. Function - (optional) If you pass a callback the HTTP request is made asynchronous.

Returns

A promise that resolves to the transaction receipt if the transaction was sent successfully, else rejects with an error.

setPrivate

txnMngr.setPrivate(rawTransaction);
Marks a signed transaction as private by changing the value of v to 37 or 38.

Parameters

  1. rawTransaction: String - RLP-encoded hex-format signed transaction

Returns

Updated RLP-encoded hex-format signed transaction

storeRawRequest

txnMngr.storeRawRequest(data, privateFrom);
Calls Tessera’s ThirdParty /storeraw API to encrypt the provided data and store in preparation for a eth_sendRawPrivateTransaction.

Parameters

  1. data: String - Hex encoded private transaction data (i.e. value of data/input field in the transaction)
  2. privateFrom: String - Sending party’s base64-encoded public key

Returns

A promise that resolves to the hex-encoded hash of the encrypted data (key field) that should be used to replace the data field of a transaction if externally signing.

sendRawRequest

txnMngr.sendRawRequest(rawTransaction, privateFor);
Call eth_sendRawPrivateTransaction, sending the signed transaction to the recipients specified in privateFor.

Parameters

  1. rawTransaction: String - RLP-encoded hex-format signed transaction
  2. privateFor: List<String> - List of the recipients’ base64-encoded public keys

Returns

A promise that resolves to the transaction receipt if the transaction was sent successfully, else rejects with an error.

Examples

Externally signing and sending a private tx

Info

This is not supported by Constellation and requires Quorum v2.2.0+

Code sample.

  1. storeRawRequest to encrypt the transaction data
    txnManager.storeRawRequest(data, from)
    
  2. Replace data field of transaction with key field from storeRawRequest response
  3. Sign the transaction
  4. Mark the signed transaction as private with setPrivate
    txnManager.setPrivate(signedTx)
    
  5. Send the signed transaction to Quorum with sendRawRequest
     txnManager.sendRawRequest(serializedTransaction, privateFor)
    

Other examples

The 7nodes-test directory in the quorum.js project repo contains examples of quorum.js usage. These scripts can be tested with a running 7nodes test network.