deriveAccount

Cosmos RPC

Overview

The deriveAccount method enables you to derive a Cosmos account identifier from a public key, facilitating the association of public keys with specific blockchain addresses.

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.
publicKeyobjectYesContains the public key information necessary to derive the account.
hexBytesstring (from publicKey)YesHexadecimal representation of the public key.
curveTypestring (from publicKey)YesThe cryptographic curve type of the public key, e.g., "secp256k1".
metadataobjectNoOptional metadata related to the derivation process.

Returns

FieldTypeDescription
accountIdentifierobjectAn object representing the derived account identifier for the Cosmos account.

Example Result

{
  "accountIdentifier": "cosmos1..."
}

Request Example

curl --location 'https://api.tatum.io/v3/blockchain/node/cosmos-mainnet/construction/derive' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
    "networkIdentifier": {
        "blockchain": "cosmos",
        "network": "cosmos-mainnet"
    },
    "publicKeys": {
        "hexBytes": "PUBLIC_KEY_HEX_BYTES",
        "curveType": "secp256k1"
    }
}'
// Import required libraries and modules from Tatum SDK
import { TatumSDK, Cosmos, Network } from "@tatumio/tatum";

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

// Define the input parameters with only required fields
const params = {
  networkIdentifier: {
    blockchain: "COSMOS",
    network: "COSMOS_MAINNET",
  },
  publicKeys: {
    hexBytes: "PUBLIC_KEY_HEX_BYTES", // Hexadecimal representation of the public key.
    curveType: "secp256k1", // Cryptographic curve type.
  },
};

// Derive the Cosmos account identifier from the public key
const accountIdentifier = await tatum.rpc.deriveAccount(params);

// Log the derived account identifier
console.log("Account Identifier:", accountIdentifier);

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