Application Integration
In this lesson, we will discuss the two important objects for interaction of node SDK.
We'll cover the following
Applications can interact with a chaincode deployed on a fabric network using a fabric SDK. Hyperledger Fabric 1.4 provides official SDK in node and java.
In this course we will see how to interact with the network using the node SDK.
The node SDK has two important objects for interaction with a fabric network:
- Gateway
- Wallet
The Wallet #
The wallet provides storage and usage histories of user identities for transactions on the network. Remember, in our basic-network we deployed fabric-ca. The self-signed certificate for fabric-ca is configured on the network as a trusted root CA so only users that hold a valid certificate & corresponding key from our fabric-ca will be able to submit a transaction on the network. In our example code, we will be storing these keys and certificates in a file-based wallet to keep things simple to understand.
The Gateway #
The Gateway provides methods to connect to a network channel, using a user’s id from their wallet, and executes chaincode methods installed on the channel.
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
// Assuming the wallet has an identity saved by name user1
// The cpp object contains all network's connection urls
await gateway.connect(ccp, { wallet, identity: 'user1', discovery: { enabled: false } });
// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork('mychannel');
// Get the contract from the network.
const contract = network.getContract('fabcar');
// Evaluate the specified transaction.
// queryCar transaction - requires 1 argument, ex: ('queryCar', 'CAR4')
// queryAllCars transaction - requires no arguments, ex: ('queryAllCars')
const result = await contract.evaluateTransaction('queryAllCars');
Get hands-on with 1200+ tech skills courses.