All Products
Document Center

Send a private transaction using geth

Last Updated: Jan 17, 2019
  1. Start an interactive console to connect to a Quorum node, you can refer to document Setup geth interactive JavaScript console to build an interactive console

  2. Create an Ethereum account. If you have already created an Ethereum account on the node, you can use the existing account to complete the follow-up operation

    1. // create a account that use empty password
    2. var account = personal.newAccount("");
    3. // using an existing account in node
    4. // var account = eth.accounts[0]
    5. // unlock account for 300 seconds with empty password
    6. personal.unlockAccount(account, "", 300);
    7. // set it as default account
    8. web3.eth.defaultAccount = account;
  3. Specify the address of the private smart contract, the public key of the nodes participating in the private smart contract, and the ABI, and then initiate the call. You can refer to the steps in Deploy private contract to deploy smart contracts and get the address and ABI of the smart contract.

    Note: The ‘privateFor’ parameter for sending a private transaction must be consistent with the parameters for deploying the private smart contract, otherwise the smart contract will be inconsistent.

    1. // tx-mangager public key list; it should be same with the list that when your deploy the private contract
    2. var privateFor = ["WLyCI0x1NBdy2VI4IdmxGYhRP7PKGL6wD87iN5vKp3w="];
    3. // your private contract address that you want to call
    4. var address = "0x0000000";
    5. // your contarct ABI that address corresponds to
    6. 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"}];
    7. var contract = eth.contract(abi).at(address)
    8. // call get method of demo contract
    9. contract.get()
    10. // call set method of demo contract, and create a new private transaction
    11. contract.set(999, {from: account, privateFor: privateFor })