constructionPreprocess

Cosmos RPC

Overview

The constructionPreprocess method is called prior to constructionPayloads to construct a request for any metadata that is needed for transaction construction. This method is used to fetch information such as account nonce. The options object returned from this method will be sent to the constructionMetadata endpoint UNMODIFIED by the caller in an offline execution environment. If your Construction API implementation has configuration options, they MUST be specified in the constructionPreprocess request in the metadata field.

Parameters

NameTypeRequiredDescription
networkIdentifierobjectYesIdentifies the Cosmos blockchain and network details.
blockchainstring (from networkIdentifier)YesThe blockchain identifier, set to COSMOS for Cosmos.
networkstring (from networkIdentifier)YesThe network name for Cosmos.
subNetworkIdentifierobject (from networkIdentifier)NoOptional sub-network identifier.
networkstring (from subNetworkIdentifier)YesThe name of the sub-network within Cosmos.
metadataobject (from subNetworkIdentifier)NoMetadata associated with the sub-network.
operationsarrayYesDescribes the operations associated with the transaction.
operation_identifierobject (from operations)YesIdentifier for each operation.
indexnumber (from operation_identifier)YesThe index of the operation within the transaction.
network_indexnumber (from operation_identifier)NoNetwork-specific index of the operation.
related_operationsarray (from operations)NoOperations related to the current operation.
indexnumber (from related_operations)YesIndex of related operations.
network_indexnumber (from related_operations)NoNetwork-specific index of related operations.
typestring (from operations)YesType of operation (e.g., "TRANSFER").
statusstring (from operations)NoStatus of the operation (e.g., "SUCCESS").
accountobject (from operations)NoAccount details involved in the operation.
addressstring (from account)YesCosmos account address associated with the operation.
sub_accountobject (from account)NoDetails of a sub-account, if applicable.
metadataobject (from account)NoMetadata for the account.
addressstring (from sub_account)YesAddress of the sub-account.
metadataobject (from sub_account)NoMetadata for the sub-account.
amountobject (from operations)NoDetails of the amount involved in the operation.
valuestring (from amount)YesTransaction amount.
currencyobject (from amount)YesCurrency details of the transaction.
metadataobject (from amount)NoAdditional currency-related metadata.
symbolstring (from currency)YesSymbol of the currency used.
decimalsnumber (from currency)YesDecimal places of the currency.
metadataobject (from currency)NoAdditional currency-related metadata.
coin_changeobject (from operations)NoInformation about changes to coin states.
coin_identifierobject (from coin_change)YesIdentifier for the coin involved in the change.
identifierstring (from coin_identifier)YesGlobally unique identifier of a Coin.
coin_actionstring (from coin_change)YesType of action performed on the coin (e.g., 'coin_created').
metadataobject (from operations)NoAdditional metadata for operations construction.
metadataobjectNoAdditional metadata for transaction construction.

Returns

FieldTypeDescription
optionsobjectObject containing options for the transaction.

Example Result

{
  "options": {
    "fee": "10000",
    "nonce": "3"
  }
}

Request Example

curl --location 'https://api.tatum.io/v3/blockchain/node/cosmos-mainnet/construction/preprocess' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
    "networkIdentifier": {
        "blockchain": "cosmos",
        "network": "mainnet"
    },
    "operations": [
      {
        "operation_identifier": {
          "index": 1
        },
        "type": "TRANSFER",
      }
    ]
}'
// 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_MAINNET,
});

// Define the input parameters with only required fields
const params = {
  networkIdentifier: {
    blockchain: "cosmos", // Specifies the blockchain
    network: "mainnet", // Specifies the network name
  },
  operations: [
    {
      operation_identifier: {
        index: 1, // Specifies the operation index (number)
      },
      type: "TRANSFER", // Specifies the operation type
    },
  ],
};

// Create a request to fetch metadata for transaction construction
const preprocessRequest = await tatum.rpc.constructionPreprocess(params);

// Log the preprocess request
console.log("Construction Preprocess Request:", preprocessRequest);

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