Quick Start

import ParaSwift

// Sign a Cosmos transaction
let paraManager = ParaManager(apiKey: "your-api-key")
let wallet = (try await paraManager.fetchWallets()).first { $0.type == .cosmos }!

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.signature)")

Common Operations

Sign Transactions for Different Chains

// 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

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.signature)")

Get Wallet Address

// 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

// 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

let message = "Hello, Cosmos!"
let result = try await paraManager.signMessage(
    walletId: wallet.id,
    message: message
)
print("Signature: \(result.signature)")

Supported Networks

Testnets

NetworkChain IDPrefixNative TokenRPC URL
Cosmos Hub Testnettheta-testnet-001cosmosuatomhttps://rpc.sentry-01.theta-testnet.polypore.xyz
Osmosis Testnetosmo-test-5osmouosmohttps://rpc.osmotest5.osmosis.zone

Mainnets

NetworkChain IDPrefixNative TokenDecimalsRPC URL
Cosmos Hubcosmoshub-4cosmosuatom6https://cosmos-rpc.publicnode.com
Osmosisosmosis-1osmouosmo6https://osmosis-rpc.publicnode.com
Junojuno-1junoujuno6https://rpc-juno.itastakers.com
Stargazestargaze-1starsustars6https://rpc.stargaze-apis.com
Akashakashnet-2akashuakt6https://rpc.akash.forbole.com
Celestiacelestiacelestiautia6https://rpc.celestia.pops.one
dYdXdydx-mainnet-1dydxadydx18https://dydx-dao-api.polkachu.com
Injectiveinjective-1injinj18https://injective-rpc.publicnode.com

Complete Example

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.signature)"
            } catch {
                result = "Error: \(error)"
            }
            isLoading = false
        }
    }
}

Proto vs Amino Formats

// 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"
)