> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getpara.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cosmos Integration

> Sign transactions for Cosmos chains using Para's unified wallet architecture

export const Card = ({imgUrl, title, description, href, horizontal = false, newTab = false}) => {
  const [isHovered, setIsHovered] = useState(false);
  const handleClick = e => {
    e.preventDefault();
    if (newTab) {
      window.open(href, '_blank', 'noopener,noreferrer');
    } else {
      window.location.href = href;
    }
  };
  return <div className={`not-prose relative my-2 p-[1px] rounded-xl transition-all duration-300 ${isHovered ? 'bg-gradient-to-r from-[#FF4E00] to-[#874AE3]' : 'bg-gray-200'}`} onMouseEnter={() => setIsHovered(true)} onMouseLeave={() => setIsHovered(false)}>
      <a href={href} onClick={handleClick} className={`not-prose flex ${horizontal ? 'flex-row' : 'flex-col'} font-normal h-full bg-white overflow-hidden w-full cursor-pointer rounded-[11px] no-underline`}>
        {imgUrl && <div className={`relative overflow-hidden flex-shrink-0 ${horizontal ? 'w-[30%] rounded-l-[11px]' : 'w-full'}`} onClick={e => e.stopPropagation()}>
            <img src={imgUrl} alt={title} className="w-full h-full object-cover pointer-events-none select-none" draggable="false" />
            <div className="absolute inset-0 pointer-events-none" />
          </div>}
        <div className={`flex-grow px-6 py-5 ${horizontal ? 'w-[70%]' : 'w-full'} flex flex-col ${horizontal && imgUrl ? 'justify-center' : 'justify-start'}`}>
          {title && <h2 className="font-semibold text-base text-gray-800 m-0">{title}</h2>}
          {description && <div className={`font-normal text-gray-500 re leading-6 ${horizontal || !imgUrl ? 'mt-0' : 'mt-1'}`}>
              <p className="m-0 text-xs">{description}</p>
            </div>}
        </div>
      </a>
    </div>;
};

## Quick Start

```swift theme={null}
import ParaSwift

// Sign a Cosmos transaction
let paraManager = ParaManager(apiKey: "your-api-key")
// Get an existing Cosmos wallet or create one
let wallets = try await paraManager.fetchWallets()
let wallet: Wallet
if let existing = wallets.first(where: { $0.type == .cosmos }) {
    wallet = existing
} else {
    wallet = try await paraManager.createWallet(type: .cosmos, skipDistributable: false)
}

let transaction = CosmosTransaction(
    to: "cosmos1recipient...",
    amount: "1000000", // 1 ATOM in micro-units
    chainId: "theta-testnet-001", // Cosmos Hub testnet (use "cosmoshub-4" for mainnet)
    format: "proto"
)

let result = try await paraManager.signTransaction(
    walletId: wallet.id,
    transaction: transaction,
    chainId: "theta-testnet-001"
)
print("Transaction signed: \(result.signedTransaction)")
```

## Common Operations

### Sign Transactions for Different Chains

```swift theme={null}
// Sign ATOM transaction on Cosmos Hub testnet
let atomTx = CosmosTransaction(
    to: "cosmos1recipient...",
    amount: "1000000", // 1 ATOM
    denom: "uatom",
    chainId: "theta-testnet-001", // Testnet
    format: "proto"
)

// Sign OSMO transaction on Osmosis testnet
let osmoTx = CosmosTransaction(
    to: "osmo1recipient...",
    amount: "1000000", // 1 OSMO
    denom: "uosmo",
    chainId: "osmo-test-5", // Testnet
    format: "proto"
)

// Sign JUNO transaction on Juno mainnet
let junoTx = CosmosTransaction(
    to: "juno1recipient...",
    amount: "1000000", // 1 JUNO
    denom: "ujuno",
    chainId: "juno-1",
    format: "proto"
)
```

### Sign Transaction

```swift theme={null}
let transaction = CosmosTransaction(
    to: "cosmos1recipient...",
    amount: "1000000", // 1 ATOM
    denom: "uatom",
    memo: "Transfer via Para",
    chainId: "theta-testnet-001", // Testnet
    format: "proto" // or "amino" for legacy
)

let result = try await paraManager.signTransaction(
    walletId: wallet.id,
    transaction: transaction,
    chainId: "theta-testnet-001",
    rpcUrl: "https://rpc.sentry-01.theta-testnet.polypore.xyz"
)
// Cosmos returns: { signBytes, signDoc, format }
print("Signed: \(result.signedTransaction)")
```

### Get Wallet Address

```swift theme={null}
// Get the Cosmos wallet address for a specific chain
let wallet = (try await paraManager.fetchWallets()).first { $0.type == .cosmos }!
let address = wallet.address // Returns the primary address
print("Cosmos address: \(address ?? "No address")")
```

### Check Balance

```swift theme={null}
// Native token balance
let balance = try await paraManager.getBalance(
    walletId: wallet.id,
    rpcUrl: "https://cosmos-rpc.publicnode.com",
    chainPrefix: "cosmos" // Important: specify chain prefix for address derivation
)
print("Balance: \(balance) uatom")

// Different chain
let osmoBalance = try await paraManager.getBalance(
    walletId: wallet.id,
    rpcUrl: "https://osmosis-rpc.publicnode.com",
    chainPrefix: "osmo" // Different prefix for Osmosis
)
print("Balance: \(osmoBalance) uosmo")
```

