0

从合同调用中转换字符串或数字响应的最佳方法是什么。我有一个 Uint8Array 并希望它解码为字符串或数字(ParseInt)。

打字稿合同调用:

await contract.tx.mint({ gasLimit: gasLimit }, alicePair.address).signAndSend(alicePair, async (result) => {

console.log(`result status of mint ${result.status}`);

if (result.status.isInBlock) {
    logger.info('in a block');
  } else if (result.status.isFinalized) {
    logger.info('finalized');
    callValue = await contract.query.balanceOf(alicePair.address, {gasLimit: gasLimit}, alicePair.address);

    logger.info(`Balance of Alice after [${callValue.result.toHuman()}]`);
    console.log(callValue.result.asOk.data);

  }


});

我尝试使用 x-textdecoder,但我得到一个空的控制台输出:

const decoder = new TextDecoder('utf-8');
console.log('Balance Buffer decode:' +  decoder.decode(callValue.result.asOk.data));

合同调用的响应是:

Bytes(8) [Uint8Array] [
  21,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  registry: TypeRegistry { createdAtHash: undefined },
  createdAtHash: undefined,
  initialU8aLength: 0
]
4

0 回答 0