I'm using Hyperledeger Fabric v1.1 and I'm developing a backend in NodeJs.
Using the Fabric NodeJS SDK I can successfully query the blockchain and retrieve the information of the current block.
However, I can't properly convert the hash of the block from the Buffer type.
Below the snippet of the json that I retrieve from the blockchain.
currentBlockHash:{
"buffer": {
"type": "Buffer",
"data": [8,38,18,32,150,172,137,248,232,203,159,23,44,4,75,29,169,171,120,165,83,22,158,45,93,3,37,120,100,164,229,211,49,194,208,181,26,32,119,47,159,196,237,190,29,24,139,56,212,190,59,126,77,80,76,228,28,171,108,134,241,97,162,190,84,39,240,25,115,135]
}
}
How can I convert this to a normal string in utf-8 in NodeJS?
您可以使用arraybuffer-to-string
npm package 。
var str = arrayBufferToString(buffer, encoding='utf8')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.