The RawTransactionManager module of Smilo.js provides access to private transaction APIs that require a connection to a Privacy Manager.
Example
const Web3 = require("web3");
const smilojs = require("Smilo-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 = smilojs.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
!!! info "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
txnParams- The transaction to sign and sendgasPrice:Number- Must always be 0 in Smilo networksgasLimit:Number- The amount of gas to use for the transactionto:String- (optional) The destination address of the message, left undefined for a contract-creation transactionvalue:Number- (optional) The value transferred for the transactiondata: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 transactionfrom-Object: Decrypted account objectnonce:Number- (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonceprivateFrom:String- When sending a private transaction, the sending party's base64-encoded public key to use. If not present and passingprivateFor, the default key as configured in theTransactionManageris usedprivateFor:List<String>- When sending a private transaction, an array of the recipients' base64-encoded public keysisPrivate:boolean- Is the transaction private
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
!!! info "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
txnParams- The transaction to sign and sendgasPrice:Number- Must always be 0 in Smilo networksgasLimit:Number- The amount of gas to use for the transactionto:String- (optional) The destination address of the message, left undefined for a contract-creation transactionvalue:Number- (optional) The value transferred for the transactiondata: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 transactionfrom-Object: Decrypted account objectnonce:Number- (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonceprivateFrom:String- When sending a private transaction, the sending party's base64-encoded public key to use. If not present and passingprivateFor, the default key as configured in theTransactionManageris usedprivateFor:List<String>- When sending a private transaction, an array of the recipients' base64-encoded public keysisPrivate:boolean- Is the transaction private
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
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
data:String- Hex encoded private transaction data (i.e. value ofdata/inputfield in the transaction)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
rawTransaction:String- RLP-encoded hex-format signed transactionprivateFor: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 Smilo v2.2.0+
storeRawRequestto encrypt the transactiondatatxnManager.storeRawRequest(data, from)- Replace
datafield of transaction withkeyfield fromstoreRawRequestresponse - Sign the transaction
- Mark the signed transaction as private with
setPrivatetxnManager.setPrivate(signedTx) - Send the signed transaction to Smilo with
sendRawRequesttxnManager.sendRawRequest(serializedTransaction, privateFor)
Other examples
The 7nodes-test directory in the Smilo.js project repo contains examples of Smilo.js usage. These scripts can be tested with a running 7nodes test network.
