Skip to content

feat: add sign-with-wallet-adapter React example#29

Merged
tilo-14 merged 11 commits intoLightprotocol:mainfrom
klausundklaus:feat/sign-with-wallet-adapter
Mar 2, 2026
Merged

feat: add sign-with-wallet-adapter React example#29
tilo-14 merged 11 commits intoLightprotocol:mainfrom
klausundklaus:feat/sign-with-wallet-adapter

Conversation

@klausundklaus
Copy link
Contributor

@klausundklaus klausundklaus commented Feb 26, 2026

Summary

  • Adds toolkits/sign-with-wallet-adapter/react/ — a Wallet Adapter equivalent of the existing Privy example
  • Swaps the signing layer from Privy SDK to @solana/wallet-adapter-react while keeping identical Light Token SDK usage (transfer, wrap, unwrap)
  • Fixes hot/cold balance fetch order in useUnifiedBalance so mints discovered only via compressed accounts also get hot balance lookup

What changed from Privy

Layer Privy Wallet Adapter
Provider PrivyProvider ConnectionProvider + WalletProvider + WalletModalProvider
Sign useSignTransaction → serialize unsigned → sign buffer → deserialize useWallet().signTransaction → sign Transaction object → serialize
Connect UI Privy login/logout WalletMultiButton (auto-detects wallet-standard wallets)
Wallet selection Multi-wallet dropdown Single connected wallet
Dependencies removed @privy-io/react-auth, @solana-program/memo, @solana/kit
Dependencies added @solana/wallet-adapter-react, @solana/wallet-adapter-react-ui

Files identical to Privy

useLightBalance, useUnifiedBalance, useTransactionHistory, CopyButton, Section, TransactionStatus, TransactionHistory, WalletInfo, config files (vite, tsconfig, vitest)

Test plan

  • 26/26 unit tests passing (pnpm test)
  • Build succeeds with zero TS errors (pnpm build)
  • Integration tests skip cleanly without RPC URL
  • Manual test with Phantom on devnet (needs VITE_HELIUS_RPC_URL)

🤖 Generated with Claude Code


Open with Devin

Adds a Wallet Adapter equivalent of the existing Privy example.
Swaps the signing layer from Privy SDK to @solana/wallet-adapter-react
while keeping identical Light Token SDK usage (transfer, wrap, unwrap).

Changes from Privy example:
- ConnectionProvider + WalletProvider + WalletModalProvider (replaces PrivyProvider)
- useWallet().signTransaction (replaces useSignTransaction from Privy)
- signAndSendBatches takes signTransaction(Transaction) -> Transaction
- WalletMultiButton for connect/disconnect (replaces Privy login/logout)
- Removed wallet selector (single connected wallet)
- Fixed hot/cold balance fetch order (cold before hot) so compressed-only
  mints also get hot balance lookup

26 unit tests passing, build clean.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

- useWrap now awaits confirmTransaction after sendRawTransaction,
  matching the behavior of signAndSendBatches (used by transfer/unwrap)
- Added confirmTransaction assertion to wrap test
- README expanded to match Privy example quality: hook docs, component
  docs, setup helpers table, quick start guide

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

klausundklaus and others added 2 commits February 26, 2026 03:32
Tests useUnifiedBalance, useTransfer, and useTransactionHistory against
devnet using filesystem keypair signing. Creates a fresh mint with SPL
interface, mints tokens, wraps to light-token, then exercises the full
transfer + balance + history flow.

Run: VITE_HELIUS_RPC_URL=<url> pnpm test:integration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Support both devnet and localnet testing:
- VITE_HELIUS_RPC_URL=<url> for devnet (Helius bundles compression API)
- VITE_LOCALNET=true for localnet (createRpc() uses default ports 8899/8784/3001)
- Localnet mode airdrops SOL before running tests

Note: localnet currently blocked by CLI/SDK version mismatch (CLI v0.27.0
programs don't match SDK v0.23.0-beta.9 instructions). Devnet tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
devin-ai-integration[bot]

This comment was marked as resolved.

- useUnifiedBalance: fetch actual mint decimals via getMint() instead of
  hardcoding 9 (fixes wrong display/amounts for USDC and other non-9
  decimal tokens)
- useWrap, useUnwrap: align on Math.round to match useTransfer (all 3
  hooks now consistent)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

Mirror of the wallet-adapter fixes:
- useUnifiedBalance: fetch actual mint decimals via getMint()
- useUnifiedBalance: fix hot/cold fetch order (cold before hot) so mints
  discovered only via compressed accounts also get hot balance lookup
- useTransfer, useWrap, useUnwrap: Math.floor → Math.round

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@klausundklaus klausundklaus force-pushed the feat/sign-with-wallet-adapter branch from a744666 to 08dbfbc Compare March 2, 2026 14:40
devin-ai-integration[bot]

This comment was marked as resolved.

klausundklaus and others added 4 commits March 2, 2026 14:47
getMint() defaults to TOKEN_PROGRAM_ID, silently failing for T22 mints
and falling back to hardcoded decimals: 9. Track tokenProgram per mint
in mintMap and pass it through to getMint().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Same four bugs as React versions:
- toUiAmount(amount, 9) called early, hardcoding 9 decimals
- Hot balance fetched before cold (ordering bug)
- decimals: 9 never updated from on-chain
- No tokenProgram tracking for T22 getMint

Refactored to store raw bigint values in accumulator and convert
to UI amounts at assembly time using actual mint decimals.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
List all 5 toolkits in both root and toolkits README. Add missing
pinocchio-swap to program examples table.

Entire-Checkpoint: 4afa49be1970
Keep both wallet-adapter and sponsor-rent-top-ups rows.

Entire-Checkpoint: 4afa49be1970
@tilo-14 tilo-14 merged commit a3d0aff into Lightprotocol:main Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants