Code examples for the Particle Network Universal Account SDK.
yarn- Copy
.env.exampleto.envand fill in your own values - Run any example:
npx tsx examples/buy-solana.ts| Example | Description |
|---|---|
| buy-evm.ts | Buy EVM tokens |
| buy-solana.ts | Buy Solana tokens |
| sell-evm.ts | Sell EVM tokens |
| sell-solana.ts | Sell Solana tokens |
| Example | Description |
|---|---|
| transfer-evm.ts | Transfer EVM tokens |
| transfer-solana.ts | Transfer Solana tokens |
| Example | Description |
|---|---|
| convert-evm.ts | Convert tokens on EVM |
| convert-solana.ts | Convert tokens on Solana |
| Example | Description |
|---|---|
| custom-transaction-evm-with-money.ts | EVM contract call with fund bridging |
| custom-transaction-evm-no-money.ts | EVM transaction without funding |
| custom-transaction-solana-with-money.ts | Solana instruction with USDC transfer |
| custom-transaction-solana-no-money.ts | Solana instruction without funding |
| Example | Description |
|---|---|
| 7702-create-delegated.ts | Create delegated account with EIP-7702 |
| 7702-convert-evm.ts | Convert tokens using EIP-7702 mode |
| Example | Description |
|---|---|
| get-primary-asset.ts | Get primary assets and USD values |
| get-transactions.ts | Query transaction history |
Universal Account provides a WebSocket endpoint for real-time push notifications. The default URL is wss://universal-app-ws-proxy.particle.network (configurable via UNIVERSALX_WSS_URL). All channels share the same connection and heartbeat mechanism (ping/pong every 5s).
| Example | Description |
|---|---|
| transaction-status-wss.ts | Track transaction status via address-update channel |
| user-assets-wss.ts | Subscribe to real-time balance updates via user-assets channel |
Subscribe with your UA addresses to receive real-time transaction status updates.
See transaction-status-wss.ts for a complete example that sends a transaction and waits for confirmation via WebSocket.
Subscribe with your smart account options to receive asset balance changes across all chains.
// Subscribe
{
"type": "subscribe",
"channel": "user-assets",
"params": {
"ownerAddress": "0x...",
"name": "UNIVERSAL",
"version": "1.0.3",
"useEIP7702": false,
"solanaAccountIndex": "SOLANA_ACCOUNT_INDEX.CLASSIC" // optional, use with EIP-7702 mode
}
}
// Incoming message
{
"channel": "user-assets",
"data": {
"assets": [
{ "chainId": 56, "address": "0x...", "amountOnChain": "10000000000000000000", "isToken2022": false, "accountExists": true }
]
}
}The solanaAccountIndex param is optional and only relevant when using EIP-7702 mode. It controls which Solana address is used for asset tracking:
| Constant | Description |
|---|---|
SOLANA_ACCOUNT_INDEX.CLASSIC |
Use the classic Solana smart account address |
SOLANA_ACCOUNT_INDEX.EIP7702 |
Use the EIP-7702 derived Solana address |
See user-assets-wss.ts for a complete example that listens for balance updates in real time.
| Example | Description |
|---|---|
| warmup.ts | Initialization / warmup |
| polymarket.ts | Polymarket integration |
| test-svm-balance.ts | Solana balance test suite |
For transaction speed benchmarking, see universal-account-benchmark.