Skip to content
LogoLogo

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
paymasterContextRecord<string, unknown>NoCustom paymaster context for gas sponsorship
storageSyncStorageNoCustom storage implementation (defaults to localStorage on web, in-memory fallback in React Native)
nativeGetFnNativePasskeyGetFnNoNative passkey get function for React Native (e.g. Passkey.get). See React Native Usage.
nativeCreateFnNativePasskeyCreateFnNoNative passkey create function for React Native (e.g. Passkey.create). See React Native Usage.
rpIdstringNoRelying party identifier (defaults to window.location.hostname). Required in React Native.
rpNamestringNoRelying party name (defaults to 'JAW')

options

Type: CreateAccountOptions

PropertyTypeRequiredDescription
usernamestringYesUsername/display name for the passkey

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', rpId: 'myapp.com', rpName: 'My Awesome App' },
  { username: 'alice' }
);

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 }],
      },
    };
  }
}

React Native Usage

In React Native, window and navigator.credentials are unavailable. Pass Passkey.get and Passkey.create from react-native-passkey directly in config — JAW handles all format conversion, challenge generation, and public key extraction internally.

import { Account } from '@jaw.id/core';
import { Passkey } from 'react-native-passkey';
import type { SyncStorage } from '@jaw.id/core';
 
// Your SyncStorage backed by MMKV or similar
const storage: SyncStorage = {
  /* ... */
};
 
// Configure once — all RN options live in config
const config = {
  chainId: 8453,
  apiKey: 'your-api-key',
  storage,
  nativeGetFn: Passkey.get,
  nativeCreateFn: Passkey.create,
  rpId: 'myapp.com',
  rpName: 'My App',
};
 
const account = await Account.create(config, { username: 'alice' });