Tools, FAQ, Tutorials:
evaluate-transaction.js - Evaluate Chaincode Transaction
How to write a Node.js script to evaluate a transaction defined in the Invoke method of a chaincode?
✍: FYIcenter.com
Here is sample Node.js script, evaluate-transaction.js, that
uses a given user identity from the local wallet to
evaluate a transaction on chaincode.
/* Copyright (c) FYIcenter.com
*/
'use strict';
const { FileSystemWallet, Gateway } = require('fabric-network');
const fs = require('fs');
const ccp = JSON.parse(fs.readFileSync("connection.json", 'utf8'));
const user = process.argv[2];
const channel = process.argv[3];
const chaincode = process.argv[4];
const tx = process.argv.slice(5);
async function main() {
try {
// Create a new gateway for connecting to our peer node.
const wallet = new FileSystemWallet("wallet");
const gateway = new Gateway();
await gateway.connect(ccp, { wallet, identity: user, discovery: { enabled: false } });
// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork(channel);
// Get the contract from the network.
const contract = network.getContract(chaincode);
// Evaluate the specified transaction.
const result = await contract.evaluateTransaction(...tx);
console.log("Tx function and arguments:");
console.log(tx);
console.log("Tx result: %s", result);
} catch (error) {
console.error(`Failed to evaluate transaction: ${error}`);
process.exit(1);
}
}
main();
To run this application script on your client system, you need finish the last tutorial to register "alice" to ca.example.com, and import the certificate and the key info the local wallet.
Try the script to call the queryAllCars() function of the "fabcar" Invoke() method.
$ node evaluate-transaction alice mychannel fabcar queryAllCars
Tx function and arguments:
[ 'queryAllCars' ]
Tx result: [
{"Key":"CAR0", "Record":{"colour":"blue","make":"Toyota","model":"Prius","owner":"Tomoko"}},
{"Key":"CAR1", "Record":{"colour":"red","make":"Ford","model":"Mustang","owner":"Brad"}},
{"Key":"CAR2", "Record":{"colour":"green","make":"Hyundai","model":"Tucson","owner":"Jin Soo"}},
...
]"
⇒ submit-transaction.js - Submit Chaincode Transaction
⇐ register-user.js - Register New User
2019-04-22, ∼1820🔥, 0💬
Popular Posts:
How to install "C++/CLI Support" component in Visual Studio? I need to build my Visual Studio C++/CL...
How to read RSS validation errors at w3.org? If your RSS feed has errors, the RSS validator at w3.or...
Can Two Forms Be Nested? Can two forms be nested? The answer is no and yes: No. You can not nest two...
What is EPUB 3.0 Metadata "dc:description" Element? EPUB 3.0 Metadata "dc:description" is an optiona...
What is Azure API Management Publisher Dashboard? Azure API Management Publisher Dashboard is an Azu...