WalletConnect Integration

Overview

Aria Wallet supports WalletConnect v2, enabling connections from mobile apps and cross-platform experiences. This guide covers integration using cosmos-kit (recommended) and direct WalletConnect connections.

Integration Options

  • cosmos-kit - Recommended for React apps
  • Direct WalletConnect - For custom implementations
  • Mobile Deep Links - Connect to Aria mobile app

Using cosmos-kit

Installation

# Install cosmos-kit with Aria wallet adapter npm install @cosmos-kit/react @cosmos-kit/aria-extension chain-registry # Or with yarn yarn add @cosmos-kit/react @cosmos-kit/aria-extension chain-registry

Provider Setup

import { ChainProvider } from "@cosmos-kit/react"; import { wallets as ariaWallets } from "@cosmos-kit/aria-extension"; import { chains, assets } from "chain-registry"; function App() { return ( <ChainProvider chains={chains} assetLists={assets} wallets={[...ariaWallets]} walletConnectOptions={{ signClient: { projectId: "YOUR_WALLETCONNECT_PROJECT_ID", metadata: { name: "My dApp", description: "My awesome dApp", url: "https://mydapp.com", icons: ["https://mydapp.com/logo.png"] } } }} > <YourApp /> </ChainProvider> ); }

Using the Hook

import { useChain } from "@cosmos-kit/react"; function ConnectButton() { const { connect, disconnect, address, isWalletConnected, wallet } = useChain("cosmoshub"); if (isWalletConnected) { return ( <div> <p>Connected: {address}</p> <p>Wallet: {wallet?.prettyName}</p> <button onClick={disconnect}>Disconnect</button> </div> ); } return <button onClick={connect}>Connect Wallet</button>; }

Signing Transactions

import { useChain } from "@cosmos-kit/react"; function SendTokens() { const { getSigningStargateClient, address } = useChain("cosmoshub"); const sendTokens = async () => { const client = await getSigningStargateClient(); const result = await client.sendTokens( address, "cosmos1recipient...", [{ denom: "uatom", amount: "1000000" }], "auto" ); console.log("TX Hash:", result.transactionHash); }; return <button onClick={sendTokens}>Send 1 ATOM</button>; }

Direct WalletConnect Connection

For non-React applications or custom implementations.

// WalletConnect v2 URI connection const wcUri = "wc:abc123..."; // From QR code or deep link // Connect using Aria's built-in WalletConnect support await window.aria.connect(wcUri); // After connection, use the wallet normally await window.aria.enable("cosmoshub-4"); const key = await window.aria.getKey("cosmoshub-4");

Mobile Integration

Detect mobile and adjust your connection strategy.

function isMobile() { return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i .test(navigator.userAgent); } async function connectWallet() { if (isMobile()) { // On mobile, use WalletConnect or deep linking const uri = await generateWalletConnectUri(); window.location.href = `aria://wc?uri=${encodeURIComponent(uri)}`; } else { // On desktop, use the browser extension if (window.aria) { await window.aria.enable("cosmoshub-4"); } else { alert("Please install Aria Wallet extension"); } } }

Session Management

Manage wallet connections and handle disconnection events.

// Check connection status async function checkConnection() { try { const key = await window.aria.getKey("cosmoshub-4"); console.log("Connected:", key.bech32Address); return true; } catch (e) { console.log("Not connected"); return false; } } // Disconnect and clear session async function disconnectWallet() { await window.aria.disconnect(); clearUserState(); } // Listen for connection changes window.addEventListener("aria_keystore_change", async () => { const isConnected = await checkConnection(); if (!isConnected) { handleDisconnect(); } else { await refreshUserData(); } });