ื‘ืฆืข ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื‘-JPMorgan Quorum blockchain ื‘ืืžืฆืขื•ืช Web3

ื‘ืฆืข ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื‘-JPMorgan Quorum blockchain ื‘ืืžืฆืขื•ืช Web3

ืžึดื ื™ึธืŸ ื”ื•ื ื‘ืœื•ืงืฆ'ื™ื™ืŸ ืžื‘ื•ืกืก Ethereum ืฉืคื•ืชื— ืขืœ ื™ื“ื™ JPMorgan ื•ืœืื—ืจื•ื ื” ื”ืคืš ืœืคืœื˜ืคื•ืจืžืช ื”ืกืคืจื™ื ื”ืžื‘ื•ื–ืจื™ื ื”ืจืืฉื•ื ื” ื”ืžื•ืฆืขืช ืขืœ ื™ื“ื™ Microsoft Azure.

Quorum ืชื•ืžืš ื‘ืขืกืงืื•ืช ืคืจื˜ื™ื•ืช ื•ืฆื™ื‘ื•ืจื™ื•ืช ื•ื™ืฉ ืœื• ืžืงืจื™ ืฉื™ืžื•ืฉ ืžืกื—ืจื™ื™ื ืจื‘ื™ื.

ื‘ืžืืžืจ ื–ื” ื ื‘ื—ืŸ ืชืจื—ื™ืฉ ืื—ื“ ื›ื–ื” - ืคืจื™ืกืช ืจืฉืช ืคื ืงืกื™ื ืžื‘ื•ื–ืจืช ื‘ื™ืŸ ืกื•ืคืจืžืจืงื˜ ืœื‘ืขืœ ืžื—ืกืŸ ืขืœ ืžื ืช ืœืกืคืง ืžื™ื“ืข ืขื“ื›ื ื™ ืขืœ ื˜ืžืคืจื˜ื•ืจืช ื”ืžื—ืกืŸ.

ื”ืงื•ื“ ื”ืžืฉืžืฉ ื‘ืžื“ืจื™ืš ื–ื” ื ืžืฆื ื‘ ืžืื’ืจื™ื ื‘- GitHub.

ื”ืžืืžืจ ืžื›ืกื”:

  • ื™ืฆื™ืจืช ื—ื•ื–ื” ื—ื›ื;
  • ืคืจื™ืกื” ืฉืœ ืจืฉืช Quorum ื‘ืืžืฆืขื•ืช ืขืจืžืช ืฉืจืฉืจืช;
  • ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื‘ืงื•ื•ืจื•ื;
  • ืขืกืงืื•ืช ืคืจื˜ื™ื•ืช ื‘ืงื•ื•ืจื•ื.

ืœืฉื ื”ืžื—ืฉื”, ืื ื• ืžืฉืชืžืฉื™ื ื‘ืชืจื—ื™ืฉ ืœื ื™ื˜ื•ืจ ื˜ืžืคืจื˜ื•ืจื” ื‘ืžื—ืกื ื™ื ืฉืœ ื—ื‘ืจื™ ืจืฉืช Quorum ื‘ืชื•ืš ื”ืื™ื ื˜ืจื ื˜ ืฉืœ ื”ื“ื‘ืจื™ื (IoT).

ื”ึถืงืฉืึตืจ

ืงื‘ื•ืฆื” ืฉืœ ื—ื‘ืจื•ืช ืžื—ืกื ื™ื ืžืชืื—ื“ืช ื‘ืงื•ื ืกื•ืจืฆื™ื•ื ื›ื“ื™ ืœืื—ืกืŸ ื™ื—ื“ ืžื™ื“ืข ื•ืœื”ืคื•ืš ืชื”ืœื™ื›ื™ื ืœืื•ื˜ื•ืžื˜ื™ื™ื ื‘ื‘ืœื•ืงืฆ'ื™ื™ืŸ. ืœืฉื ื›ืš, ื—ื‘ืจื•ืช ื”ื—ืœื™ื˜ื• ืœื”ืฉืชืžืฉ ื‘ืงื•ื•ืจื•ื. ื‘ืžืืžืจ ื–ื” ื ืชื™ื™ื—ืก ืœืฉื ื™ ืชืจื—ื™ืฉื™ื: ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืขืกืงืื•ืช ืคืจื˜ื™ื•ืช.

ืขืกืงืื•ืช ื ื•ืฆืจื•ืช ืขืœ ื™ื“ื™ ืžืฉืชืชืคื™ื ืฉื•ื ื™ื ื›ื“ื™ ืœื™ืฆื•ืจ ืื™ื ื˜ืจืืงืฆื™ื” ืขื ื”ืงื•ื ืกื•ืจืฆื™ื•ื ืฉืืœื™ื• ื”ื ืฉื™ื™ื›ื™ื. ื›ืœ ืขืกืงื” ืคื•ืจืกืช ื—ื•ื–ื” ืื• ืงื•ืจืืช ืœืคื•ื ืงืฆื™ื” ื‘ื—ื•ื–ื” ื›ื“ื™ ืœื”ืขืœื•ืช ื ืชื•ื ื™ื ืœืจืฉืช. ืคืขื•ืœื•ืช ืืœื• ืžืฉื•ื›ืคืœื•ืช ืœื›ืœ ื”ืฆืžืชื™ื ื‘ืจืฉืช.

ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื–ืžื™ื ื•ืช ืœืฆืคื™ื™ื” ืขืœ ื™ื“ื™ ื›ืœ ืžืฉืชืชืคื™ ื”ืงื•ื ืกื•ืจืฆื™ื•ื. ืขืกืงืื•ืช ืคืจื˜ื™ื•ืช ืžื•ืกื™ืคื•ืช ืจื•ื‘ื“ ืฉืœ ืกื•ื“ื™ื•ืช ื•ื–ืžื™ื ื•ืช ืจืง ืœืžืฉืชืชืคื™ื ืฉื™ืฉ ืœื”ื ื–ื›ื•ื™ื•ืช ืœืขืฉื•ืช ื–ืืช.

ืขื‘ื•ืจ ืฉื ื™ ื”ืชืจื—ื™ืฉื™ื, ืื ื• ืžืฉืชืžืฉื™ื ื‘ืื•ืชื• ื—ื•ื–ื” ืœืฆื•ืจืš ื‘ื”ื™ืจื•ืช.

ื—ื•ื–ื” ื—ื›ื

ืœื”ืœืŸ ื—ื•ื–ื” ื—ื›ื ืคืฉื•ื˜ ืฉื ื•ืฆืจ ืขื‘ื•ืจ ื”ืชืจื—ื™ืฉ ืฉืœื ื•. ื™ืฉ ืœื• ืžืฉืชื ื” ืฆื™ื‘ื•ืจื™ temperature, ืฉื ื™ืชืŸ ืœืฉื ื•ืช ื‘ืืžืฆืขื•ืช set ื•ืœืงื‘ืœ ืœืคื™ ื”ืฉื™ื˜ื” get.

pragma solidity ^0.4.25;
contract TemperatureMonitor {
  int8 public temperature;
function set(int8 temp) public {
    temperature = temp;
  }
function get() view public returns (int8) {
    return temperature;
  }
}

ืขืœ ืžื ืช ืฉื”ื—ื•ื–ื” ื™ืขื‘ื•ื“ ืื™ืชื• web3.js, ื™ืฉ ืœืชืจื’ื ืื•ืชื• ืœืคื•ืจืžื˜ ABI ื•ืœืงื•ื“ ื‘ืชื™ื. ืฉื™ืžื•ืฉ ื‘ืคื•ื ืงืฆื™ื” formatContractืœื”ืœืŸ ืžืจื›ื™ื‘ ืืช ื”ื—ื•ื–ื” ื‘ืืžืฆืขื•ืช solc-js.

function formatContract() {
  const path = './contracts/temperatureMonitor.sol';
  const source = fs.readFileSync(path,'UTF8');
return solc.compile(source, 1).contracts[':TemperatureMonitor'];
}

ื”ื—ื•ื–ื” ืฉื”ื•ืฉืœื ื ืจืื” ื›ืš:

// interface
[ 
  { 
    constant: true,
    inputs: [],
    name: โ€˜getโ€™,
    outputs: [Array],
    payable: false,
    stateMutability: โ€˜viewโ€™,
    type: โ€˜functionโ€™ 
  },
  { 
    constant: true,
    inputs: [],
    name: โ€˜temperatureโ€™,
    outputs: [Array],
    payable: false,
    stateMutability: โ€˜viewโ€™,
    type: โ€˜functionโ€™ 
  },
  {
    constant: false,
    inputs: [Array],
    name: โ€˜setโ€™,
    outputs: [],
    payable: false,
    stateMutability: โ€˜nonpayableโ€™,
    type: โ€˜functionโ€™ 
  }
]

// bytecode
0x608060405234801561001057600080fd5b50610104806100206000396000f30060806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416636d4ce63c81146057578063adccea12146082578063faee13b9146094575b600080fd5b348015606257600080fd5b50606960ae565b60408051600092830b90920b8252519081900360200190f35b348015608d57600080fd5b50606960b7565b348015609f57600080fd5b5060ac60043560000b60c0565b005b60008054900b90565b60008054900b81565b6000805491810b60ff1660ff199092169190911790555600a165627a7a72305820af0086d55a9a4e6d52cb6b3967afd764ca89df91b2f42d7bf3b30098d222e5c50029

ื›ืขืช, ื›ืฉื”ื—ื•ื–ื” ืžื•ื›ืŸ, ื ืคืจื•ืก ืืช ื”ืจืฉืช ื ืคืจื•ืก ืืช ื”ื—ื•ื–ื”.

ืคืจื™ืกืช ืฆื•ืžืช

ื‘ืฆืข ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื‘-JPMorgan Quorum blockchain ื‘ืืžืฆืขื•ืช Web3

ืคืจื™ืกืช ืฆื•ืžืช ื™ื›ื•ืœื” ืœื”ื™ื•ืช ื“ื™ ืขืชื™ืจืช ืขื‘ื•ื“ื” ื•ื ื™ืชืŸ ืœื”ื—ืœื™ืฃ ืชื”ืœื™ืš ื–ื” ื‘ืืžืฆืขื•ืช ืฉื™ืจื•ืช ืขืจืžืช ืฉืจืฉืจืช.

ืœื”ืœืŸ ื”ืชื”ืœื™ืš ืœืคืจื™ืกืช ืจืฉืช Quorum ืขื ืงื•ื ืฆื ื–ื•ืก Raft ื•ืฉืœื•ืฉื” ืฆืžืชื™ื.

ืจืืฉื™ืช, ื‘ื•ืื• ื ื™ืฆื•ืจ ืคืจื•ื™ืงื˜ ื•ื ืงืจื ืœื• Quorum Project:

ื‘ืฆืข ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื‘-JPMorgan Quorum blockchain ื‘ืืžืฆืขื•ืช Web3

ื‘ื•ืื• ื ื™ืฆื•ืจ ืจืฉืช Quorum ืขื ืงื•ื ืฆื ื–ื•ืก Raft ื‘-Google Cloud Platform:

ื‘ืฆืข ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื‘-JPMorgan Quorum blockchain ื‘ืืžืฆืขื•ืช Web3

ื‘ื•ืื• ื ื•ืกื™ืฃ ืขื•ื“ ืฉื ื™ ืฆืžืชื™ื ืœืฆื•ืžืช ืฉื›ื‘ืจ ื ื•ืฆืจ ื›ื‘ืจื™ืจืช ืžื—ื“ืœ:

ื‘ืฆืข ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื‘-JPMorgan Quorum blockchain ื‘ืืžืฆืขื•ืช Web3

ืฉืœื•ืฉื” ืฆืžืชื™ื ืจืฆื™ื:

ื‘ืฆืข ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื‘-JPMorgan Quorum blockchain ื‘ืืžืฆืขื•ืช Web3

ื“ืฃ ืคืจื˜ื™ ื”ืฆื•ืžืช ืžืฆื™ื’ ืืช ื ืงื•ื“ืช ื”ืงืฆื” ืฉืœ ื”-RPC, ื”ืžืคืชื— ื”ืฆื™ื‘ื•ืจื™ ื•ื›ื•'.

ื‘ืฆืข ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื‘-JPMorgan Quorum blockchain ื‘ืืžืฆืขื•ืช Web3

ื”ืจืฉืช ืคืจื•ืกื”. ืขื›ืฉื™ื• ื‘ื•ืื• ื ืคืจื•ืก ื—ื•ื–ื™ื ื—ื›ืžื™ื ื•ื ื‘ืฆืข ืขืกืงืื•ืช ื‘ืืžืฆืขื•ืช web3.js.

ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช

ื”ึถืงืฉืึตืจ

ืœื˜ืžืคืจื˜ื•ืจืช ื”ืžื—ืกืŸ ื—ืฉื™ื‘ื•ืช ืจื‘ื” ื‘ื”ืคื—ืชืช ืขืœื•ื™ื•ืช, ื‘ืžื™ื•ื—ื“ ืขื‘ื•ืจ ืžื•ืฆืจื™ื ื”ืžื™ื•ืขื“ื™ื ืœืื—ืกื•ืŸ ื‘ื˜ืžืคืจื˜ื•ืจื•ืช ืžืชื—ืช ืœืืคืก.

ืขืœ ื™ื“ื™ ืžืชืŸ ืืคืฉืจื•ืช ืœื—ื‘ืจื•ืช ืœื—ืœื•ืง ืืช ื”ื˜ืžืคืจื˜ื•ืจื” ื”ื—ื™ืฆื•ื ื™ืช ืฉืœ ืžื™ืงื•ืžืŸ ื”ื’ื™ืื•ื’ืจืคื™ ื‘ื–ืžืŸ ืืžืช ื•ืœืชืขื“ ืื•ืชื” ื‘ืกืคืจ ื—ืฉื‘ื•ื ื•ืช ื‘ืœืชื™ ื ื™ืชืŸ ืœืฉื™ื ื•ื™, ืžืฉืชืชืคื™ ื”ืจืฉืช ืžืคื—ื™ืชื™ื ืขืœื•ื™ื•ืช ื•ื–ืžืŸ.

ื‘ืฆืข ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื‘-JPMorgan Quorum blockchain ื‘ืืžืฆืขื•ืช Web3

ื ื‘ืฆืข ืฉืœื•ืฉ ืžืฉื™ืžื•ืช, ื”ืžื•ืžื—ืฉื•ืช ื‘ืชืจืฉื™ื:

  1. ืื ื• ื ืคืจื•ืก ืืช ื”ื—ื•ื–ื” ื‘ืืžืฆืขื•ืช ืฆื•ืžืช 1:

    const contractAddress = await deployContract(raft1Node);
    console.log(`Contract address after deployment: ${contractAddress}`);

  2. ื”ื’ื“ืจ ืืช ื”ื˜ืžืคืจื˜ื•ืจื” ื‘ืืžืฆืขื•ืช ืฆื•ืžืช 2 ื‘-3 ืžืขืœื•ืช:

    const status = await setTemperature(raft2Node, contractAddress, 3);
    console.log(`Transaction status: ${status}`);

  3. ืฆื•ืžืช 3 ื™ืงื‘ืœื• ืžื™ื“ืข ืžื”ื—ื•ื–ื” ื”ื—ื›ื. ื”ื—ื•ื–ื” ื™ื—ื–ื™ืจ ืืช ื”ืขืจืš 3 ืžืขืœื•ืช:

    const temp = await getTemperature(raft3Node, contractAddress);
    console.log(โ€˜Retrieved contract Temperatureโ€™, temp);

    ืœืื—ืจ ืžื›ืŸ, ื ื‘ื—ืŸ ื›ื™ืฆื“ ืœื‘ืฆืข ืขืกืงื” ืฆื™ื‘ื•ืจื™ืช ื‘ืจืฉืช Quorum ื‘ืืžืฆืขื•ืช web3.js.

ืื ื• ื™ื•ื–ืžื™ื ืžื•ืคืข ื‘ืืžืฆืขื•ืช RPC ืขื‘ื•ืจ ืฉืœื•ืฉื” ืฆืžืชื™ื:

const raft1Node = new Web3(
 new Web3.providers.HttpProvider(process.env.RPC1), null, {
   transactionConfirmationBlocks: 1,
 },
);
const raft2Node = new Web3(
 new Web3.providers.HttpProvider(process.env.RPC2), null, {
   transactionConfirmationBlocks: 1,
 },
);
const raft3Node = new Web3(
 new Web3.providers.HttpProvider(process.env.RPC3), null, {
   transactionConfirmationBlocks: 1,
 },
);

ื‘ื•ืื• ื ืคืจื•ืก ืืช ื”ื—ื•ื–ื” ื”ื—ื›ื:

// returns the default account from the Web3 instance initiated previously
function getAddress(web3) {
  return web3.eth.getAccounts().then(accounts => accounts[0]);
}
// Deploys the contract using contract's interface and node's default address
async function deployContract(web3) {
  const address = await getAddress(web3);
// initiate contract with contract's interface
  const contract = new web3.eth.Contract(
    temperatureMonitor.interface
  );
return contract.deploy({
    // deploy contract with contract's bytecode
    data: temperatureMonitor.bytecode,
  })
  .send({
    from: address,
    gas: '0x2CD29C0',
  })
  .on('error', console.error)
  .then((newContractInstance) => {
    // returns deployed contract address
    return newContractInstance.options.address;
  });
}

web3.js ืžืกืคืง ืฉืชื™ ืฉื™ื˜ื•ืช ืœืื™ื ื˜ืจืืงืฆื™ื” ืขื ื”ื—ื•ื–ื”: call ะธ send.

ื‘ื•ืื• ื ืขื“ื›ืŸ ืืช ื˜ืžืคืจื˜ื•ืจืช ื”ื—ื•ื–ื” ืขืœ ื™ื“ื™ ื‘ื™ืฆื•ืข set ื‘ืฉื™ื˜ืช web3 send.

// get contract deployed previously
async function getContract(web3, contractAddress) {
  const address = await getAddress(web3);
return web3.eth.Contract(
    temperatureMonitor.interface,
    contractAddress, {
      defaultAccount: address,
    }
  );
}
// calls contract set method to update contract's temperature
async function setTemperature(web3, contractAddress, temp) {
  const myContract = await getContract(web3, contractAddress);
return myContract.methods.set(temp).send({}).then((receipt) => {
    return receipt.status;
  });
}

ืœืื—ืจ ืžื›ืŸ ืื ื• ืžืฉืชืžืฉื™ื ื‘ืฉื™ื˜ืช web3 call ื›ื“ื™ ืœืงื‘ืœ ืืช ื˜ืžืคืจื˜ื•ืจืช ื”ื—ื•ื–ื”. ืฉื™ืžื• ืœื‘ ืฉื”ืฉื™ื˜ื” call ืžื‘ื•ืฆืข ืขืœ ืฆื•ืžืช ืžืงื•ืžื™ ื•ื”ืขืกืงื” ืœื ืชื™ื•ื•ืฆืจ ื‘ื‘ืœื•ืงืฆ'ื™ื™ืŸ.

// calls contract get method to retrieve contract's temperature
async function getTemperature(web3, contractAddress) {
  const myContract = await getContract(web3, contractAddress);
return myContract.methods.get().call().then(result => result);
}

ืขื›ืฉื™ื• ืืชื” ื™ื›ื•ืœ ืœืจื•ืฅ public.js ื›ื“ื™ ืœืงื‘ืœ ืืช ื”ืชื•ืฆืื” ื”ื‘ืื”:

// Execute public script
node public.js
Contract address after deployment: 0xf46141Ac7D6D6E986eFb2321756b5d1e8a25008F
Transaction status: true
Retrieved contract Temperature 3

ืœืื—ืจ ืžื›ืŸ, ื ื•ื›ืœ ืœื”ืฆื™ื’ ืืช ื”ืขืจื›ื™ื ื‘-Quorum Explorer ื‘ื—ืœื•ื ื™ืช Chainstack, ื›ืคื™ ืฉืžื•ืฆื’ ืœื”ืœืŸ.

ื›ืœ ืฉืœื•ืฉืช ื”ืฆืžืชื™ื ืงื™ื™ืžื• ืื™ื ื˜ืจืืงืฆื™ื” ื•ื”ืขืกืงืื•ืช ืขื•ื“ื›ื ื•:

  1. ื”ืขืกืงื” ื”ืจืืฉื•ื ื” ืคืจืกื” ืืช ื”ื—ื•ื–ื”.
  2. ื”ืขืกืงื” ื”ืฉื ื™ื™ื” ืงื‘ืขื” ืืช ื˜ืžืคืจื˜ื•ืจืช ื”ื—ื•ื–ื” ืœ-3 ืžืขืœื•ืช.
  3. ื”ื˜ืžืคืจื˜ื•ืจื” ืžืชืงื‘ืœืช ื“ืจืš ืฆื•ืžืช ืžืงื•ืžื™, ื›ืš ืฉืœื ื ื•ืฆืจืช ืขืกืงื”.

ื‘ืฆืข ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื‘-JPMorgan Quorum blockchain ื‘ืืžืฆืขื•ืช Web3

ืขืกืงืื•ืช ืคืจื˜ื™ื•ืช

ื”ึถืงืฉืึตืจ

ื“ืจื™ืฉื” ื ืคื•ืฆื” ืฉืœ ืืจื’ื•ื ื™ื ื”ื™ื ื”ื’ื ืช ืžื™ื“ืข. ื›ื“ื•ื’ืžื”, ืฉืงื•ืœ ืชืจื—ื™ืฉ ืฉื‘ื• ืกื•ึผืคึผึถืจืžึทืจืงึถื˜ ืฉื•ื›ืจืช ื—ืœืœ ืžื—ืกืŸ ืœืื—ืกื•ืŸ ืคื™ืจื•ืช ื™ื ืžื ืคืจื“ ืžื•ึนื›ึตืจ:

  • ืžื•ึนื›ึตืจ ื‘ืืžืฆืขื•ืช ื—ื™ื™ืฉื ื™ IoT, ืงื•ืจื ืขืจื›ื™ ื˜ืžืคืจื˜ื•ืจื” ื›ืœ 30 ืฉื ื™ื•ืช ื•ืžืฉื“ืจ ืื•ืชื ืœืกื•ืคืจ ืžืจืงื˜;
  • ืขืจื›ื™ื ืืœื” ืฆืจื™ื›ื™ื ืœื”ื™ื•ืช ื–ืžื™ื ื™ื ื‘ืœื‘ื“ ืืœ ื”ืžื•ื›ืจ ะธ ืœืกื•ืคืจ ืžืจืงื˜, ืžืจื•ืฉืช ืขืœ ื™ื“ื™ ืงื•ื ืกื•ืจืฆื™ื•ื.

ื‘ืฆืข ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื‘-JPMorgan Quorum blockchain ื‘ืืžืฆืขื•ืช Web3

ื ืฉืœื™ื ืืช ืืจื‘ืข ื”ืžืฉื™ืžื•ืช ื”ืžื•ืฆื’ื•ืช ื‘ืชืจืฉื™ื ืœืžืขืœื”.

  • ืื ื• ืžืฉืชืžืฉื™ื ื‘ืื•ืชื ืฉืœื•ืฉื” ืฆืžืชื™ื ืžื”ืชืจื—ื™ืฉ ื”ืงื•ื“ื ื›ื“ื™ ืœื”ื“ื’ื™ื ืขืกืงืื•ืช ืคืจื˜ื™ื•ืช:
  • ืกื•ืคืจืžืจืงื˜ ืคื•ืจืก ื—ื•ื–ื” ื—ื›ื ืฉื”ื•ื ืคืจื˜ื™ ืกื•ึผืคึผึถืจืžึทืจืงึถื˜ ะธ ืžื•ึนื›ึตืจ.
  • ื”ืฆื“ ื”ืฉืœื™ืฉื™ ืื™ืŸ ืœื• ื–ื›ื•ืช ื’ื™ืฉื” ืœื—ื•ื–ื” ื”ื—ื›ื.

ื ื›ื ื” ืืช ื”ืฉื™ื˜ื•ืช get ะธ set ื‘ืฉื ืกื•ึผืคึผึถืจืžึทืจืงึถื˜ ะธ ืžื•ึนื›ึตืจ ืœื”ื“ื’ื™ื ืขืกืงื” ืคืจื˜ื™ืช ืฉืœ Quorum.

  1. ืื ื• ื ืคืจื•ืก ื—ื•ื–ื” ืคืจื˜ื™ ืขื‘ื•ืจ ื”ืžืฉืชืชืคื™ื ืกื•ืคืจืžืจืงื˜ ะธ ืžื•ึนื›ึตืจ ื“ืจืš ืžืฉืชืชืฃ ืกื•ืคืจืžืจืงื˜:

    const contractAddress = await deployContract(
    raft1Node,
    process.env.PK2,
    );
    console.log(`Contract address after deployment: ${contractAddress}`);

  2. ื‘ื•ืื• ื ืงื‘ืข ืืช ื”ื˜ืžืคืจื˜ื•ืจื” ืž ืฆื“ ืฉืœื™ืฉื™ (ืฆื•ืžืช ื—ื™ืฆื•ื ื™) ื•ืงื‘ืœ ืืช ืขืจืš ื”ื˜ืžืคืจื˜ื•ืจื”:

    // Attempts to set Contract temperature to 10, this will not mutate contract's temperature
    await setTemperature(
    raft3Node,
    contractAddress,
    process.env.PK1,
    10,
    );
    // This returns null
    const temp = await getTemperature(raft3Node, contractAddress);
    console.log(`[Node3] temp retrieved after updating contract from external nodes: ${temp}`);

  3. ื‘ื•ืื• ื ืงื‘ืข ืืช ื”ื˜ืžืคืจื˜ื•ืจื” ืž ืžื•ึนื›ึตืจ (ืฆื•ืžืช ืคื ื™ืžื™) ื•ืงื‘ืœ ืืช ืขืจืš ื”ื˜ืžืคืจื˜ื•ืจื”:

    ื”ื˜ืžืคืจื˜ื•ืจื” ื‘ืชืจื—ื™ืฉ ื–ื” ืืžื•ืจื” ืœื”ื—ื–ื™ืจ ืืช ื”ืขืจืš 12 ืžื”ื—ื•ื–ื” ื”ื—ื›ื. ืฉื™ืžื• ืœื‘ ืžื•ึนื›ึตืจ ื›ืืŸ ื™ืฉ ื’ื™ืฉื” ืžื•ืจืฉื™ืช ืœื—ื•ื–ื” ื”ื—ื›ื.

    // Updated Contract temperature to 12 degrees
    await setTemperature(
    raft2Node,
    contractAddress,
    process.env.PK1,
    12,
    );
    // This returns 12
    const temp2 = await getTemperature(raft2Node, contractAddress);
    console.log(`[Node2] temp retrieved after updating contract from internal nodes: ${temp2}`);

  4. ืื ื—ื ื• ืžืงื‘ืœื™ื ืืช ื”ื˜ืžืคืจื˜ื•ืจื” ืž ืฆื“ ืฉืœื™ืฉื™ (ืฆื•ืžืช ื—ื™ืฆื•ื ื™):

    ื‘ืฉืœื‘ 3 ื”ื˜ืžืคืจื˜ื•ืจื” ื ืงื‘ืขื” ืœ-12, ืื‘ืœ ื”ืฆื“ ื”ืฉืœื™ืฉื™ ืื™ืŸ ืœื• ื’ื™ืฉื” ืœื—ื•ื–ื” ื”ื—ื›ื. ืœื›ืŸ ืขืจืš ื”ื”ื—ื–ืจื” ื—ื™ื™ื‘ ืœื”ื™ื•ืช null.

    // This returns null
    const temp3 = await getTemperature(raft3Node, contractAddress);
    console.log(`[Node3] temp retrieved from external nodes after update ${temp}`);

    ืœืื—ืจ ืžื›ืŸ, ื ืกืชื›ืœ ืžืงืจื•ื‘ ืขืœ ื‘ื™ืฆื•ืข ืขืกืงืื•ืช ืคืจื˜ื™ื•ืช ื‘ืจืฉืช Quorum ืขื web3.js. ืžื›ื™ื•ื•ืŸ ืฉืจื•ื‘ ื”ืงื•ื“ ื–ื”ื” ืขื‘ื•ืจ ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช, ื ื“ื’ื™ืฉ ืจืง ืืช ื”ื—ืœืงื™ื ื”ืฉื•ื ื™ื ืขื‘ื•ืจ ืขืกืงืื•ืช ืคืจื˜ื™ื•ืช.

ืฉื™ืžื• ืœื‘ ืฉื”ื—ื•ื–ื” ืฉื”ื•ืขืœื” ืœืจืฉืช ืื™ื ื• ื ื™ืชืŸ ืœืฉื™ื ื•ื™, ื•ืœื›ืŸ ื™ืฉ ืœื”ืขื ื™ืง ื’ื™ืฉื” ืžื•ืจืฉื™ืช ืœืฆืžืชื™ื ื”ืžืชืื™ืžื™ื ืขืœ ื™ื“ื™ ื”ืคืขืœืช ื”ื—ื•ื–ื” ื”ืฆื™ื‘ื•ืจื™ ื‘ื–ืžืŸ ืคืจื™ืกืช ื”ื—ื•ื–ื”, ื•ืœื ืœืื—ืจ ืžื›ืŸ.

async function deployContract(web3, publicKey) {
  const address = await getAddress(web3);
  const contract = new web3.eth.Contract(
    temperatureMonitor.interface,
  );
return contract.deploy({
    data: temperatureMonitor.bytecode,
  })
  .send({
    from: address,
    gas: โ€˜0x2CD29C0โ€™, 
    // Grant Permission to Contract by including nodes public keys
    privateFor: [publicKey],
  })
  .then((contract) => {
    return contract.options.address;
  });
}

ืขืกืงืื•ืช ืคืจื˜ื™ื•ืช ืžื‘ื•ืฆืขื•ืช ื‘ืื•ืคืŸ ื“ื•ืžื” - ืขืœ ื™ื“ื™ ื”ื›ืœืœืช ื”ืžืคืชื— ื”ืฆื™ื‘ื•ืจื™ ืฉืœ ื”ืžืฉืชืชืคื™ื ื‘ื–ืžืŸ ื”ื‘ื™ืฆื•ืข.

async function setTemperature(web3, contractAddress, publicKey, temp) {
  const address = await getAddress(web3);
  const myContract = await getContract(web3, contractAddress);
return myContract.methods.set(temp).send({
    from: address,
    // Grant Permission by including nodes public  keys
    privateFor: [publicKey],
  }).then((receipt) => {
    return receipt.status;
  });
}

ืขื›ืฉื™ื• ืื ื—ื ื• ื™ื›ื•ืœื™ื ืœืจื•ืฅ private.js ืขื ื”ืชื•ืฆืื•ืช ื”ื‘ืื•ืช:

node private.js
Contract address after deployment: 0x85dBF88B4dfa47e73608b33454E4e3BA2812B21D
[Node3] temp retrieved after updating contract from external nodes: null
[Node2] temp retrieved after updating contract from internal nodes: 12
[Node3] temp retrieved from external nodes after update null

ืกื™ื™ืจ ื”ืงื•ื•ืจื•ื ื‘-Chainstack ื™ืฆื™ื’ ืืช ื”ื“ื‘ืจื™ื ื”ื‘ืื™ื:

  • ืคืจื™ืกืช ื”ื—ื•ื–ื” ืžื”ืžืฉืชืชืฃ ืกื•ืคืจืžืจืงื˜;
  • ื”ื’ืฉืžื” SetTemperature ืž ืฆื“ ืฉืœื™ืฉื™;
  • ื”ื’ืฉืžื” SetTemperature ืžืžืฉืชืชืฃ ืžื•ึนื›ึตืจ.

ื‘ืฆืข ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื‘-JPMorgan Quorum blockchain ื‘ืืžืฆืขื•ืช Web3

ื›ืคื™ ืฉืืชื” ื™ื›ื•ืœ ืœืจืื•ืช, ืฉืชื™ ื”ืขืกืงืื•ืช ื”ื•ืฉืœืžื•, ืื‘ืœ ืจืง ื”ืขืกืงื” ืžื”ืžืฉืชืชืฃ ืžื•ึนื›ึตืจ ืขื“ื›ืŸ ืืช ื”ื˜ืžืคืจื˜ื•ืจื” ื‘ื—ื•ื–ื”. ืœืคื™ื›ืš, ืขืกืงืื•ืช ืคืจื˜ื™ื•ืช ืžืกืคืงื•ืช ืื™-ืฉื™ื ื•ื™, ืืš ื™ื—ื“ ืขื ื–ืืช ืื™ื ืŸ ื—ื•ืฉืคื•ืช ื ืชื•ื ื™ื ืœืฆื“ ืฉืœื™ืฉื™.

ืžืกืงื ื”

ื‘ื“ืงื ื• ืžืงืจื” ืฉื™ืžื•ืฉ ืžืกื—ืจื™ ืขื‘ื•ืจ Quorum ื›ื“ื™ ืœืกืคืง ืžื™ื“ืข ื˜ืžืคืจื˜ื•ืจื” ืขื“ื›ื ื™ ื‘ืžื—ืกืŸ ืขืœ ื™ื“ื™ ืคืจื™ืกืช ืจืฉืช ื‘ื™ืŸ ืฉื ื™ ื’ื•ืจืžื™ื - ืกื•ืคืจืžืจืงื˜ ื•ื‘ืขืœ ืžื—ืกืŸ.

ื”ืจืื™ื ื• ื›ื™ืฆื“ ื ื™ืชืŸ ืœืฉืžื•ืจ ืžื™ื“ืข ื˜ืžืคืจื˜ื•ืจื” ืขื“ื›ื ื™ ื‘ืืžืฆืขื•ืช ืขืกืงืื•ืช ืฆื™ื‘ื•ืจื™ื•ืช ื•ืคืจื˜ื™ื•ืช ื›ืื—ื“.

ื™ื›ื•ืœื™ื ืœื”ื™ื•ืช ื”ืจื‘ื” ืชืจื—ื™ืฉื™ื ืฉืœ ื™ื™ืฉื•ืžื™ื, ื•ื›ืคื™ ืฉืืชื” ื™ื›ื•ืœ ืœืจืื•ืช, ื–ื” ื‘ื›ืœืœ ืœื ืงืฉื”.

ื ืกื”, ื ืกื” ืœื”ืจื—ื™ื‘ ืืช ื”ืกืงืจื™ืคื˜ ืฉืœืš. ื™ืชืจ ืขืœ ื›ืŸ, ืชืขืฉื™ื™ืช ื˜ื›ื ื•ืœื•ื’ื™ื™ืช ื”ื‘ืœื•ืงืฆ'ื™ื™ืŸ ื™ื›ื•ืœ ืœื’ื“ื•ืœ ื›ืžืขื˜ ืคื™ ืขืฉืจื” ืขื“ 2024.

ืžืงื•ืจ: www.habr.com

ื”ื•ืกืคืช ืชื’ื•ื‘ื”