This tutorial demonstrates how to integrate Particle Network's Universal Accounts into your dApp using viem for wallet connection and transaction execution.
-
Wallet Connection with Viem
- Connect with MetaMask using viem
- Handle wallet state and events
- Manage wallet reconnection
-
Universal Account Creation
- Initialize Universal Account with user's EOA
- Configure account settings including gas payment options
-
Account Information
- View EVM smart account address
- View Solana smart account address
- Check unified token balances across chains
- Explore detailed portfolio breakdown
-
Universal Transactions
- Execute a simple USDT request on Avalanche
- Handle transaction states and errors
- View transaction details on Universal Explorer
-
Clone the repository:
git clone https://github.com/soos3d/universal-accounts-viem-starter.git cd universal-accounts-viem-starter/ethers-universal-accounts -
Install dependencies:
npm install # or yarn -
Configure environment variables: Create a
.env.localfile with your Particle Network credentials:NEXT_PUBLIC_PROJECT_ID=your_project_id NEXT_PUBLIC_CLIENT_KEY=your_client_key NEXT_PUBLIC_APP_ID=your_app_idYou can obtain these credentials by creating a project in the Particle Network Dashboard
-
Run the development server:
npm run dev # or yarn dev -
Open http://localhost:3000 in your browser to see the demo.
-
Connect Wallet with Viem
- The app uses viem's
createWalletClientto connect to MetaMask - User's EOA address is captured and stored in state
- Wallet connection is managed with proper error handling
- The app uses viem's
-
Initialize Universal Account
- A Universal Account instance is created using the connected wallet as the owner
- Account configuration includes slippage settings and universal gas options
- The SDK handles the creation and management of smart accounts
-
View Account Information
- The app fetches and displays both EVM and Solana smart account addresses
- Token balances across all chains are retrieved and shown in a unified view
- A detailed portfolio breakdown is available showing tokens by chain
-
Execute Universal Transactions
- Users can request test USDT on Avalanche
- The transaction flow demonstrates:
- Creating a universal transaction
- Signing with the connected wallet
- Sending the transaction through Universal Account
- Viewing transaction results
app/page.tsx- Main component with wallet connection and Universal Account logicapp/components/WalletConnection.tsx- Handles wallet connection UI and stateapp/components/AccountInfo.tsx- Displays account addresses and balancesapp/components/Portfolio.tsx- Shows detailed token breakdown by chain