Updated 2019-10-24

web3js-eea

Use the web3.js-eea library to create and send private transactions.

Options Parameter

The Options parameter has the following properties:

createPrivacyGroup

Creates privacy group for Hyperledger Besu privacy.

Parameters

Transaction options

name : string - Name of the privacy group. Optional.

description : string - Name of the privacy group. Optional.

Returns

string : Privacy group ID

Example

const createPrivacyGroup = () => {
  const contractOptions = {
    addresses: [orion.node1.publicKey, orion.node2.publicKey],
    name: "Privacy Group A",
    description: "Members of Group A"
  };
  return web3.eea.createPrivacyGroup(contractOptions).then(result => {
    console.log(`The privacy group created is:`, result);
    return result;
  });
};

deletePrivacyGroup

Deletes privacy group.

Parameters

Transaction options

Returns

string : Privacy group ID

Example

const deletePrivacyGroup = givenPrivacyGroupId => {
  const contractOptions = {
    privacyGroupId: givenPrivacyGroupId
  };
  return web3.eea.deletePrivacyGroup(contractOptions).then(result => {
    console.log(`The privacy group deleted is:`, result);
    return result;
  });
};

findPrivacyGroup

Finds privacy groups containing only the specified members.

Parameters

Transaction options

Returns

array of objects : Privacy groups containing only the specified members.

Example

const findPrivacyGroup = () => {
  const contractOptions = {
    addresses: [orion.node1.publicKey, orion.node2.publicKey]
  };
  return web3.eea.findPrivacyGroup(contractOptions).then(result => {
    console.log(`The privacy groups found are:`, result);
    return result;
  });
};

generatePrivacyGroup

Generates the privacy group ID for EEA privacy. The privacy group ID is the RLP-encoded privateFor and privateFrom keys.

Parameters

Transaction options

Returns

string : Privacy group ID

Example

const privacyGroupId = web3.eea.generatePrivacyGroup({
  privateFrom: "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=",
  privateFor: ["Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs="]
});

getMarkerTransaction

Gets the privacy marker transaction transaction receipt.

Parameters

txHash - string : Transaction hash of the private transaction

retries - int : Maximum number of attempts to get the private marker transaction receipt

delay - int : Delay between retries in milliseconds

Returns

Privacy marker transaction receipt

Example

const privateMarkerTransacion = web3.eea.getMarkerTransaction("0x9c41b3d44ed73511c82a9e2b1ef581eb797475c82f318ca2802358d3ba4a8274", 5, 100);

getTransactionCount

Returns the number of transactions sent from the specified address for the privacy group.

Parameters

Transaction options

Returns

int : Transaction count for that account (privateKey) and privacy group

Example

return web3.eea
   .getTransactionCount({
   privateKey: besu.node1.privateKey,
   privateFrom: orion.node1.publicKey,
   privateFor: [orion.node2.publicKey],
})

getTransactionReceipt

Gets the private transaction receipt using priv_getTransactionReceipt.

Parameters

txHash - string : Transaction hash of the private transaction

enclavePublicKey - string : privateFrom key for the transaction

retries - int : Optional. Maximum number of attempts to get the private marker transaction receipt. Default is 300.

delay - int : Optional. Delay between retries in milliseconds. Default is 1000.

Returns

Private transaction receipt

Example

const privateTxReceipt = web3.eea.getTransactionReceipt("0x9c41b3d44ed73511c82a9e2b1ef581eb797475c82f318ca2802358d3ba4a8274", "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=");

sendRawTransaction

Signs and sends a RLP-encoded private transaction to Besu using eea_sendRawTransaction.

sendRawTransaction supports EEA-compliant privacy using privateFor, or Besu-extended privacy using privacyGroupId.

Parameters

Transaction options

Returns

string : Transaction hash of the privacy marker transaction

Besu-extended Privacy

const createPrivateEmitterContract = privacyGroupId => {
  const contractOptions = {
    data: `0x${binary}`,
    privateFrom: orion.node1.publicKey,
    privacyGroupId,
    privateKey: besu.node1.privateKey
  };
  return web3.eea.sendRawTransaction(contractOptions);
};
const functionCall = {
   to: address,
   data: functionAbi.signature,
   privateFrom,
   privacyGroupId,
   privateKey
};
return web3.eea.sendRawTransaction(functionCall);

EEA-compliant Privacy

const createPrivateEmitterContract = () => {
  const contractOptions = {
     data: `0x${binary}`,
     privateFrom: orion.node1.publicKey,
     privateFor: [orion.node2.publicKey],
     privateKey: besu.node1.privateKey
  };
  return web3.eea.sendRawTransaction(contractOptions);
};
const functionCall = {
  to: address,
  data: functionAbi.signature + functionArgs,
  privateFrom: orion.node1.publicKey,
  privateFor: [orion.node2.publicKey],
  privateKey: besu.node1.privateKey
};
return web3.eea.sendRawTransaction(functionCall);