How to calculate transaction hash
qinheqing opened this issue · comments
How to calculate transactionDigest in the ‘sui_dryRunTransactionBlock’ API? Can you provide me with some help?
export function hashTypedData(typeTag: string, data: Uint8Array): Uint8Array {
const typeTagBytes = Array.from(`${typeTag}::`).map((e) => e.charCodeAt(0));
const dataWithTag = new Uint8Array(typeTagBytes.length + data.length);
dataWithTag.set(typeTagBytes);
dataWithTag.set(data, typeTagBytes.length);
return blake2b(dataWithTag, { dkLen: 32 });
}
/**
* Generate transaction digest.
*
* @param bytes BCS serialized transaction data
* @returns transaction digest.
*/
static getDigestFromBytes(bytes: Uint8Array) {
const hash = hashTypedData('TransactionData', bytes);
return toB58(hash);
}
Found it roughly, I will try to implement it