Skip to main content

userAbstraction

Get the account abstraction mode for a user on Hyperliquid, indicating whether the account operates in unified, portfolio margin, or another mode.

When to Use This Endpoint#

The userAbstraction endpoint is essential for:

  • Account Mode Detection — Determine how a user's account is configured
  • Margin Logic — Adapt margin calculations based on unified vs portfolio margin mode
  • UI Customization — Display the correct interface based on account abstraction type
  • Trading Logic — Adjust order placement and risk management based on account mode

Request#

Endpoint#

POST https://api-hyperliquid-mainnet-info.n.dwellir.com/API_KEY/info

Headers#

HeaderValueRequired
Content-Typeapplication/jsonYes

Parameters#

ParameterTypeRequiredDescription
typestringYesMust be "userAbstraction"
userstringYesUser's Ethereum wallet address

Example Request#

{
"type": "userAbstraction",
"user": "0x63E8c7C149556D5f34F833419A287bb9Ef81487f"
}

Response#

Success Response#

Returns a string indicating the account abstraction mode for the specified user.

"unifiedAccount"

Possible Values#

ValueDescription
unifiedAccountUnified account mode — perps and spot share a single margin pool
portfolioMarginPortfolio margin mode — margin calculated across the full portfolio
disabledAccount abstraction is disabled
defaultDefault account mode

Code Examples#

curl -X POST 'https://api-hyperliquid-mainnet-info.n.dwellir.com/API_KEY/info' \
-H 'Content-Type: application/json' \
-d '{
"type": "userAbstraction",
"user": "0x63E8c7C149556D5f34F833419A287bb9Ef81487f"
}'

Common Use Cases#

1. Check Account Mode#

Determine the account abstraction mode before executing trades:

async function checkAccountMode(userAddress) {
const mode = await getUserAbstraction(userAddress);

console.log('=== Account Mode ===\n');
console.log(`Mode: ${mode}`);

return mode;
}

// Usage
const mode = await checkAccountMode('0x63E8c7C149556D5f34F833419A287bb9Ef81487f');

2. Adapt Trading Logic#

Adjust trading behavior based on account mode:

async function getTradeConfig(userAddress) {
const mode = await getUserAbstraction(userAddress);

const configs = {
unifiedAccount: {
marginShared: true,
spotAndPerpsLinked: true,
description: 'Perps and spot share a single margin pool'
},
portfolioMargin: {
marginShared: true,
spotAndPerpsLinked: true,
description: 'Margin calculated across the full portfolio'
},
disabled: {
marginShared: false,
spotAndPerpsLinked: false,
description: 'Standard isolated margin mode'
},
default: {
marginShared: false,
spotAndPerpsLinked: false,
description: 'Default account configuration'
}
};

return configs[mode] || configs['default'];
}

// Usage
const config = await getTradeConfig('0x63E8c7C149556D5f34F833419A287bb9Ef81487f');
console.log(`Mode: ${config.description}`);
console.log(`Margin shared: ${config.marginShared}`);

3. Display Account Mode Badge#

Show account mode in a dashboard:

async function getAccountModeBadge(userAddress) {
const mode = await getUserAbstraction(userAddress);

const badges = {
unifiedAccount: { label: 'Unified Account', color: 'green' },
portfolioMargin: { label: 'Portfolio Margin', color: 'blue' },
disabled: { label: 'Standard', color: 'gray' },
default: { label: 'Default', color: 'gray' }
};

return badges[mode] || { label: mode, color: 'gray' };
}

// Usage
const badge = await getAccountModeBadge('0x63E8c7C149556D5f34F833419A287bb9Ef81487f');
console.log(`Display badge: ${badge.label} (${badge.color})`);

Error Handling#

Common Errors#

ErrorCauseSolution
401 UnauthorizedInvalid API keyVerify your API key is correct
400 Bad RequestMissing or invalid user addressEnsure valid Ethereum address format
429 Too Many RequestsRate limit exceededImplement request throttling
500 Internal Server ErrorServer issueRetry with exponential backoff

Error Response Example#

{
"error": "Missing required parameter: user",
"code": "MISSING_PARAMETER"
}

Robust Error Handling#

async function safeGetUserAbstraction(userAddress, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await getUserAbstraction(userAddress);
} catch (error) {
if (error.response?.status === 429) {
await new Promise(r => setTimeout(r, Math.pow(2, i) * 1000));
} else if (error.response?.status === 400) {
throw new Error('Invalid user address');
} else if (i === maxRetries - 1) {
throw error;
}
}
}
}

Best Practices#

  1. Cache mode data — Account mode changes infrequently, cache for 5-10 minutes
  2. Validate addresses — Ensure user addresses are valid Ethereum addresses
  3. Handle unknown modes — Have fallback logic for unrecognized mode values
  4. Check before trading — Query account mode before placing orders that depend on margin type
  5. Update on mode change — Invalidate cached data when users switch account modes

Check account abstraction modes with Dwellir's HyperCore Info Endpoint. Get your API key →