Reputation: 188
There is no concept of ABI(Application Binary Interface) in Hyperledger fabric as it is there in Ethereum/Quorum.
An ABI file in Quorum is generated while compiling the Smart-contract(chaincode), which is further used by the client-application as the reference to the function definition of the deployed smart-contract.
For example: If there is a function named getAsset(assetId: string) which returns an Asset object, this complete information will be defined in the ABI file.
So, In short, ABI serves the purpose of an interface of a deployed smart-contract, and, also stays with the client-application as a reference of the function definitions of the deployed smart-contract, Which omits the possibility of the application being out of sync with the deployed contract and calling the smart-contract's functions with incorrect arguments.
Now, I am wondering how this problem can be solved in Hyperledger Fabric.
I was going through asset-transfer-basic (javascript application), there I can see a method named CreateAsset that accepts (assetId, color, owner, size, appraisedValue) but they are being passed explicitly.
What I mean by that is, there is no other way to know what arguments CreateAsset accepts without manually looking at the implementation of the function in the smart-contract.
Is there any way to solve this problem?
Upvotes: 0
Views: 478
Reputation: 188
contract = network.getContract('mychaincode', 'org.hyperledger.fabric');
result = await contract.evaluateTransaction('org.hyperledger.fabric:GetMetadata');
metadata = JSON.parse(result.toString('utf8'));
Upvotes: 0
Reputation: 1684
Chaincodes (at least ones implemented using the Contract API) have a org.hyperledger.fabric:GetMetadata
transaction function that returns a JSON payload describing all the available transaction functions and their parameters.
Using the client SDK you would invoke this by creating a client-side Contract object with the chaincode name and org.hyperledger.fabric
as the contract identifier. Then invoke the GetMetaData
transaction using that Contract object. In JavaScript, something like this:
contract = network.getContract('mychaincode', 'org.hyperledger.fabric');
result = await contract.evaluateTransaction('GetMetadata');
metadata = JSON.parse(result.toString('utf8'));
I'm not sure how well the existence of this transaction function is documented, but the structure of the metadata is documented here:
Upvotes: 2