Aim : Create a global finance block chain application with IBM Block chain Platform Extension for VS Code. Develop a Node.js smart contract and web app for a Global Finance with block chain use case financeContract.js 'use strict'; const { Contract } = require('fabric-contract-api'); class FinanceContract extends Contract { async initLedger(ctx) { console.log('Initializing Ledger with sample assets...'); const assets = [ { id: 'ASSET1', owner: 'BankA', value: 100000, currency: 'USD' }, { id: 'ASSET2', owner: 'BankB', value: 200000, currency: 'EUR' } ]; for (const asset of assets) { await ctx.stub.putState(asset.id, Buffer.from(JSON.stringify(asset))); } } async createAsset(ctx, id, owner, value, currency) { const exists = await this.assetExists(ctx, id); if (exists) { throw new Error(`Asset ${id} already exists`); } const asset = { id, owner, value: parseFloat(value), currency }; await ctx.stub.putState(id, Buffer.from(JSON.stringify(asset))); return JSON.stringify(asset); } async readAsset(ctx, id) { const assetJSON = await ctx.stub.getState(id); if (!assetJSON || assetJSON.length === 0) { throw new Error(`Asset ${id} does not exist`); } return assetJSON.toString(); } async assetExists(ctx, id) { const assetJSON = await ctx.stub.getState(id); return assetJSON && assetJSON.length > 0; } async transferAsset(ctx, id, newOwner) { const assetJSON = await this.readAsset(ctx, id); const asset = JSON.parse(assetJSON); asset.owner = newOwner; await ctx.stub.putState(id, Buffer.from(JSON.stringify(asset))); return JSON.stringify(asset); } async getAllAssets(ctx) { const allResults = []; const iterator = await ctx.stub.getStateByRange('', ''); let result = await iterator.next(); while (!result.done) { const strValue = Buffer.from(result.value.value.toString()).toString('utf8'); allResults.push(JSON.parse(strValue)); result = await iterator.next(); } return JSON.stringify(allResults); } } module.exports = FinanceContract; app.js const express = require('express'); const bodyParser = require('body-parser'); const app = express(); const port = 3000; app.use(bodyParser.json()); app.use(express.static('public')); // Simulated blockchain storage let blockchain = []; // API to create asset app.post('/createAsset', (req, res) => { const { id, owner, value, currency } = req.body; if (!id || !owner || !value || !currency) return res.status(400).send('Missing fields'); const exists = blockchain.find(a => a.id === id); if (exists) return res.status(400).send('Asset already exists'); const asset = { id, owner, value, currency, timestamp: new Date().toISOString() }; blockchain.push(asset); res.json(asset); }); // API to transfer asset app.post('/transferAsset', (req, res) => { const { id, newOwner } = req.body; const asset = blockchain.find(a => a.id === id); if (!asset) return res.status(404).send('Asset not found'); asset.owner = newOwner; res.json(asset); }); // API to get all assets app.get('/getAssets', (req, res) => { res.json(blockchain); }); app.listen(port, () => console.log(`Server running at http://localhost:${port}`)); index.html Global Finance Blockchain

Global Finance Blockchain

Create Asset

Transfer Asset

All Assets

Asset ID Owner Value Currency Timestamp