getBlock

Cosmos RPC

Overview

The getBlock endpoint is designed to fetch a block from the Cosmos blockchain using a specific Block Identifier. This can be done either by the block's hash or by its height. If transactions are available, they are included directly in the response; otherwise, Transaction Identifiers are provided for subsequent fetches.

Description

Retrieve a block by its Block Identifier. If transactions are included in the response, they are part of the returned Block object. If the transactions are not included, an array of Transaction Identifiers is returned for further fetches. Requests by block hash must be idempotent, always returning the same block contents for the same hash. Requests by block height do not have this restriction due to the possibility of chain reorganizations.

Request Parameters

NameTypeRequiredDescription
networkIdentifierobjectYesIdentifies the Cosmos blockchain and network details.
blockchainstring (from networkIdentifier)YesThe blockchain identifier, typically "Cosmos".
networkstring (from networkIdentifier)YesThe network name on which the transaction is taking place.
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.
blockIdentifierobjectYesThe identifier of the block to fetch. Can be by hash or height.
indexnumber (from blockIdentifier)NoThe height of the block (optional if hash is provided).
hashstring (from blockIdentifier)NoThe hash of the block (optional if index is provided).

Returns

FieldDescription
block_identifierInformation about the current block, including index and hash.
indexThe index (height) of the block.
hashThe hash of the block.
parent_block_identifierInformation about the parent block, including index and hash.
indexThe index (height) of the parent block.
hashThe hash of the parent block.
timestampThe timestamp at which the block was proposed, in milliseconds.
transactionsAn array of transactions included in the block.
transaction_identifierIdentifier for each transaction within the block.
hashThe hash of the transaction.
operationsAn array detailing operations within each transaction.

Each transaction detail is further broken down into identifiers and operations, providing a comprehensive breakdown of the block's contents.

Example Result

{
  "block": {
    "block_identifier": {
      "index": 19865674,
      "hash": "9035A963AA5A28729F0BA316801E901A4E8B1500B2E28301FA296C2D61816F53"
    },
    "parent_block_identifier": {
      "index": 19865673,
      "hash": "200CF85D862597295BB6D6E34888F94849B729C6D7AC688749ADCA387A57E9CD"
    },
    "timestamp": 1712310176442,
    "transactions": [
      {
        "transaction_identifier": {
          "hash": "txHash123456"
        },
        "operations": [
          // List of operations
        ]
      }
    ]
  }
}

Request Example

curl --location 'https://api.tatum.io/v3/blockchain/node/cosmos-mainnet/block' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
  "network_identifier": {
    "blockchain": "cosmos",
    "network": "mainnet"
  },
  "block_identifier": {
    "hash": "9035A963AA5A28729F0BA316801E901A4E8B1500B2E28301FA296C2D61816F53"
  }
}
import { TatumSDK, Cosmos, Network } from "@tatumio/tatum";

const cosmos = await TatumSDK.init<Cosmos>({
  network: Network.COSMOS_MAINNET,
});

const blockInfo = await tatum.rpc.getBlock({
  networkIdentifier: {
    blockchain: "cosmos",
    network: "mainnet",
  },
  block_identifier: {
    hash: "abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890", // Optional if you know the block hash
  },
});

console.log("Block Information:", blockInfo);

await tatum.destroy();