A developer demo showcasing how to integrate Particle Network's Universal Accounts SDK to build cross-chain trading functionality. This app demonstrates chain abstraction, where users can trade tokens on Monad using a unified balance from any supported chain.
This demo teaches you how to:
- Initialize the Universal Account SDK - Connect to Particle Network's infrastructure
- Fetch unified balances - Get aggregated balance across all supported chains
- Execute buy/sell transactions - Trade tokens with chain abstraction
- Preview transaction fees - Estimate costs before executing trades
ua-dex/
├── app/
│ ├── components/
│ │ ├── Widget.tsx # Main UA widget - SDK initialization & balance fetching
│ │ ├── TrendingTokens.tsx # Token list component
│ │ └── widget/
│ │ ├── BuyTabContent.tsx # Buy transaction logic
│ │ ├── SellTabContent.tsx # Sell transaction logic
│ │ └── AssetsDialog.tsx # Assets breakdown display
│ ├── api/token/ # Backend API routes (Moralis integration)
│ │ ├── trending/route.ts # Fetch trending tokens
│ │ ├── metadata/route.ts # Token metadata
│ │ └── price/route.ts # Token prices
│ └── page.tsx # Main page layout
├── lib/
│ ├── types.ts # TypeScript interfaces
│ └── utils.ts # Helper functions
└── components/ui/ # Shadcn UI components
// app/components/Widget.tsx
import { UniversalAccount } from "@particle-network/universal-account-sdk";
const universalAccount = new UniversalAccount({
projectId: process.env.NEXT_PUBLIC_PROJECT_ID,
projectClientKey: process.env.NEXT_PUBLIC_CLIENT_KEY,
projectAppUuid: process.env.NEXT_PUBLIC_APP_ID,
ownerAddress: address, // Connected wallet address
});// Get total balance across all chains
const { totalAmountInUSD, assets } = await universalAccount.getPrimaryAssets();
// assets contains breakdown by chain/token
for (const asset of assets) {
console.log(`${asset.tokenType}: $${asset.amountInUSD}`);
}// app/components/widget/BuyTabContent.tsx
const transaction = await universalAccount.createBuyTransaction({
token: { chainId: 143, address: tokenAddress }, // Monad chainId
amountInUSD: "10", // Buy $10 worth using unified balance
});
// Sign with connected wallet
const signature = await walletClient.signMessage({
account: address,
message: { raw: transaction.rootHash },
});
// Send transaction
const result = await universalAccount.sendTransaction(transaction, signature);
console.log(
`TX: https://universalx.app/activity/details?id=${result.transactionId}`
);// app/components/widget/SellTabContent.tsx
const transaction = await universalAccount.createSellTransaction({
token: { chainId: 143, address: tokenAddress },
amount: "100", // Sell 100 tokens
});
const signature = await walletClient.signMessage({
account: address,
message: { raw: transaction.rootHash },
});
const result = await universalAccount.sendTransaction(transaction, signature);- Node.js 18+
- Particle Network credentials (Project ID, Client Key, App ID)
- Moralis API Key (for token data)
-
Clone and install:
git clone https://github.com/soos3d/instant-trade-widget.git cd ua-dex yarn install -
Create
.env.local:NEXT_PUBLIC_PROJECT_ID="" NEXT_PUBLIC_CLIENT_KEY="" NEXT_PUBLIC_APP_ID="" NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID="" MORALIS_API_KEY=""
-
Run:
yarn dev
| API | Purpose |
|---|---|
| Particle Universal Accounts SDK | Chain abstraction, unified balance, transactions |
| Particle Connect | Wallet connection (MetaMask, WalletConnect, social) |
| Moralis EVM API | Token metadata, prices, trending tokens |
MIT