Replies: 3 comments 2 replies
-
It's a nice approach. Essentially exactly the kind of thing I would be implementing in a real client application, so my general application logic was just interacting with some abstraction layer that internally did appropriate un/marshalling of data and invocation of transaction functions using the SDK. One suggestion would be to use the metadata that the smart contract API produces rather than using reflection on the smart contract implementation code directly. There's a special transaction function that you can evaluate to obtain the metadata. This would allow you to auto-generate client stubs for smart contracts developed in other languages such as Go or Java, not just JavaScript. See here for some details:
This seems to me more of a development-/tooling-time package, rather than a runtime package that would naturally fit within the SDK repository itself. Kinda like the gRPC/protobuf compiler, which generates client stubs for specific gRPC services, rather than the core gRPC libraries that deal with the mechanics of runtime service invocation. That's not to say it couldn't be a Hyperledger / Fabric package in its own right though. It might be worth exploring through the Fabric RFC process: https://github.com/hyperledger/fabric-rfcs One final thing... looking to future Fabric versions, you might also consider basing generated code on the @hyperledger/fabric-gateway package, which was introduced alongside Fabric v2.4. |
Beta Was this translation helpful? Give feedback.
-
@bestbeforetoday I had a few queries and doubts regarding the comment I wanted to ask you given my lack of experience with the Hyperledger project so I sent a connection request via LinkedIn. I hope that's alright |
Beta Was this translation helpful? Give feedback.
-
@pratikpc You can see from the updated off-chain data store sample I created recently, your generated code is very similar to what I have hand-crafted. If you are still interested in developing and contributing this client code generation tool, I would really encourage you to engage with the Fabric leadership on Discord, or share what you've done and discuss at a contributor meeting (see links above). |
Beta Was this translation helpful? Give feedback.
-
In TS we currently would use Fabric Contract API which has a lot of annotations which allows us to write clean, simple and readable code.
However, the code for clients currently in use is barely readable.
This code has a few issues
To fix this, I created my own library
https://www.npmjs.com/package/@pratikpc/fabric-contract-client
This supports intellisense
And allows you to write the following code
This code is much easier to read and handles all conversions on its own.
The best part, both the codebases can be used in the same object.
You can set up the client with
The lib extract the name from the Info annotation of the chaincode object or allow you to pass it as Param 3.
I was thinking that this could be useful for fellow Hyperledger Fabric users and wished to merge my library into the fabric-network codebase. Could someone tell me what would the best ways to proceed would be?
Beta Was this translation helpful? Give feedback.
All reactions