Skip to content

Particle-Network/universal-account-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Universal Account Example

Code examples for the Particle Network Universal Account SDK.

Quick Start

  1. yarn
  2. Copy .env.example to .env and fill in your own values
  3. Run any example:
npx tsx examples/buy-solana.ts

Examples

Buy / Sell

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

Transfer

Example Description
transfer-evm.ts Transfer EVM tokens
transfer-solana.ts Transfer Solana tokens

Convert

Example Description
convert-evm.ts Convert tokens on EVM
convert-solana.ts Convert tokens on Solana

Custom Transaction

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

EIP-7702

Example Description
7702-create-delegated.ts Create delegated account with EIP-7702
7702-convert-evm.ts Convert tokens using EIP-7702 mode

Query

Example Description
get-primary-asset.ts Get primary assets and USD values
get-transactions.ts Query transaction history

WebSocket

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

address-update — Transaction Status

Subscribe with your UA addresses to receive real-time transaction status updates.

// Subscribe
{ "type": "subscribe", "channel": "address-update", "params": { "addresses": ["0x...", "solana_address"] } }

// Incoming message
{ "type": "transaction_update", "channel": "address-update", "data": { "transactionId": "...", "status": 7, "sender": "..." } }
// status: 7 = success, 11 = failure

See transaction-status-wss.ts for a complete example that sends a transaction and waits for confirmation via WebSocket.

user-assets — Real-time Balance Updates

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.

Other

Example Description
warmup.ts Initialization / warmup
polymarket.ts Polymarket integration
test-svm-balance.ts Solana balance test suite

Benchmark

For transaction speed benchmarking, see universal-account-benchmark.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors