This guide explains how to use Universal Accounts to convert existing Primary Assets across chains.
The Universal Accounts SDK supports powerful cross-chain execution through createUniversalTransaction().
This method ensures that a specified Primary Asset is made available on a destination chain—by sourcing and converting any supported Primary Asset from the user’s Universal Account, regardless of where they’re held.
In this example, we use it to convert any Primary Asset into a specific Primary Asset on any supported chain—with no bridges or manual steps, essentially creating a conversion transaction.This is ideal for use cases like topping up gas on a new chain, funding transactions in a required token, or consolidating assets into a preferred currency.
To initiate a cross-chain transaction, use createUniversalTransaction() with the following parameters:
chainId: the destination chain where the asset should be made available
expectTokens: a list of expected tokens and amounts you want to receive on the destination chain
transactions (optional): an array of follow-up actions to execute after the conversion (e.g., contract interactions). When empty, the converted tokens are sent back to the Universal Account.
Check out the Quickstart to learn how to set up Universal Accounts in your app.
The following snippet shows how to create a conversion transaction:
This method constructs a cross-chain execution plan that:
Detects available assets across all chains within the Universal Account
Calculates the optimal conversion path to fulfill the expectTokens requirement
If the user doesn’t have the expected token on the destination chain, the SDK will automatically convert and route value from other chains or tokens they hold—fully abstracted from the user.
Once the transaction object is built, the next step is to have the user sign it and submit it for execution.The returned transaction object includes important metadata, including the rootHash, which the user must sign to authorize the transaction.Here’s how you can sign and send the transaction using a browser wallet with ethers.js:
Copy
Ask AI
import { ethers, getBytes } from "ethers";// Initialize the provider and signerconst provider = new ethers.BrowserProvider(window.ethereum);const signer = await provider.getSigner();// Sign the root hashconst signature = await signer.signMessage( getBytes(transaction.rootHash));// Send the signed transactionconst result = await universalAccount.sendTransaction( transaction, signature);
Once signed and submitted, the transaction will execute on the destination chain, completing any asset conversions. The resulting tokens will be available in the user’s Universal Account balance.
The following is a complete TSX component that implements the conversion flow.This is a simple version and allows the user to convert any Primary Asset they hold into USDC on Base or Arbitrum.