# Can we calculate transaction hash before submitting? How?

**URL:** <https://forum.cardano.org/t/can-we-calculate-transaction-hash-before-submitting-how/59415>\
**Category:** Misc Dev Talk\
**Created:** [1 May 2021 15:22 UTC](https://forum.cardano.org/t/can-we-calculate-transaction-hash-before-submitting-how/59415 "2021-05-01T15:22:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nimrod](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/nimrod/32/19918_2.png) [@nimrod](https://forum.cardano.org/u/nimrod)\
**Post date:** [1 May 2021 15:22 UTC](https://forum.cardano.org/t/can-we-calculate-transaction-hash-before-submitting-how/59415/1 "2021-05-01T15:22:40Z")

</div>

I’m currently working on an app that submits transactions to a cardano-node, and I’m looking for the best or most efficient way to confirm if the transaction recently submitted actually went through.

I see that projects like [cntools](https://github.com/cardano-community/guild-operators/blob/51cc10086e8ad26d7ae254f0fa0903d5b703857e/scripts/cnode-helper-scripts/cntools.library#L700) verify submitted transactions only by checking the before and after balances. And then later just taking the hash of the latest trx.

But I’ve had a few cases already where this kind of checking fails. And this easily fails… like if 2 similar transactions produce the same result on the address that’s being checked.

So if it is possible, I’m thinking it would be a lot better to just calculate the actual transaction hash prior to submitting it and then later check for that transaction hash to confirm if it has been finalized.

If this is possible, can someone point me in the right direction? I’m planning to implement this in a nodejs app but any sample logic or spec should help…

---

<div class="post-metadata">

**Author:** ![rdlrt](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/rdlrt/32/9098_2.png) [@rdlrt](https://forum.cardano.org/u/rdlrt)\
**Post date:** [1 May 2021 22:36 UTC](https://forum.cardano.org/t/can-we-calculate-transaction-hash-before-submitting-how/59415/2 "2021-05-01T22:36:58Z")

</div>

You can view signed transaction via CLI - using `cardano-cli transaction view ...` (or query specific utxo instead of address).

Such checks are not essential for basic wallet operating wrapper scripts, but for example exchanges often verify specific UTXOs.

---

<div class="post-metadata">

**Author:** ![nimrod](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/nimrod/32/19918_2.png) [@nimrod](https://forum.cardano.org/u/nimrod)\
**Post date:** [2 May 2021 06:45 UTC](https://forum.cardano.org/t/can-we-calculate-transaction-hash-before-submitting-how/59415/3 "2021-05-02T06:45:13Z")

</div>

> [@rdlrt](#):
>
> You can view signed transaction via CLI - using `cardano-cli transaction view ...`

Thanks! I’ll dig into this.

---

<div class="post-metadata">

**Author:** ![nimrod](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/nimrod/32/19918_2.png) [@nimrod](https://forum.cardano.org/u/nimrod)\
**Post date:** [2 May 2021 07:33 UTC](https://forum.cardano.org/t/can-we-calculate-transaction-hash-before-submitting-how/59415/4 "2021-05-02T07:33:23Z")

</div>

> [@rdlrt](#):
>
> You can view signed transaction via CLI - using `cardano-cli transaction view ...`

So… the result of this looks like the following:

```auto
auxiliary data: null
auxiliary data hash: null
certificates: []
era: Mary
fee: 180285
inputs:
- 36c8bab969639292eb7eb874fb8c7cd73985728c6d89400e0c2773490ad991e6#1
mint:
  lovelace: 0
  policies: {}
outputs:
- address:
    Bech32: addr1qx8etwdj3vpky8nenxldxzc4gm7llpddad3szf99puffyvdaazlltw7cf2r36fdr47a3pwsu9yjhk7zjud5zwwmt0crqyjynkm
    credential:
      key hash: 951d46072977ce7f3b0dea694ca75b42bb4e65cb8803f5f6b39d53fa
    network: Mainnet
    stake reference: StakeRefBase (KeyHashObj (KeyHash "f612f34ffac18ab70a3604d4e5b912c9b82e62a8337512e177627588"))
  amount:
    lovelace: 8000000
    policies: {}
- address:
    Bech32: addr1q9yxcf5ffaq5nxrsfflfh0tq0fgzgqdmyghyflq936dmyldrqd7gxj690rjeljhg8d9cckd7zwq0pgv7j2e86km69wusfgdadn
    credential:
      key hash: 3235b5de9d5d5ed88f5e40f19ee77429d0754b4d6045d1edece1c004
    network: Mainnet
    stake reference: StakeRefBase (KeyHashObj (KeyHash "ee15aaabc6508905cabb26fd1b3d1e2c748b7e3f9d68d7c02d864085"))
  amount:
    lovelace: 40143633
    policies:
      407ca40d92693cb737f1cfedb98023ae753038d8c6ca9e02483d79c6:
        '524e52': 46875050
      6814db7e0dd9fc618dfa0583e9019ba68b3e993f8c7482c8a6fb59f2:
        '535347': 427000
update: null
validity interval:
  invalid before: null
  invalid hereafter: null
withdrawals: []

```

How can we get the trx hash from this? The `outputs` only contain the receiving addresses and key hashes. What else needs to be done to arrive at the trx hash / utxo hash for the transaction?

---

<div class="post-metadata">

**Author:** ![rdlrt](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/rdlrt/32/9098_2.png) [@rdlrt](https://forum.cardano.org/u/rdlrt)\
**Post date:** [2 May 2021 07:55 UTC](https://forum.cardano.org/t/can-we-calculate-transaction-hash-before-submitting-how/59415/5 "2021-05-02T07:55:26Z")

</div>

> [@nimrod](#):
>
> How can we get the trx hash from this

Just use txid instead of view (or just `cardano-cli transaction --help` for complete list of subcommands against transaction).

---

<div class="post-metadata">

**Author:** ![nimrod](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/nimrod/32/19918_2.png) [@nimrod](https://forum.cardano.org/u/nimrod)\
**Post date:** [2 May 2021 08:00 UTC](https://forum.cardano.org/t/can-we-calculate-transaction-hash-before-submitting-how/59415/6 "2021-05-02T08:00:38Z")

</div>

This is it! 👍

For those who come here in the future looking for the same thing:

```auto
cardano-cli transaction txid --tx-file tx.signed

```

Sample output (trx hash):

```auto
5fe8709128e0db69b86d3abe3215a3bdaf4c804c1a413f1725ff2c5cc546263c

```

This is not so clear in the official docs, especially if you’re new to this. 😞

---

<div class="post-metadata">

**Author:** ![rdlrt](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/rdlrt/32/9098_2.png) [@rdlrt](https://forum.cardano.org/u/rdlrt)\
**Post date:** [2 May 2021 12:50 UTC](https://forum.cardano.org/t/can-we-calculate-transaction-hash-before-submitting-how/59415/7 "2021-05-02T12:50:39Z")

</div>

> [@nimrod](#):
>
> This is not so clear in the official docs

For most command line tools (across the industry), you can check the usage instructions using `--help` or `-h`

 ![IMG_20210502_224451](https://us1.discourse-cdn.com/flex023/uploads/cardano/original/3X/4/5/4581c097e3d97fd81aa92459949c5f594de2f5d5.jpeg)

---

<div class="post-metadata">

**Author:** ![nimrod](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/nimrod/32/19918_2.png) [@nimrod](https://forum.cardano.org/u/nimrod)\
**Post date:** [3 May 2021 12:13 UTC](https://forum.cardano.org/t/can-we-calculate-transaction-hash-before-submitting-how/59415/8 "2021-05-03T12:13:06Z")

</div>

> [@rdlrt](#):
>
> For most command line tools (across the industry), you can check the usage instructions using `--help` or `-h`

This, I already know. There is also the same description for the `txid` subcommand in the [docs](https://docs.cardano.org/projects/cardano-node/en/latest/reference/cardano-node-cli-reference.html).

Looking back, it does seem very stupid of me not to have even tried it first. 😅 But it just wasn’t that apparent to me then.
