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
| Property | Type | Required | Description |
|---|---|---|---|
chainId | number | Yes | Chain ID for the account |
apiKey | string | Yes | API key for JAW services |
paymasterUrl | string | No | Custom paymaster URL for gas sponsorship |
paymasterContext | Record<string, unknown> | No | Custom paymaster context for gas sponsorship |
storage | SyncStorage | No | Custom storage implementation (defaults to localStorage on web, in-memory fallback in React Native) |
nativeGetFn | NativePasskeyGetFn | No | Native passkey get function for React Native (e.g. Passkey.get). See React Native Usage. |
nativeCreateFn | NativePasskeyCreateFn | No | Native passkey create function for React Native (e.g. Passkey.create). See React Native Usage. |
rpId | string | No | Relying party identifier (defaults to window.location.hostname). Required in React Native. |
rpName | string | No | Relying party name (defaults to 'JAW') |
options
Type: CreateAccountOptions
| Property | Type | Required | Description |
|---|---|---|---|
username | string | Yes | Username/display name for the passkey |
Returns
Promise<Account> - The newly created Account instance
Behavior
- Triggers WebAuthn credential creation (user will see browser passkey dialog)
- Creates the smart account from the passkey
- Stores the passkey account and authentication state
- Returns the ready-to-use Account instance
Errors
| Error | Description |
|---|---|
| WebAuthn errors | User cancelled passkey creation or browser doesn't support WebAuthn |
| Network errors | Failed 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' });Related
- Account.get() - Login with existing account
- Account.import() - Import from cloud backup
- Account.getStoredAccounts() - List created accounts