In this Code Pattern, we'll demonstrate how to simulate a securitization process using React.js, Hyperledger Fabric Node SDK, and an IBM Blockchain service instance.
Securitization is a financial process that can be used to consolidate a set of illquid assets into a set of tradable securities. A common example of an illquid asset would be a home mortgage, as they cannot be readily bought and sold. An example of a tradable asset can be a stock or bond. This process can be useful for financial institutions that are looking to increase the liquidity of their assets and free up capital. This application provides a dashboard that'll allow users to create and view the relationship between Assets, Pools, Investors, and Securities.
When the reader has completed this Code Pattern, they will understand how to:
- Deploy a Hyperledger Blockchain network on IBM Cloud
- Create and enroll a administrative client using the Hyperledger Node SDK
- Deploy and Instantiate a set of smart contracts to handle transactions and pool assets
-
A homebuyer leverages the services of a Loan Originator to secure financing for a home mortgage
-
The Loan Originator loads the application, and submits requests to update the Blockchain ledger state with a new Asset
This request is handled by the node.js Express backend formats CRUD request into a jsonrpc object like below, and submits it to a Hyperledger peer as a transaction proposal. The request below would register a mortgage with a value of $540000, an interest rate of 3.3%, and a credit score of 720. The credit score is used to calculate risk for potential investors.
{
jsonrpc: '2.0',
method: 'invoke',
params: {
type: 1,
chaincodeID: {
name: 'securitization_contracts'
},
ctorMsg: {
function: 'init_asset',
args: '["asset1" , "540000", "0.033", "720"]'
},
secureContext: '[email protected]'
},
id: 5
}
- Peer uses an "endorsement" service to simulate the proposed transaction against the relevant smart contracts. This endorsement service is used to confirm that the transaction is possible given the current state of the ledger. Examples of invalid proposals might be creating an asset that already exists, querying the state of an asset that does not exist, etc.
-
If the simulation is successful, the proposal is then "signed" by the peer's endorser.
-
The signed transaction is forwarded to an ordering service, which executes the transaction. In this case, the newly created "Asset" would be placed in an "Asset Pool"
-
The updated state is commited to the blockchain ledger
-
The Securitization UI queries the updated ledger state and renders tables with the updated information
-
If the Asset Pool has been split up into "Securities", an investor has the ability to buy and sell them. The security price should be updated every time there is a change to the ledger state
-
A creditor checks the ledger state to determine the risk of losses by late payments or mortgages going into default. If a significant change is found, the security credit rating will be recalculated by the creditor and updated in the ledger.
To interact with the hosted offerings, the IBM Cloud CLI will need to be installed beforehand. The latest CLI releases can be found at the link here. An install script is maintained at the mentioned link, which can be executed with one of the following commands
# Mac OSX
curl -fsSL https://clis.ng.bluemix.net/install/osx | sh
# Linux
curl -fsSL https://clis.ng.bluemix.net/install/linux | sh
# Powershell
iex(New-Object Net.WebClient).DownloadString('https://clis.ng.bluemix.net/install/powershell')
After installation is complete, confirm the CLI is working by printing the version like so
bx -v
If expecting to run this application locally, please continue by installing Node.js runtime and NPM. Currently the Hyperledger Fabric SDK only appears to work with node v8.9.0+, but is not yet supported on node v9.0+. If your system requires newer versions of node for other projects, we'd suggest using nvm to easily switch between node versions. We did so with the following commands
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
# Place next three lines in ~/.bash_profile
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install v8.9.0
nvm use 8.9.0
To run the Securitization UI locally, we'll need to install a few node libraries which are listed in our package.json
file.
- React.js: Used to simplify the generation of front-end components
- MQTT: Client package to subscribe to Watson IoT Platform and handle incoming messages
- Hyperledger Fabric SDK: Enables backend to connect to IBM Blockchain service
Install the Securitization UI node packages by running npm install
in the project root directory and in the react-backend directory. Both python
and build-essential
are required for these dependencies to install properly:
npm install
cd react-backend && npm install
There are two methods we can use to deploy the application, either use the Deploy to IBM Cloud
steps OR create the services and run locally.
- Clone repository
- Setup repository codebase locally OR Deploy to IBM Cloud
- Create Watson services with IBM Cloud
- Upload and Instantiate Chaincode
- Start the Application
- Retrieve service credentials
- Configure and run the application
Clone the securitization_blockchain
project locally. In a terminal, run:
git clone github.com/IBM/securitization_blockchain
- To deploy the application to IBM Cloud, we'll need to leverage the IBM Cloud CLI. Ensure the cli is installed using the prerequisites section above, and then run the following command to deploy the application
bx cf push
- To see the app and services created and configured for this Code Pattern, use the IBM Cloud dashboard, or run
bx cf apps
andbx cf services
in the terminal. The app should be namedmonitoring-ui
with a unique suffix.
Install the Monitoring UI node packages by running npm install
in the project root directory and in the react-backend directory. Both python
and build-essential
are required for these dependencies to install properly:
npm install
cd react-backend && npm install
NOTE: These steps are only needed when running locally instead of using the
Deploy to IBM Cloud
button.
Next, we'll need to deploy our service instances using the IBM Cloud dashboard.
We can continue on by deploying the IBM Blockchain service. This can be found by logging in to the IBM Cloud dashboard, selecting the "Catalog" button, searching for "Blockchain", and clicking on the resulting icon. Or click this link.
After selecting the blockchain icon, a form will be presented for configuring the service name, region, and pricing plan. The default values for these fields can be left as is. Also, be sure that the free pricing tier is selected, which is titled "Starter Membership Plan". If you are using an IBM Cloud Lite account, this plan can be used for free for up to 30 days. After validating that the information in the form is correct, scroll down and click the "Create" button in the lower right corner
"Smart contracts", commonly referred to as "Chaincode", can be used to execute business logic and validate incoming requests. In this context, the contracts are used to implement CRUD operations for tracking assets on the IBM Blockchain ledger.
To begin the process of uploading the smart contracts to the blockchain, we can start by opening the IBM Cloud dashboard, selecting your provisioned Blockchain service, and accessing the blockchain network monitor by clicking "Enter Monitor"
Next, click the "Install code" option on the left hand menu, and then the "Install Chaincode" button on the right of the page
Enter an id and a version (here we'll use "securitzation_contracts" and "v1"). Then, select the "Add Files" button to upload the samples.go, schemas.go, and simple_contract_hyperledger.go files
Finally, we'll need to Instantiate the chaincode. This can be done by opening the chaincode options menu and selecting "Instantiate"
This will present a form where arguments can be provided to the chaincodes init
function. In this case, we'll just need to provide a json string "1.0"
in the Arguments section, and then click "Submit"
For additional documentation on the chaincode implementation, please see the README in the simple_contract directory
- Start the app locally with
cd sc-ui
npm start | PORT=3001 node react-backend/bin/www
- To access the Securitization application, open the following URL in a browser:
http://localhost:3000/
The credentials for IBM Cloud Blockchain service, can be found in the Services
menu in IBM Cloud by selecting the Service Credentials
option for each service.
The Blockchain credentials consist of the key
, secret
, and network_id
parameters
The securitization flow can be summed up with the following diagram
-
A homebuyer will apply for financing of an asset via a loan "originator". The loan will have a balance, interest rate, monthly payment, and expected time period for payback (many mortgages are roughly 30 years). A total expected payoff amount will be generated based off this information as well.
-
Once the loan has been approved and processed, the loan originator then finances the asset, and transfers the debt to a "Special Purpose Vehicle", which is a entity that protects the assets even if the originator goes bankrupt.
-
The Asset is then placed into a "Pool" along with other assets. Once Assets have been placed into a pool, a set of "securities" can be generated to allow the pool to become tradable. Each Security can be bought and sold by investors, and has a "Yield" which determines the return each security holder will receive on their investment.
-
The Homebuyer submits payments towards their mortgage.
-
Each payment is split up and distributed amongst investors who own "securities" associated with the pool. When all mortgages in the pool are paid off, each investor should have received their original investment back plus the agreed "Yield" amount. Each payment will also have a processing fee which will be dispersed to the originator
This process can be replicated with this application by visiting the dashboard and creating Originators, Assets, Pools, Securities, and Investors using the provided forms.
First, we'll need to create a loan "Originator", which will require an ID, Processing Fee (percentage), and (optional) Company Name. This form can be loaded by selecting the "Create Originator" button
Note that the Balance and Assets fields in the table are initially blank, but will be filled in as we associate assets with the originator. And as the originator receives processing fees and security sale proceeds, their Balance will increase as well
Next, we'll create an Asset, which will require an outstanding balance, interest rate, and a payment period, which defines how many monthly payments they'll need to pay off their entire balance. This can be done by scrolling directly down to the "Assets" Table, clicking the "Create New Asset" button.
Once the Asset has been created, we can also link it to an originator using the "Transfer Asset" button
The resulting table should then reflect the following
Create an Asset Pool via the "Create Pool" form by providing an ID. We can also transfer our asset(s) to the pool using the "Transfer Asset" button in the Assets table
Create one or more "Securities". The create security form will require a ID, associated Asset Pool, and "Coupon Rate". The Coupon Rate defines the return on investment.
Finally, we can create our Investors, which have the ability to buy and sell securities. This can be done by clicking the "Create Investor" button and providing a unique id. Once the investor is created, we can then buy and sell securities using the respective buttons. So in this example, we'll do so by clicking the "Buy Security" button and providing the Security and Investor Id.
Now we can simulate a mortgage payment and view the corresponding payment distributions. We can do so by scrolling back up to the Assets table selecting the "Process Payment" view, and entering an Asset Id and Payment Amount.
Submitting the payment will then:
- Calculate the payment amount allocated to interest and principal
- Adjust the remaining balance
- Calculate and disperse payment amount owed to security holders and originator
Once these calculations are complete, the dashboard tables will then be updated with the latest ledger state
sendPeersProposal - Promise is rejected: Error: 2 UNKNOWN: chaincode error (status: 500, message: Authorization for GETINSTALLEDCHAINCODES on channel getinstalledchaincodes has been denied with error Failed verifying that proposal's creator satisfies local MSP principal during channelless check policy with policy [Admins]: [This identity is not an admin]
This error occurs if the certificate generated by the SDK user has not been uploaded to the peer
Error: The gRPC binary module was not installed. This may be fixed by running "npm rebuild"
grpc
is a requirement for the fabric-client SDK. Confirm that is has been installed in thereact_backend
directory withnpm install [email protected]
- Blockchain Patterns: Enjoyed this Code Pattern? Check out our other Blockchain Patterns