Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Account.get()

Get an account instance - restores an existing session or triggers WebAuthn login.

Type: static async

Signature

static async get(
  config: AccountConfig,
  credentialId?: string
): Promise<Account>

Parameters

config

Type: AccountConfig

PropertyTypeRequiredDescription
chainIdnumberYesChain ID for the account
apiKeystringYesAPI key for JAW services
paymasterUrlstringNoCustom paymaster URL for gas sponsorship

credentialId

Type: string | undefined

Optional credential ID to login with. If provided and not already authenticated, triggers WebAuthn authentication.

Returns

Promise<Account> - The Account instance

Behavior

This is the primary method to get an Account instance:

  1. If credentialId is provided: Always triggers WebAuthn authentication, even if already authenticated. This ensures user verification when selecting a specific account.

  2. If no credentialId and already authenticated: Restores the account from storage without prompting WebAuthn.

  3. If no credentialId and not authenticated: Throws an error.

Errors

ErrorDescription
Not authenticatedNot authenticated and no credentialId provided
No account found for credential IDProvided credentialId doesn't exist in storage

Examples

Restore Existing Session

import { Account } from '@jaw.id/core';
 
// Restore without WebAuthn prompt (if already authenticated)
try {
  const account = await Account.get({
    chainId: 1,
    apiKey: 'your-api-key',
  });
  console.log('Restored account:', account.address);
} catch (error) {
  console.log('Not authenticated');
}

Login with Specific Account

import { Account } from '@jaw.id/core';
 
// Get stored accounts
const accounts = Account.getStoredAccounts('your-api-key');
 
if (accounts.length > 0) {
  // Login with first account (triggers WebAuthn)
  const account = await Account.get(
    { chainId: 1, apiKey: 'your-api-key' },
    accounts[0].credentialId
  );
  console.log('Logged in as:', account.address);
}

Related