Writing the transaction listener code

Open the TransListener-BankA.js file in a code editor, and proceed as follows:

We start by importing the dependencies for building our transaction listener, like this:

const { FileSystemWallet, Gateway } = require('fabric-network');
const ipfsClient = require('ipfs-http-client')
const ipfs = ipfsClient('http://localhost:5001')
const fs = require("fs");
const pg = require('pg');

The fabric-network module is used to connect to the blockchain network and listen to events triggered by our corprem smart contract.

The IPFS client allows us to publish to and fetch files from the IPFS network. It is set to the client port of Bank A, which is 5001.

The fs module allows interaction with the local filesystem.

The pg module is used to connect to the postgres database.

Next, we define the parameters for connecting to the banka postgres database.

The conString object is passed to the pg postgres client to connect to the database. We add the postgres client port, the username, and the password for the banka Unix user and the database, to connect to the conString object, as follows:

const conString = "postgres://banka:banka@localhost:5432/banka";
const client = new pg.Client(conString);
client.connect();

The ccpPath object stores the location of the connection profile for connecting and submitting transactions to the Bank A node. We'll use it to connect our transaction listener to the blockchain gateway. Lastly, we call the Transactionlistener, as follows:

const ccpPath = '~/fabric-samples/bankchain/connection-banka.json';
Transactionlistener();

Let's start writing the methods for our listener.

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

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