I would like to be able to use various functions from the nodejs crypto module in my Fabric Composer chaincode. Is that possible? I tried hashing a simple string within my chaincode but it didn't work - in Playground I received this error message: 'TypeError: Cannot read property 'apply' of null.' and using CLI to local HLF the transaction never completed. I tested my javascript hashing code separately and it works but not when I try to run it within chaincode.
At the moment you cannot use node modules in transaction processor functions- you're limited to base javascript. It's possible that nodejs support will come in the future, and making crypo APIs available in composer is another option being considered.
If you want to try something in the mean time, crypto-browserify might be worth investigating. I don't know if anyone has got that to work though, so please report back if you try it.
Related
package main
import (
"encoding/json"
"fmt"
"strconv"
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/client/event"
"github.com/hyperledger/fabric-sdk-go/pkg/client/ledger"
"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
)
type Degree struct {......
I am new to Blockchain programming and I am trying to build a degree verification application with the help of my friend. We wrote the whole program, Installed/Set Up Hyperledger Fabric, Go on Ubuntu 22.04. When we try to run it using
go build fabric.go (or) go run fabric.go
We get the following error,
fabric.go:7:2: no required module provides package github.com/hyperledger/fabric/core/chaincode/shim; to add it: go get github.com/hyperledger/fabric/core/chaincode/shim fabric.go:8:2: no required module provides package github.com/hyperledger/fabric/protos/peer; to add it: go get github.com/hyperledger/fabric/protos/peer
We tried installing the required Go module dependencies as it suggested and we keep getting
go: module github.com/hyperledger/fabric#upgrade found (v2.1.1+incompatible), but does not contain package github.com/hyperledger/fabric/core/chaincode/shim
and
go: module github.com/hyperledger/fabric#upgrade found (v2.1.1+incompatible), but does not contain package github.com/hyperledger/fabric/protos/peer
I have no idea how to proceed further and I could use your help. Please explain it as if you are explain it to a five year old, because as I said I am new to this and I am not fully versed with all the terms. I am learning fabric by making projects.
I don't really see enough information in your question to see where your problem is occurring and therefore how to solve it. You should not be importing any packages from github.com/hyperledger/fabric/.... This is the core Fabric server implementation and it is not intended to be consumed as a library. Neither the client SDK or chaincode APIs should be importing these packages either, so I am not sure what in your code is referencing them.
If you are just learning Fabric, I would strongly recommend that you use Fabric v2.4 (or later) and use the Fabric Gateway client API to build your client application instead of the legacy Go SDK. Samples linked from that documentation homepage demonstrate how to use the API to build client applications.
The Fabric documentation on client applications describes the key elements of the client application API. The in-line code examples reference the TypeScript sample but there is an identical sample implementation in Go, and the API structure is extremely similar in all the supported client languages, so the tutorial should be useful regardless of your application language.
I have been creating some Lambda functions on AWS using the serverless framework, Flask and SLS WSGI. Some dynamodb tables but that should not matter in this case.
The problem that I am facing is that I can not debug the whole thing end to end, I am able to run sls wsgi serve and run a local instance of my lambda functions, happy days. However, I am a little bit spoiled by other dev tools, languages and IDEs (even just Flask itself) that allow me to set breakpoints and see the scope, step through etc. So I would really like to be able to get that done here as well.
I tried launching the sls command mentioned above in a launch configuration inside vs code, no luck. Next thing I tried was to run the default flask launch config but that obviously didn't include all the configuration stored in the sls.yml file which is essential for accessing the local dynamodb instance.
The last thing I tried was to attach to ptvsd at the end of my app.py file. So I would hit a wait action from ptvsd, attach the debugger in vs code to the specified port, which seems to be successful and returning the code execution. However, it seems like sls wsgi runs the file twice, so that the attaching happens for the first instance and not the second, which then does not trigger a breakpoint when I try to execute an API call through Postman.
I guess I could include the wait step everywhere manually, then attach for each method that I am trying to debug inside the code instead of in the IDE, but that seems like overkill and not very convenient.
I have been looking for answers online and reading through docs and could find no further.
I figured out that I can use Attach using Process Id It is however a little bit tricky because there are always 2 processes running in the list (different pid's). Its not great, but it does the trick
One technique I have found useful, albeit in a node environment but should apply here, is to make use of unit testing as a way to execute code locally with the ability to tie in a debuggerm as well as make use of mocking to stub away the external dependencies such as AWS services (S3, DynamoDB, etc). I wrote a blog post about setting this up for node but you may find it useful as a way to consider setting things up with Pythoin as well: https://serverless.com/blog/serverless-local-development/
However, in the world of serverless development, it ultimately doesn't matter how sophisticated you get with your local development environment, you will have to to test in the cloud environment as well. The unit testing technique I described is good for catching those basic syntactical and logical errors but you still will need to perform a deployment into the cloud and test in that environment. Its one of the reasons at Serverless we are working very hard on ways to improve the ability and time it takes to deploy to the cloud so that testing in AWS is replaces local testing.
Based on the training videos I have watched, they all talk about the composer as something you use to "define and test your business network", but it almost feels like once its verified and tested, you throw it away and use something more serious. Am I wrong? Even term "playground" feels "experimental" -- something you mess with, but thats all. So, would you build a production system based on composer? How do you split it into multiple machines for redundancy? If composer is so slick and the "obvious" choice for building hyperledger applications, when would you NOT use it and use Fabric or Sawtooth instead? I am trying to get started and dont want to waste time on the wrong path. If you were to build a "serious" supply chain application with multiple players, what framework approach would you take? Thank you
Hyperledger Composer is not a separate platform. It uses Hyperledger Fabric "under the hood". The main problem with Composer is it does not have all the options and features of Fabric exposed in the Composer interface. So, it allows for rapid prototyping at the expense of flexibility. Composer has an impressive user interface.
Unfortunately, Composer is now in maintenance mode with no new features being put into it. See https://lists.hyperledger.org/g/composer/message/125
I would consider Hyperledger Sawtooth or Hyperledger Fabric for permissioned blockchain applications.
After I've put together my business network definition, what is actually happening on peers after I deploy that package? I'm especially interested in how a hyperledger peer can be interpreting javascript, since that doesn't appear to be a supported language for chaincode.
The Composer chain code is written in Go. It uses the Duktape Javascript interpreter to execute the user (and system) JS code within a Go process.
The Composer chain code maps the public JS API to the underlying Fabric Go API calls.
From a Fabric perspective this is just a "normal" piece of Go chain code, albeit quite a complex one!
When you "deploy" a business network using the Composer CLI, you are actually doing 2 things:
deploying the Composer chain code (Go) and starting it
deploying the bytes of the business network archive and storing it in world-state, so that it is available to the interpreter when you submit transactions
In the future we would like to replace the use of Duktape by native Node.js execution. Thanks to Fabric's modular architecture (and use of Docker containers and gRPC) this should be possible.
I'm looking for a way to create an app which has a realtime web interface as well as an API which can be called by a node.js client while sharing most of its code.
I'd like to be able to manage data, monitor and execute tasks inside of my app via browser, but also have an automation/scheduling program which connects to my web app and tells it to run various tasks and get results of each task.
Unfortunately it doesn't look like I can connect to Meteor from the server, so I'm wondering if there's another approach? Is what I described even possible using Meteor?
I have done some testing using socket.io and I think I may be able to do it this way, but Meteor seems like it'd be really great for the realtime user interface.
Yes, you can use npm packages to do what you want. Just like standard Node.js programming.
There might be one error you run into when calling Meteor between external code, but it is easy to solve.
I guess in your case you could set up a TCP server that way and make it update a collection, then you could get the clients to update through the reactive collection publishing mechanism.