I want to parse ICP transactions from the ledger canister, but I don’t know how to get the correct transaction hash.
For example, 2 consecutive ICP transactions:
On dashboard:
7’469’166 Transaction: 085df7f2cefbf9c80c7ea7bdeb2d7ebfd4d2d8ce2aab487585a6c624e39a5700 - ICP Dashboard
7’469’167 Transaction: 076062f9ee64777e01c202f72a00658a396bbb1c0069bb82f39a05741d86f9e2 - ICP Dashboard
if we get the same txs from icp ledger at Canister: NNS ICP Ledger - ICP Dashboard
tx 7’469’167 has parent_hash (which should ref to 7’469’166) 0216316bb82123613f5d64914da3b942ef84a5371f81c2b38758e35c14b9a9ed
which is different than the hash of tx 7’469’166 on dashboard 085df7f2cefbf9c80c7ea7bdeb2d7ebfd4d2d8ce2aab487585a6c624e39a5700
1 Like
Hi, I looked at the two blocks you mentioned and I believe there is some confusion around blocks and transaction hashes.
- A block contains a transaction. A block is unique while a transaction may not be unique.
- The transaction hash does not have to be unique. There can be multiple transactions in the icp ledger that have the same transaction hash. Uniqueness is only guaranteed when deduplication is set. A block hash contains a unique block index and is therefore always unique.
- A block hash is not the same as a transaction hash. They hash different objects and are thus never the same.
- The parent hash in the block object refers to the hash of the previous block in the blockchain that is stored inside the icp ledger. This means that comparing the transaction hashes to a parent hash will never yield the same result.
To sum up: The parent hash is a block hash and should only be compared against another block hash. Block hashes are not the same as transaction hashes. Transaction hashes are not necessarily unique.
I hope this answers your question.
1 Like
Thanks, I understand the difference now. But it does not resolve my issue, actually. Because I need a transaction hash.
Is it possible to add tx hash to icp ledger canister? New optional field should be backward compatible…
I think it will be more useful than a block hash.
The block hash is important since a blockchain only works a block stores the hash of its previous block. Otherwise, there is no way of varifying a chain of blocks.
There is no plan of adding the transaction hash to the block format right now. You can calculate the hash by serializing the Transaction object and taking a Sha256 hash of it.
The tx hash only gives you a very limited amount of information. The more clear and unique hash is the block hash.
1 Like
How to serialize the transaction in JS?
Is there any example or utility function that calculates the tx hash in JS?
Interestingly, this is not implemented for ICRC tokens.
UPD: I see this will be implemented in ICRC-3
Hello ZenVoich,
I hope this message finds you well. I recently came across your involvement in a project related to ICP (Internet Computer Protocol) transactions and the creation of a JavaScript port. I’m currently working on a similar project and I wanted to inquire if you were successful in creating the JavaScript port for hashing ICP transactions. Any updates or insights you can provide regarding this topic would be greatly appreciated.
Your experience could be of significant value to the community, and I’m keen to hear about your progress. Thank you in advance for your time and assistance.
Best regards,
Alexander
Hello NikolasHai,
I hope this message finds you well. I am currently working on a project that involves hashing ICP (Internet Computer Protocol) transactions in Java, and I’m seeking a code example along with sample data to assist with debugging. Specifically, I’d like to understand how to:
- Encode ICP transaction data in CBOR format.
- Calculate the SHA-256 hash of the CBOR-encoded data.
To make the debugging process smoother, having an example code snippet along with sample data would be immensely helpful. This will allow me to verify that the transaction hash obtained from my Java implementation matches what’s displayed on the official ICP dashboard and the Rosette client for the same transaction.
Your assistance in providing both code and data for reference is greatly appreciated, and I believe it will not only benefit my project but also be valuable to the community.
Thank you in advance for your time and insights.
Best regards,
Alexander