### Sign Message

```swift theme={null}
let message = "Hello, Cosmos!"
let result = try await paraManager.signMessage(
    walletId: wallet.id,
    message: message
)
print("Signature: \(result.signedTransaction)")
```

## Supported Networks

### Testnets

| Network                | Chain ID            | Prefix   | Native Token | RPC URL                                            |
| ---------------------- | ------------------- | -------- | ------------ | -------------------------------------------------- |
| **Cosmos Hub Testnet** | `theta-testnet-001` | `cosmos` | `uatom`      | `https://rpc.sentry-01.theta-testnet.polypore.xyz` |
| **Osmosis Testnet**    | `osmo-test-5`       | `osmo`   | `uosmo`      | `https://rpc.osmotest5.osmosis.zone`               |

### Mainnets

| Network        | Chain ID         | Prefix     | Native Token | Decimals | RPC URL                                |
| -------------- | ---------------- | ---------- | ------------ | -------- | -------------------------------------- |
| **Cosmos Hub** | `cosmoshub-4`    | `cosmos`   | `uatom`      | 6        | `https://cosmos-rpc.publicnode.com`    |
| **Osmosis**    | `osmosis-1`      | `osmo`     | `uosmo`      | 6        | `https://osmosis-rpc.publicnode.com`   |
| **Juno**       | `juno-1`         | `juno`     | `ujuno`      | 6        | `https://rpc-juno.itastakers.com`      |
| **Stargaze**   | `stargaze-1`     | `stars`    | `ustars`     | 6        | `https://rpc.stargaze-apis.com`        |
| **Akash**      | `akashnet-2`     | `akash`    | `uakt`       | 6        | `https://rpc.akash.forbole.com`        |
| **Celestia**   | `celestia`       | `celestia` | `utia`       | 6        | `https://rpc.celestia.pops.one`        |
| **dYdX**       | `dydx-mainnet-1` | `dydx`     | `adydx`      | 18       | `https://dydx-dao-api.polkachu.com`    |
| **Injective**  | `injective-1`    | `inj`      | `inj`        | 18       | `https://injective-rpc.publicnode.com` |

## Complete Example

```swift theme={null}
import SwiftUI
import ParaSwift

struct CosmosWalletView: View {
    @EnvironmentObject var paraManager: ParaManager
    @State private var selectedChain = "theta-testnet-001"
    @State private var isLoading = false
    @State private var result: String?
    
    let wallet: Wallet
    
    let chains = [
        "theta-testnet-001": ("Cosmos Hub Testnet", "https://rpc.sentry-01.theta-testnet.polypore.xyz", "uatom", "cosmos"),
        "osmo-test-5": ("Osmosis Testnet", "https://rpc.osmotest5.osmosis.zone", "uosmo", "osmo")
    ]
    
    var body: some View {
        VStack(spacing: 20) {
            Picker("Chain", selection: $selectedChain) {
                ForEach(chains.keys.sorted(), id: \.self) { chainId in
                    Text(chains[chainId]!.0).tag(chainId)
                }
            }
            .pickerStyle(.segmented)
            
            Text(wallet.address ?? "No address")
                .font(.system(.caption, design: .monospaced))
            
            Button(action: signTransaction) {
                Text(isLoading ? "Signing..." : "Sign Transaction for \(chains[selectedChain]!.0)")
            }
            .disabled(isLoading)
            
            if let result = result {
                Text(result)
                    .font(.caption)
            }
        }
        .padding()
    }
    
    private func signTransaction() {
        isLoading = true
        Task {
            do {
                let chainInfo = chains[selectedChain]!
                let transaction = CosmosTransaction(
                    to: "\(chainInfo.3)1recipient...", // Uses chain prefix
                    amount: "1000000", // 1 token in micro-units
                    denom: chainInfo.2,
                    memo: "Test transaction from Swift",
                    chainId: selectedChain,
                    format: "proto"
                )
                
                let txResult = try await paraManager.signTransaction(
                    walletId: wallet.id,
                    transaction: transaction,
                    chainId: selectedChain,
                    rpcUrl: chainInfo.1
                )
                result = "Signed! Signature: \(txResult.signedTransaction)"
            } catch {
                result = "Error: \(error)"
            }
            isLoading = false
        }
    }
}
```

## Proto vs Amino Formats

```swift theme={null}
// Modern Proto format (recommended)
let protoTx = CosmosTransaction(
    to: "cosmos1recipient...",
    amount: "1000000",
    denom: "uatom",
    format: "proto",
    chainId: "theta-testnet-001" // Testnet
)

// Legacy Amino format (compatibility)
let aminoTx = CosmosTransaction(
    to: "cosmos1recipient...",
    amount: "1000000",
    denom: "uatom",
    format: "amino",
    chainId: "theta-testnet-001" // Testnet
)

// Use convenience constructor
let simpleTx = CosmosTransaction(
    to: "cosmos1recipient...",
    amount: "1000000",
    denom: "uatom",
    chainId: "theta-testnet-001"
)
```
