Reown Web Examples
repository·main·Indexed 19 days ago
https://github.com/reown-com/web-examplesA collection of reference implementations for WalletConnect v2, providing concrete examples of how to build Wallets and dApps using WalletConnect's SDKs and APIs. Includes demos for Chain Abstraction using AppKit, a React dApp with a standalone v2 client, smart sessions, and wallet examples utilizing the Sign SDK and Wallet Development Kit (WDK) for multi-chain key derivation across EVM, Solana, and TON.
What's inside reown-com/web-examples
- This repository serves as a catalogue of various wallet and dApp examples that implement WalletConnect's SDKs and APIs. It is organized into two main categories: Wallets and dApps. Each example is a standalone project containing its own specific README with detailed setup instructions, implementation details, and explanations.
How WDK handles multi-chain key derivation
mainThe wallet uses the Tether Wallet Development Kit (WDK) to derive accounts for multiple chains from a single 24-word BIP-39 seed phrase. The derivation paths used are:
- EVM: Uses
@tetherto/wdk-wallet-evmwith BIP-44m/44'/60'/0'/0/0. - Solana: Uses
@tetherto/wdk-wallet-solanawith SLIP-0010m/44'/501'/0'/0'. - TON: Uses
@tetherto/wdk-wallet-tonwith BIP-44,WalletContractV5R1.
Key management is centralized in
src/lib/WDKWallet.ts. The Solana and TON signers do not hold keys; they bridge WalletConnect payloads to the rawkeyPairexposed by WDK.- EVM: Uses
Understand the Wallet Example Architecture
mainThe React Wallet Example is built with Next.js and follows a specific flow for handling WalletConnect logic:
- Initialization: Occurs in
_app.tsx. TheuseInitialization.tshook is responsible for initializing the WalletConnect client, ethers, and cosmos wallets. - Event Management: The
useWalletConnectEventsManager.tshook manages subscriptions and handles WalletConnect events. It triggers the appropriate Modal views. - UI/UX (Modals): Modal views handle data display and user actions (approving or rejecting requests).
- Request Handling: Once a user acts on a modal, the data is passed to
RequestHandlerUtil.ts. This utility performs the necessary work based on the request method and returns formatted JSON-RPC result data to be used for WalletConnect client responses.
- Initialization: Occurs in
Explore dApp implementation examples
mainFor developers looking to build decentralized applications (dApps) that connect to wallets via WalletConnect, the following examples are available:
- React dApp v2: A React-based dApp implementation.
- Chain Abstraction Demo: A demonstration of chain abstraction capabilities.
- Smart Sessions Demo: A demonstration of Smart Sessions functionality.
Setup the React Wallet Example
mainThis example demonstrates basic and advanced use cases for WalletConnect's Sign SDK, implementing both Sign v1 and v2 side-by-side.
Warning: The wallet uses legacy v1 implementation files (prefixed with
Legacy...) for backwards compatibility reference. Use this for development purposes only; do not use it for managing real funds.Prerequisites
- Obtain a Project ID from WalletConnect Cloud.
- Add your Project ID to the
src/utils/WalletConnectUtil.tsfile.
Installation Steps
- Install dependencies:
yarn install
or
npm install
2. Setup environment variables: ```bash cp .env.local.example .env.local- Start the development server:
yarn dev
or
npm run dev
### Environment Variables - `NEXT_PUBLIC_PROJECT_ID`: Your WalletConnect Project ID. - `NEXT_PUBLIC_RELAY_URL`: The relay URL (pre-configured).cp .env.local.example .env.local yarn devDeploy pos-dapp to Vercel
mainThepos-dappproject can be deployed using the Vercel platform. For detailed instructions on the deployment process, refer to the official Next.js deployment documentation.Set up the Chain Abstraction Demo
mainThe Chain Abstraction Demo is an application that demonstrates how to use Reown's AppKit to enable seamless stablecoin transfers across multiple networks.
To run the demo locally, follow these steps:
- Configure Environment Variables:
- Copy
.env.exampleto a new file named.envin the project root. - Obtain a Project ID from Reown Cloud.
- Add your Project ID to the
.envfile.
- Copy
- Install Dependencies: Use
npm,yarn,pnpm, orbunto install the required packages. - Start the Server: Run the development script to launch the application.
Once running, access the application at
http://localhost:3000. You can modify the UI by editingapp/page.tsx.# 1. Setup environment cp .env.example .env # (Add your Project ID to .env) # 2. Install dependencies npm install # 3. Start development server npm run dev- Configure Environment Variables:
Setup the WDK Wallet Example
mainTo run the WDK Wallet Example, ensure you have Node.js 18+ and
pnpminstalled. You must also have a WalletConnect/Reown Project ID from the Reown Dashboard.- Install dependencies:
pnpm install - Configure environment variables:
cp .env.local.example .env.local - Edit
.env.localto include yourNEXT_PUBLIC_PROJECT_ID. - Start the development server:
The app will be available atpnpm devhttp://localhost:3002.
pnpm install cp .env.local.example .env.local pnpm dev- Install dependencies:
Run, test, and build the React dApp
mainUse the following commands to manage the application lifecycle:
- Development: Start the local development server with
yarn dev. - Testing: Run the test suite with
yarn test. - Production Build: Generate a production build with
yarn build.
yarn dev yarn test yarn build- Development: Start the local development server with
Set up the React dApp (with standalone v2 client)
mainThis example demonstrates how to implement a React dApp using the standalone WalletConnect v2 client to handle pairings, manage sessions, and send JSON-RPC requests to paired wallets.
To run this project locally, follow these steps:
- Install dependencies: Use
yarnto install the required packages. - Configure environment variables: Copy the provided example file to
.env.local. - Provide a Project ID: You must replace the placeholder in
NEXT_PUBLIC_PROJECT_IDwith a valid ID generated from WalletConnect Cloud.
# Install dependencies yarn # Set up environment variables cp .env.local.example .env.local- Install dependencies: Use
Implement WalletConnect Pay flow
mainThe WalletConnect Pay implementation is fully client-side and uses your
projectId(viapayConfig.appId) for authentication. The workflow for processing a Pay link is:- Detect Link: Use
isPaymentLink(uri)to identify a Pay link. - Fetch Options: Call
getPaymentOptions({ paymentLink, accounts })to retrieve available payment options (e.g., EVM or Solana accounts). - Select Option: The user selects a specific payment option.
- Get Actions: Call
getRequiredPaymentActions({ paymentId, optionId })to retrieve the necessary signing actions. - Sign Actions: Sign each action using the WDK-derived key.
- EVM: Signs EIP-712 typed data (e.g., EIP-2612 or Permit2).
- Solana: Signs via a
SolanaSignerbridge.
- Confirm: Call
confirmPayment({ paymentId, optionId, signatures })to finalize.
// Conceptual flow for WalletConnect Pay const options = await getPaymentOptions({ paymentLink, accounts }); const selectedOption = options[0]; const actions = await getRequiredPaymentActions({ paymentId, optionId: selectedOption.id }); // Sign actions using WDK-derived keys const signatures = await Promise.all(actions.map(action => signAction(action))); await confirmPayment({ paymentId, optionId: selectedOption.id, signatures });- Detect Link: Use
Run the smart-sessions-demo development server
mainTo start the development server for the
smart-sessions-demoproject, use one of the following package manager commands in your terminal. Once running, the application will be available athttp://localhost:3000.npm run dev # or yarn dev # or pnpm dev # or bun dev