Get transaction's block number in Hyperledger Composer - hyperledger-fabric

The GET Endpoints for transactions only return the transactionId but I would like to get the block number too.
Is it possible to get a transaction's block number using the Hyperledger Composer REST API?. Any other workarounds involving other tools are appreciated.

This is not possible via the Composer REST API.
However it should be possible using the Composer Javascript API - using the getNativeAPI() method from the BusinessNetworkConnection class. This calls through to the Fabric SDK and queryTransaction() method of the channel class provides block information. Alternatively queryInfo() method will provide the block height.
The Composer API doc can be found here:
https://hyperledger.github.io/composer/latest/api/api-doc-index
and the Fabric SDK here:
https://fabric-sdk-node.github.io/Channel.html
Note that the getNativeAPI() function available in the Composer Transaction Processor only exposes the chaincodeStub class in the Fabric SDK and so can't find Block information, which is why this is not possible in the REST API.
The Blockchain Explorer, has a REST API which exposes block information, however it is another component to configure and manage.

Related

How to make a user authentication using hyperledger fabric

i have a current channel of hyperledger fabric with chaincode that does CRUD operations my question is that is there any way to make a method in a chaincode that registers the new user when certain condition match.
You can use one of several methods to get the identity of the user:
GetCreator
GetId
GetMSPId
They are part of the Client Identity Chaincode Library, documented here: https://pkg.go.dev/github.com/hyperledger/fabric-chaincode-go/pkg/cid#section-readme
The Hyperledger Fabric docs provide some help for access control also if you're interested in that: https://hyperledger-fabric.readthedocs.io/en/latest/private-data/private-data.html?highlight=getmspid#private-data-sharing-patterns

Intergration of Hyperledger Fabric chaincode with Frontent using APIs

I am trying to integrate my chaincode with the frontend by creating APIs. I am currently using the chaincode from fabric-samples (/asset-basic-transfer/chaincode-javascript).
If I try to create the APIs using the traditional way, I get this error:
Cannot read property 'putState' of undefined
I am getting the error when I use:
await ctx.stub.putState(id, Buffer.from(stringify(sortKeysRecursive(asset))));.
When I just call the function using:
assetTransfer.CreateAsset(ctx, id, data) - I get an error saying that CreateAsset is not a function.
How to fix this error? Or, alternatively, how to create APIs that can be called?
It is worth making sure you understand the key concepts of a Hyperledger Fabric blockchain network, and how the different components relate:
https://hyperledger-fabric.readthedocs.io/en/release-2.2/network/network.html#invoking-a-smart-contract
https://hyperledger-fabric.readthedocs.io/en/release-2.2/smartcontract/smartcontract.html
A chaincode (or smart contract) runs at the server side and is invoked by an endorsing peer in response to client proposals. So you would not invoke chaincode functions or APIs directly from your application layer. Instead, you should look to use one of the Fabric application APIs to submit or evaluate transactions that will drive your deployed smart contract:
https://hyperledger-fabric.readthedocs.io/en/release-2.2/getting_started.html#hyperledger-fabric-application-sdks
Your application layer would provide an API that can be invoked by your frontend, and would use a Fabric application API to interact with Fabric on behalf of the frontend.

How to get block info by txid in hyperledger composer?

In hyperledger composer, I can get transactionId, but I also need block info.
Currently it is not possible to get that information from Composer, but there is an Improvement Proposal issue active in GitHub to provide this functionality in the future.
If you need to provide this information visually there is the Blockchain Explorer I think this has a REST API so you could make calls to it for block information.

Cryptocurrency based on Hyperledger

Does Hyperledger Fabric support possibility to create a cryptocurrency like well know Bitcoin/Ethereum?
I don't mean tokens which I can implement by chaincode.
You can implement any business logic by using Hyperledger Fabric chaincode, which essentially a simple program. Chaincode manages ledger state by operation on transactions submitted by application and ensure to have it consistent across network peers.
Hyperledger Fabric currently supports chaincodes written in Go, while in a future will be added support for nodeJS and Java. Chaincode interface defined as following:
// Chaincode interface must be implemented by all chaincodes. The fabric runs
// the transactions by calling these functions as specified.
type Chaincode interface {
// Init is called during Instantiate transaction after the chaincode container
// has been established for the first time, allowing the chaincode to
// initialize its internal data
Init(stub ChaincodeStubInterface) pb.Response
// Invoke is called to update or query the ledger in a proposal transaction.
// Updated state variables are not committed to the ledger until the
// transaction is committed.
Invoke(stub ChaincodeStubInterface) pb.Response
}
So you can implement your cryptocurrency into chaincode. To get an inspiration on how you can implement it, you might want to take a look on following demo application of balance-transfer.
There is a Token feature in the alpha release of 2.0, you can check it out: https://hyperledger-fabric.readthedocs.io/en/latest/whatsnew.html#fabtoken
Also check here for
Can we create non-fungible tokens with Hyperledger?
The platform-neutral Token Taxonomy Initiative overseen by the Enterprise Ethereum Alliance (EEA) has announced the publication of the Token Taxonomy Framework (TTF) V 1.0, which enables businesses and developers to universally understand and define what a token is in non-technical terms, regardless of how it is implemented.

Composer, Participants and User-Management

When triggering a transaction with the "composer-cli" one has to specify the "enrollId" and the "secret" to be able to send the request. So transaction is fired in the context of a given fabric-user.
I was asking myself if there is a way to map the identity of the fabric-user firing the transaction to a given "participant" from the Participant Registry (in the composer JS code, which implements business logic)?
Are these two layers of authentication completely separated? If yes, then how is one supposed to identify in the JS code that a given participant (in composer terminology) is firing the transaction? Thx.
Please refer to the docs here:
https://fabric-composer.github.io/managing/identity-issue.html
The issue identity / revoke identity CLI commands are used to map a Fabric user to a Composer participant.

Resources