Writing the settleLC method

The settleLC method is called when the Seller wants to initiate a settlement. The method starts by instantiating the LCMaster contract.

Next, it calls the viewLC method in LCMaster with the LC number for which settlement is requested. It gets the LC number from the fields defined in the state, as follows:

settleLC = () => {
let app = this;
var contractMaster = new this.web3.eth.Contract(this.LCMaster.abi,this.LCMaster.address);
contractMaster.methods.viewLC(app.state.fields.LCNo).call().then(function(response){

On a successful response, we capture the LC contract address for the LC number, from the response in the LCAddress local variable, as follows:

if(response) {
let LCAddress = response[6];

We instantiate a new contract instance for the LC smart contract. After instantiating, the settleLC method is called in the LC smart contract. We pass the settlement amount and the document hash as input parameters, as follows:

var contractLC = new app.web3.eth.Contract(app.LCabi.abi,LCAddress);
contractLC.methods.settleLC(app.state.fields.Amount,app.state.fields.DocHash)
.send({from: app.web3.eth.defaultAccount})
.then(function(response){

if(response) {
console.log(response);
app.resetApp;
}

The successful response is logged to the console and resetApp is called to reset the app state.

That brings us to the end of our App.js file. Let's run the app and see how it looks.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.100.42