how to calculate the transaction hash use Typescript SDK? #104
-
how to calculate the transaction hash use Typescript SDK? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
To get the transaction hash using the TypeScript SDK, you would follow the process of
Once the transaction is submitted, the API will return a transaction hash that represents the unique identifier of the transaction on-chain. Here's an example of what that looks like:
Refer to these docs for more info. |
Beta Was this translation helpful? Give feedback.
-
We've got a new answer for this one! I've copied this in a stack overflow as well. ExampleShort answer (how to hash)This has now been added to the TypeScript SDK, take a look here It basically does:
Longer answer (How to hash)Aptos hashes all types in a standard way. This is done by first creating a prefix, for every type. This is defined as a SHA3-256 of
Then, there is serialization of the transactions as BCS. In the case here, the TypeScript SDK drops the enum byte, so it has to be recombined (in BCS). Take a look here at the details https://github.com/aptos-labs/aptos-core/blob/main/types/src/transaction/mod.rs#L1931-L1959 The order of the items in the struct give the enum byte.
Finally, hashing all of these together gives the final answer
|
Beta Was this translation helpful? Give feedback.
We've got a new answer for this one! I've copied this in a stack overflow as well.
Example
https://github.com/aptos-labs/aptos-ts-sdk/blob/5cec8cecb6684ec37d379a62ae8df6a6fab06f61/tests/e2e/transaction/transactionBuilder.test.ts#L559-L579
Short answer (how to hash)
This has now been added to the TypeScript SDK, take a look here
aptos-labs/aptos-ts-sdk@5cec8ce
It basically does:
Longer answer (How to hash)
Aptos hashes all types in a standard way. This is done by first creating a prefix, for every type. This is defined as a SHA3-256 of
APTOS::<Type>
The struct type is here as
Transaction
…