issue.js - Application to Issue New Paper


What is the Application to Issue New Pape, issue.js?



issue.js is a client application using the Hyperledger Fabric Node.js SDK library to invoke the issue() function of the papercontract running on the PaperNet.

1. View issue.js source code:

(isabella)$ cd ~/hyperledger-binaries/fabric-samples
(isabella)$ cd commercial-paper/organization/magnetocorp/application

(isabella)$ more issue.js 
/* SPDX-License-Identifier: Apache-2.0
 * This application has 6 basic steps:
 * 1. Select an identity from a wallet
 * 2. Connect to network gateway
 * 3. Access PaperNet network
 * 4. Construct request to issue commercial paper
 * 5. Submit transaction
 * 6. Process response

'use strict';

// Bring key classes into scope, most importantly Fabric SDK network class
const fs = require('fs');
const yaml = require('js-yaml');
const { FileSystemWallet, Gateway } = require('fabric-network');
const CommercialPaper = require('../contract/lib/paper.js');

// A wallet stores a collection of identities for use
//const wallet = new FileSystemWallet('../user/isabella/wallet');
const wallet = new FileSystemWallet('../identity/user/isabella/wallet');

// Main program function
async function main() {

  // A gateway defines the peers used to access Fabric networks
  const gateway = new Gateway();

  // Main try/catch block
  try {

    // Specify userName for network access
    // const userName = '';
    const userName = '';

    // Load connection profile; will be used to locate a gateway
    let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/networkConnection.yaml', 'utf8'));

    // Set connection options; identity and wallet
    let connectionOptions = {
      identity: userName,
      wallet: wallet,
      discovery: { enabled:false, asLocalhost: true }

    // Connect to gateway using application specified parameters
    console.log('Connect to Fabric gateway.');

    await gateway.connect(connectionProfile, connectionOptions);

    // Access PaperNet network
    console.log('Use network channel: mychannel.');

    const network = await gateway.getNetwork('mychannel');

    // Get addressability to commercial paper contract
    console.log('Use org.papernet.commercialpaper smart contract.');

    const contract = await network.getContract('papercontract', 'org.papernet.commercialpaper');

    // issue commercial paper
    console.log('Submit commercial paper issue transaction.');

    const issueResponse = await contract.submitTransaction('issue', 
       'MagnetoCorp', '00001', '2020-05-31', '2020-11-30', '5000000');

    // process response
    console.log('Process issue transaction response.');

    let paper = CommercialPaper.fromBuffer(issueResponse);

    console.log(`${paper.issuer} commercial paper : ${paper.paperNumber} successfully issued for value ${paper.faceValue}`);
    console.log('Transaction complete.');

  } catch (error) {

    console.log(`Error processing transaction. ${error}`);

  } finally {

    // Disconnect from the gateway
    console.log('Disconnect from Fabric gateway.')

main().then(() => {

  console.log('Issue program complete.');

}).catch((e) => {

  console.log('Issue program exception.');


2. Run issue.js:

(isabella)$ node issue.js

Connect to Fabric gateway.
Use network channel: mychannel.
Use org.papernet.commercialpaper smart contract.
Submit commercial paper issue transaction.
Process issue transaction response.
MagnetoCorp commercial paper : 00001 successfully issued for value 5000000
Transaction complete.
Disconnect from Fabric gateway.
Issue program complete.

We can see from the program output that MagnetoCorp commercial paper 00001 was issued with a face value of 5M USD.

Note that how the gateway uses the networkConnection.yaml file to store the connection addresses and port number of PaperNet.


See New Paper on CouchDB Server

Create Identity Wallet for Isabella

commercial-paper Sample Network

⇑⇑ Hyperledger Tutorials

2019-11-21, 984🔥, 0💬