React Widget

Drop-in IntentGuardButton component for React dApps. Shows QR, polls for commit, and returns verified status.

Install

npm install intentguard-sdk @solana/web3.js

Basic Usage

import { IntentGuardButton } from 'intentguard-sdk/react';

function SwapPage() {
  return (
    <IntentGuardButton
      action="swap"
      params={{ amount: 1_000_000_000, mint: 'EPjFWdd5...' }}
      appId="JUP6Lkb..."
      user={walletPublicKey}
      connection={connection}
      onVerified={(hash) => executeSwap(hash)}
      onExpired={() => showError('Intent expired')}
    />
  );
}

Props

PropTypeRequiredDescription
actionstringYesAction name for hash computation
paramsobjectYesAction parameters for hash computation
appIdstring | PublicKeyYesTarget app program ID
userPublicKeyYesUser's wallet public key
connectionConnectionYesSolana RPC connection
onVerified(hash) => voidYesCalled when intent is verified on-chain
onExpired() => voidNoCalled when intent TTL expires
ttlnumberNoTTL in seconds (default 300)
pollIntervalnumberNoPoll interval in ms (default 2000)
allowManualHashbooleanNoShow manual hash entry fallback for CLI users

Widget States

  1. idle — Button shows "Verify with IntentGuard"
  2. show_qr — QR code displayed for mobile scanning
  3. waiting — Polling for on-chain commit detection
  4. verified — Intent verified, onVerified callback fires
  5. expired — TTL passed, onExpired callback fires
  6. manual_input — Manual hex hash entry (CLI fallback)

QR Payload Format

{
  "protocol": "intentguard",
  "version": 1,
  "app": "JUP6Lkb...",
  "action": "swap",
  "params": { "amount": 1000000000, ... },
  "display": { "title": "Swap 1 SOL", "description": "..." }
}

The mobile app scans this QR, shows the human-readable display, and commits the intent hash on-chain after biometric confirmation.

Deep Links

For direct mobile integration without QR scanning:

intentguard://commit?payload=base64_encoded_qr_payload