getHashOfTransaction

Cosmos RPC

Overview

The getHashOfTransaction method computes the hash for a signed transaction, providing a unique identifier used to track and verify transactions on the Cosmos network.

Description

This method is essential for obtaining a transaction hash from a signed transaction blob. This hash serves as the transaction's unique identifier within the Cosmos blockchain, aiding in transaction verification and tracking.

Request Parameters

NameTypeRequiredDescription
networkIdentifierobjectYesIdentifies the Cosmos blockchain and network details.
blockchainstring (from networkIdentifier)YesThe blockchain identifier, typically "Cosmos".
networkstring (from networkIdentifier)YesThe network name, e.g., "cosmos-mainnet".
subNetworkIdentifierobject (from networkIdentifier)NoOptional sub-network identifier object.
networkstring (from subNetworkIdentifier)YesThe name of the sub-network within Cosmos.
metadataobject (from subNetworkIdentifier)NoMetadata associated with the sub-network.
signedTransactionstringYesThe signed transaction blob for which the hash is to be calculated.

Returns

FieldDescription
transactionHashThe hash of the signed transaction, serving as its unique identifier.

Example Result

{
"transaction_hash": "0x2f23fd8cca835af21f3ac375bac601f97ead75f2e79143bdf71fe2c4be043e8f"
}

Request Example

curl --location 'https://api.tatum.io/v3/blockchain/node/cosmos-mainnet/construction/hash' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
  "network_identifier": {
    "blockchain": "cosmos",
    "network": "mainnet"
  },
  "signedTransaction": "SIGNED_TRANSACTION_BLOB"
}
// Import required libraries and modules from Tatum SDK
import { TatumSDK, CosmosRosetta, Network } from "@tatumio/tatum";

// Initialize the Tatum SDK for Cosmos
const tatum = await TatumSDK.init<CosmosRosetta>({
  network: Network.COSMOS_ROSETTA,
});

// Define the input parameters in a single object
const hashRequest = {
  networkIdentifier: {
    blockchain: "COSMOS", // Specify the blockchain identifier ('COSMOS' for Cosmos).
    network: "NETWORK_NAME", // Specify the network name.
  },
  signedTransaction: "SIGNED_TRANSACTION", // Specify the signed transaction blob.
};

// Calculate the hash of the transaction
const transactionHash = await tatum.rpc.getHashOfTransaction(hashRequest);

// Log the transaction hash
console.log("Transaction Hash:", transactionHash);

// Always destroy the Tatum SDK instance when done to stop any background processes
await tatum.destroy();