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.create()

Create a new account with a passkey.

Type: static async

Signature

static async create(
  config: AccountConfig,
  options: CreateAccountOptions
): Promise<Account>

Parameters

config

Type: AccountConfig

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

options

Type: CreateAccountOptions

PropertyTypeRequiredDescription
usernamestringYesUsername/display name for the passkey
rpIdstringNoRelying party identifier (defaults to window.location.hostname)
rpNamestringNoRelying party name (defaults to 'JAW')

Returns

Promise<Account> - The newly created Account instance

Behavior

  1. Triggers WebAuthn credential creation (user will see browser passkey dialog)
  2. Creates the smart account from the passkey
  3. Stores the passkey account and authentication state
  4. Returns the ready-to-use Account instance

Errors

ErrorDescription
WebAuthn errorsUser cancelled passkey creation or browser doesn't support WebAuthn
Network errorsFailed to communicate with JAW services

Examples

Basic Usage

import { Account } from '@jaw.id/core';
 
const account = await Account.create(
  { chainId: 1, apiKey: 'your-api-key' },
  { username: 'alice' }
);
 
console.log('Created account:', account.address);
console.log('Username:', account.getMetadata()?.username);

With Custom RP Settings

const account = await Account.create(
  { chainId: 1, apiKey: 'your-api-key' },
  {
    username: 'alice',
    rpId: 'myapp.com',
    rpName: 'My Awesome App',
  }
);

Usage in Custom UI Handler

class MyUIHandler implements UIHandler {
  private config?: UIHandlerConfig;
 
  async handleConnect(request: ConnectUIRequest) {
    // Show your custom onboarding UI
    const username = await this.showUsernameInput();
 
    const account = await Account.create(
      {
        chainId: request.data.chainId,
        apiKey: this.config?.apiKey,
      },
      { username }
    );
 
    return {
      id: request.id,
      approved: true,
      data: {
        accounts: [{ address: account.address }],
      },
    };
  }
}

Related