Reputation: 221
I know it's not recommended to perform an API call from a Chaincode to a non-deterministic service. Let's say we have a trusted API and the call doesn't need to be endorsed by all the peers in the network. What would be the best design pattern to implement such a scenario?
Upvotes: 1
Views: 228
Reputation: 142
Here's some similar questions asked which you can refer:
Calling external data on Hyperledger Fabric Chaincode (external data as input in business logic)
Accessing External Api in HyperLedger Fabric
IMHO, it seems like Hyperledger Fabric Chaincode is more suitable for "Ledgering" (recording transaction) rather than operating like an application or "Smart Contract" which you include the business logic. This is because external data may be non-deterministic.
Best practice: You should have an application outside of Hyperledger Fabric that implements the business logic (Deposit, transfer, etc). Then, this application calls the chaincode (like how you do with SDK) to record down the transaction. Or listen to the event like how it is mentioned here :
https://lists.hyperledger.org/g/fabric/message/2501
Upvotes: 1
Reputation: 5140
There is no problem to contact an external service from the chaincode, even when there are multiple peers required in the endorsement policy.
The only restriction is that you need all peers to sign over the same results, so make sure that the chaincode invocations across all peers produce the same payload (same read set, same write set, same results).
It is up to you how to implement it. If your external service is non-deterministic and you must include its results in the ledger, then you can have a proxy that will cache its result for every transaction identifier and then return the same result for all API calls with the same transaction identifier.
Upvotes: 3