Reputation: 25
I am trying to create hyperledger chaincode using nodejs and fabric-shim is new to me.
I am trying to fetch history of an asset using getHistoryForKey()
.
I tried iterating through HistoryQueryIterator
using while
but i was not successful.
@Transaction()
public async getAllHistory(ctx:Context,key:string):Promise<void>{
const history = await ctx.stub.getHistoryForKey(key);
while(history.next()){
history.next().then(value =>{
console.info("================>",value.toString());
})
.catch(err =>{
console.info("ERROR",err);
})
}
}
The above code gives [object Object]
.
If someone could point me in the right direction it would be helpful.
Upvotes: 1
Views: 880
Reputation: 1720
You can find an example about how to use getHistoryForKey
in the official Hyperledger Fabric samples ( chaincodes/marbles02).
Upvotes: 2