Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transaction hash differs from node/cli #696

Closed
error1100 opened this issue Oct 7, 2024 · 2 comments
Closed

transaction hash differs from node/cli #696

error1100 opened this issue Oct 7, 2024 · 2 comments

Comments

@error1100
Copy link

error1100 commented Oct 7, 2024

Hey there, unfortunately I'm seeing different tx hashes vs what the node code produces.

One example:

  • tx id on chain: a5f678bdf70101480f058a0845e94db04b6f1875155877a42a7c73a9bae5c5f4
  • tx id calculated via cardano-cli: a5f678bdf70101480f058a0845e94db04b6f1875155877a42a7c73a9bae5c5f4
  • tx id calculated by via transaction_hash: 3ea4b79bc55863e8c7a9f9e177ac64274372baab71194a373188bbbc0fc65a62
const csl = require("@emurgo/cardano-serialization-lib-nodejs");

const txHex = '84a300838258200...00ad7b401f5f6';
const tx = csl.Transaction.from_hex(txHex);
const txBody = tx.body();
const txHash = csl.hash_transaction(txBody);
const txId = txHash.to_hex();

console.log(`txId: ${txId}`);

cborHex attached.
tx.signed.txt

Edit: tested with 12.1.1

@lisicky
Copy link
Contributor

lisicky commented Oct 8, 2024

Hi @error1100! It because the Transaction type has no guarantee that CBOR will be the same after serialization roundtrip.
To avoid this issue you can use FixedTransaction type and get tx hash directly from this type.

const txHex = '84a300838258200...00ad7b401f5f6';
const tx = csl.FixedTransaction.from_hex(txHex);
const txHash = tx.transaction_hash()

FixedTransaction is aimed to avoid most of issues when you need to sign a tx from a third party. You can sign or add signature by the next functions:

.sign_and_add_vkey_signature()
.sign_and_add_icarus_bootstrap_signature()
.sign_and_add_daedalus_bootstrap_signature()
.add_vkey_witness()
.add_bootstrap_witness()

@error1100
Copy link
Author

Thank you! Switching to FixedTransaction solves the issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants