Skip to main content

userRole

Get role information for a user on Hyperliquid, including permissions, access levels, and account capabilities.

When to Use This Endpoint#

The userRole endpoint is essential for:

  • Permission Checking — Verify user access levels and capabilities
  • Access Control — Implement role-based access in applications
  • Feature Gating — Enable/disable features based on user role
  • Account Management — Understand account type and permissions

Request#

Endpoint#

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

Headers#

HeaderValueRequired
Content-Typeapplication/jsonYes
X-Api-KeyYour API keyYes

Parameters#

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

Example Request#

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

Response#

Success Response#

Returns role information for the specified user.

{
"role": "standard"
}

Response Fields#

FieldTypeDescription
rolestringUser's role on the platform (e.g., "standard", "vip", "market_maker")

Code Examples#

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

Common Use Cases#

1. Check User Permissions#

Verify user role for access control:

async function checkUserPermissions(userAddress) {
const roleData = await getUserRole(userAddress);

console.log('=== User Permissions ===\n');
console.log(`Role: ${roleData.role}`);

return roleData.role;
}

// Usage
const role = await checkUserPermissions('0x63E8c7C149556D5f34F833419A287bb9Ef81487f');

2. Role-Based Feature Access#

Implement role-based feature gating:

async function canAccessFeature(userAddress, featureName) {
const roleData = await getUserRole(userAddress);

// Define feature access by role
const featureAccess = {
standard: ['basic_trading', 'view_data'],
vip: ['basic_trading', 'view_data', 'advanced_analytics', 'priority_support'],
market_maker: ['basic_trading', 'view_data', 'advanced_analytics', 'market_making', 'api_access']
};

const userFeatures = featureAccess[roleData.role] || [];
const hasAccess = userFeatures.includes(featureName);

console.log(`Feature "${featureName}": ${hasAccess ? 'Granted' : 'Denied'}`);
return hasAccess;
}

// Usage
const canUseAdvancedAnalytics = await canAccessFeature(
'0x63E8c7C149556D5f34F833419A287bb9Ef81487f',
'advanced_analytics'
);

3. Display Role Badge#

Show user role in UI:

async function getUserRoleBadge(userAddress) {
const roleData = await getUserRole(userAddress);

const badges = {
standard: { label: 'Standard', color: 'gray' },
vip: { label: 'VIP', color: 'gold' },
market_maker: { label: 'Market Maker', color: 'blue' }
};

return badges[roleData.role] || { label: 'User', color: 'gray' };
}

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

4. Build Access Control System#

Create comprehensive access control:

class AccessControl {
constructor(userAddress) {
this.userAddress = userAddress;
this.role = null;
}

async initialize() {
const roleData = await getUserRole(this.userAddress);
this.role = roleData.role;
return this.role;
}

hasPermission(permission) {
const permissions = {
standard: ['read', 'basic_trade'],
vip: ['read', 'basic_trade', 'advanced_trade', 'analytics'],
market_maker: ['read', 'basic_trade', 'advanced_trade', 'analytics', 'market_make', 'api']
};

const userPermissions = permissions[this.role] || [];
return userPermissions.includes(permission);
}

getPermissions() {
const permissions = {
standard: ['read', 'basic_trade'],
vip: ['read', 'basic_trade', 'advanced_trade', 'analytics'],
market_maker: ['read', 'basic_trade', 'advanced_trade', 'analytics', 'market_make', 'api']
};

return permissions[this.role] || [];
}
}

// Usage
const acl = new AccessControl('0x63E8c7C149556D5f34F833419A287bb9Ef81487f');
await acl.initialize();

if (acl.hasPermission('advanced_trade')) {
console.log('User can access advanced trading');
}

5. Role-Based Dashboard#

Customize dashboard based on user role:

async function buildRoleBasedDashboard(userAddress) {
const roleData = await getUserRole(userAddress);

const dashboardConfig = {
standard: {
widgets: ['account_summary', 'basic_charts', 'order_book'],
features: ['basic_trading']
},
vip: {
widgets: ['account_summary', 'advanced_charts', 'order_book', 'analytics'],
features: ['basic_trading', 'advanced_trading', 'analytics']
},
market_maker: {
widgets: ['account_summary', 'advanced_charts', 'order_book', 'analytics', 'api_stats'],
features: ['basic_trading', 'advanced_trading', 'analytics', 'market_making', 'api_access']
}
};

const config = dashboardConfig[roleData.role] || dashboardConfig.standard;

return {
role: roleData.role,
dashboard: config,
timestamp: new Date().toISOString()
};
}

// Usage
const dashboard = await buildRoleBasedDashboard('0x63E8c7C149556D5f34F833419A287bb9Ef81487f');
console.log('Dashboard configuration:', dashboard);

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 safeGetUserRole(userAddress, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await getUserRole(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 role data — Role changes infrequently, cache for 5-10 minutes
  2. Validate addresses — Ensure user addresses are valid Ethereum addresses
  3. Default to least privilege — Use most restrictive role as default
  4. Handle unknown roles — Have fallback for unrecognized roles
  5. Implement feature flags — Combine with feature flags for flexible access control

Performance Tips#

Cached Role Checker#

class CachedRoleChecker {
constructor(cacheDurationMs = 300000) {
this.cache = new Map();
this.cacheDurationMs = cacheDurationMs; // 5 minutes
}

async getRole(userAddress) {
const cached = this.cache.get(userAddress);
const now = Date.now();

if (cached && (now - cached.timestamp) < this.cacheDurationMs) {
return cached.role;
}

const roleData = await getUserRole(userAddress);
this.cache.set(userAddress, {
role: roleData.role,
timestamp: now
});

return roleData.role;
}

invalidate(userAddress) {
this.cache.delete(userAddress);
}

clearAll() {
this.cache.clear();
}
}

// Usage
const roleChecker = new CachedRoleChecker();
const role = await roleChecker.getRole('0x63E8c7C149556D5f34F833419A287bb9Ef81487f');

Implement role-based access control with Dwellir's HyperCore Info Endpoint. Get your API key →