0

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?

Manu Rastogi
  • 188
  • 1
  • 7
  • As per my understanding, Without looking at smart-contract you can not find a number of arguments of chain code Or any other functionality as ABI. – Isha Padalia Nov 06 '20 at 09:55

2 Answers2

1

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:

https://hyperledger.github.io/fabric-chaincode-node/release-2.2/api/tutorial-annotated-contract-metadata.html

bestbeforetoday
  • 1,302
  • 1
  • 8
  • 12
  • Is this method 'GetMetadata' implemented by default or I should write the implementation of it? Because I'm getting this error. "Error: You've asked to invoke a function that does not exist: GetMetadata" – Manu Rastogi Nov 08 '20 at 11:19
  • It should be, result = await contract.evaluateTransaction('org.hyperledger.fabric:GetMetadata'); in line number 2 – Manu Rastogi Nov 10 '20 at 06:09
0
contract = network.getContract('mychaincode', 'org.hyperledger.fabric');
result = await contract.evaluateTransaction('org.hyperledger.fabric:GetMetadata');
metadata = JSON.parse(result.toString('utf8'));
Manu Rastogi
  • 188
  • 1
  • 7