Is it possible to use PrivateFor in the Azure Blockchain Workbench?

Linxight 61 Reputation points
2020-06-24T20:02:53.23+00:00

Since the Workbench uses Quorum, it should be possible to use PrivateFor in it to make private transactions. How is it possible to set up the PrivateFor parameter, and are there any good code examples for this?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,738 questions
0 comments No comments
{count} votes

Accepted answer
  1. AshokPeddakotla-MSFT 30,321 Reputation points
    2020-06-26T11:45:55.62+00:00

    @Linxight-8494

    Welcome to Q&A forum!

    AFAIK, it is not possible/currently not supported for workbench but on ABS you can use PrivateFor.

    Here is an example how you can do private transactions with Quorum: https://github.com/jpmorganchase/quorum-examples/tree/master/examples/7nodes#demonstrating-privacy

    Also, check how to connect to ABS transaction nodes: https://learn.microsoft.com/en-us/azure/blockchain/service/connect-geth

    Sample Code:

     a = eth.accounts[0]
     web3.eth.defaultAccount = a;
        
     // abi and bytecode generated from simplestorage.sol:
     // > solcjs --bin --abi simplestorage.sol
     var abi = [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initVal","type":"uint256"}],"payable":false,"type":"constructor"}];
        
     var bytecode = "0x6060604052341561000f57600080fd5b604051602080610149833981016040528080519060200190919050505b806000819055505b505b610104806100456000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632a1afcd914605157806360fe47b11460775780636d4ce63c146097575b600080fd5b3415605b57600080fd5b606160bd565b6040518082815260200191505060405180910390f35b3415608157600080fd5b6095600480803590602001909190505060c3565b005b341560a157600080fd5b60a760ce565b6040518082815260200191505060405180910390f35b60005481565b806000819055505b50565b6000805490505b905600a165627a7a72305820d5851baab720bba574474de3d09dbeaabc674a15f4dd93b974908476542c23f00029";
        
     var simpleContract = web3.eth.contract(abi);
     var simple = simpleContract.new(42, {from:web3.eth.accounts[0], data: bytecode, gas: 0x47b760, privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]}, function(e, contract) {
         if (e) {
             console.log("err creating contract", e);
         } else {
             if (!contract.address) {
                 console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");
             } else {
                 console.log("Contract mined! Address: " + contract.address);
                 console.log(contract);
             }
         }
     });
    

    Code is available here https://github.com/jpmorganchase/quorum-examples/blob/master/examples/7nodes/private-contract.js

    Hope this helps. Do let me know if you need further help.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful