concept MPC in category blockchain

appears as: MPC, MPC, The MPC
Blockchain in Action

This is an excerpt from Manning's book Blockchain in Action.

  • Instead of cashing these small payments every time a bin of plastic garbage is collected and incurring fees, the worker waits until the last bin of the day and then receives the payment through one on-chain Tx. By design, this single Tx request is for the value of the last micropayment because it holds the accumulated value.
  • For utility functions that convert wei to ether
  • Listing 7.2 app.js

    App = {
        web3: null,
        contracts: {},
         url:'http://127.0.0.1:7545',                                     #1
         network_id:5777,             
        ...                                
        init: function() {
          return App.initWeb3();
        },
     
        initWeb3: function() {         
            ...
            App.web3 = new Web3(App.url);                                 #2
          }
          return App.initContract();  
        },
     
        initContract: function() {   
          ...     
            App.contracts.Payment = new App.web3.eth.Contract(data.abi,      
                       data.networks[App.network_id].address, {});        #3
    ...      })                                                           
      
      ...  },  
     
        populateAddress : function(){  
          ..
            new Web3(App.url).eth.getAccounts((err, accounts) => {        #4
    ...    },                                                        
     
        handleSignedMessage:function(receiver,amount){      
       ...
          var weiamount=App.web3.utils.toWei(amount, 'ether');
          ...
        },
     
        constructPaymentMessage:function(contractAddress, weiamount) {
          return App.web3.utils.soliditySha3(contractAddress,weiamount)   #5
        },
      
        signMessage:function (message,amount) {      
          web3.personal.sign(message, web3.eth.defaultAccount, function(err, 
                                         signedMessage)                   #6
    {
    ...    },                                                                
     
    handleTransfer:function(amount,signedMessage){
            
            if(App.web3.utils.isHexStrict(signedMessage)){
            var weiamount=App.web3.utils.toWei(amount,'ether')            #7
            var amount=App.web3.utils.toHex(weiamount)                    #7
            ...}
    Figure 8.15 Beneficiary’s and bidders’ interfaces