- Initialize a Universal Account after a user logs in.
- Fetch and display the user’s Universal Account addresses.
- Fetch and display the user’s unified balance across chains.
This example showcases a Next.js app using Particle Auth as its login method.However, the same logic can be applied to any other EOA-based provider or signer.
Getting Started
To start integrating Universal Accounts:1
Clone the Quickstart Repository
This repository includes the full working demo app.
Terminal
2
Set Environment Variables
First, create a project in the Particle Dashboard to get the required credentials.In this example, we use Particle Auth for user authentication. However, you can use any EOA-compatible provider or signer.Regardless of your choice, you’ll still need to create a project in the Particle Dashboard and initialize Universal Accounts using the project credentials.Create a
The same project keys are used for both Particle Auth and Universal Accounts.
.env
file in the root of the ua-quickstart
directory with the following variables:.env
3
Install Dependencies
Install the project dependencies using your preferred package manager:
4
Run the App
Start the development server:Once the app is running, log in with any supported method via Particle Auth. After logging in, the app will display your Universal Account addresses and unified balance.
Universal Accounts are standalone smart accounts. As such, to fund yours, you will need to transfer assets into it—unless you’re logging into a pre-existing Universal Account, created through UniversalX or any other Universal Accounts-enabled app.
Features Walkthrough
1. Universal Account Initialization
After the user logs in, the app creates a new Universal Account instance inside auseEffect
.
The constructor requires:
- The connected user’s address.
- Your Particle project credentials.
- Optional config settings.
page.tsx
In this case, the user’s address is retrieved directly from Particle Auth after they log in.
Universal Account Initialization in the Repository
Code location:
page.tsx
→ useEffect
watching connected && address
2. Fetching a Universal Account’s Addresses
The app fetches a Universal Account’s EVM and Solana Universal Account addresses usinggetSmartAccountOptions()
.
This returns a UA’s:
- EOA/Owner Account (from Particle Auth).
- EVM Universal Account address.
- Solana Universal Account address.
page.tsx
Fetching Smart Account Addresses in the Repository
Code location:
page.tsx
→ useEffect
watching universalAccount && address
3. Fetching A Universal Account’s Unified Balance
To show the user’s total balance of Primary Assets across chains, the app usesgetPrimaryAssets()
from the Universal Accounts SDK.
This returns:
totalAmountInUSD
- Detailed breakdown per token + chain (if needed).
Full Primary Assets Breakdown
Learn how to retrieve a full Primary Assets breakdown on our SDK reference.
page.tsx
page.tsx
Primary Assets are key tokens for which Universal Accounts have deep liquidity. As such, the SDK uses them as the base assets for any cross-chain operation—including gas, swaps, and liquidity routing.
Fetching Unified Balance in the Repository
Code location:
page.tsx
→ useEffect
watching universalAccount && address
4. Sending Transactions
Within the demo app, you can find examples for two types of transactions, both using a Universal Account:- A custom contract call with its destination on the Base Mainnet.
- A USDT swap on Arbitrum.
Contract Call Example
To interact with a smart contract—such as calling a function likecheckIn()
—you can use createUniversalTransaction()
with the transactions
and expectTokens
fields.
This method lets you define one or more contract calls while specifying which tokens the contract expects to receive or require:
page.tsx
provider
instance of Particle Auth is used to sign the transaction directly.
In this example, the transaction expects 0.0000001 ETH on Base Mainnet. Even if the user doesn’t have ETH on Base, Universal Accounts will convert assets from other chains to meet this requirement.
Send Custom Transaction in the Repository
Code location:
page.tsx
→ handleTransaction()
Token Swap Example
To swap tokens (e.g., 1 USDT on Arbitrum in this example), the demo app usescreateBuyTransaction()
.
It does so in the following way:
page.tsx
The user can use any token on any supported chain to initiate the transfer—Universal Accounts handle conversion to the destination asset and routing automatically.
Send Swap Transaction in the Repository
Code location:
page.tsx
→ handleTransferTransaction()
Full Code Reference
Check out the completepage.tsx
file below to see how everything fits together.
You can also copy/paste the below file into your project or use it as a base for your own integration:
page.tsx