Quick Start
Copy
Ask AI
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.signedTransaction)")
Common Operations
Sign Transactions for Different Chains
Copy
Ask AI
// 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
Copy
Ask AI
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
Copy
Ask AI
// 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
Copy
Ask AI
// 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
Copy
Ask AI
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
Copy
Ask AI
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
Copy
Ask AI
// 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"
)