frontend code reactJS:
await axios
.put("http://localhost:8080/api/updateBudget/"+gmail, bud)
.then((response) => {
console.log(response);
})
.catch((error) => {
if (error.response) {
console.log(error.response);
console.log("server responded");
} else if (error.request) {
console.log("network error");
} else {
console.log(error);
}
});
Backend code NodeJS:
app.put('/api/updateBudget/:gmail', async function (req, res) {
try {
const ccpPath = path.resolve(__dirname, '..', 'dev','fabric-samples','test-network', 'organizations', 'peerOrganizations', 'org1.example.com', 'connection-org1.json');
const ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
const walletPath = path.join(process.cwd(), 'wallet');
const wallet = await Wallets.newFileSystemWallet(walletPath);
console.log(`Wallet path: ${walletPath}`);
const identity = await wallet.get('appUser');
if (!identity) {
console.log('An identity for the user "appUser" does not exist in the wallet');
console.log('Run the registerUser.js application before retrying');
return;
}
const gateway = new Gateway();
await gateway.connect(ccp, { wallet, identity: 'appUser', discovery: { enabled: true, asLocalhost: true } });
const network = await gateway.getNetwork('testchannel');
const contract = network.getContract('supply_chain');
await contract.submitTransaction('updateBudget',req.body.gmail,req.body.bud);
console.log('Transaction has been submitted');
res.send('Transaction has been submitted');
await gateway.disconnect();
} catch (error) {
console.error(`Failed to evaluate transaction: ${error}`);
process.exit(1);
}
});
i am getting network error in console and typeError in terminal whenver i hit the api. In frontend i have used ReactJS and in backend i have used NodeJS and i am storing data in blockchain.