Overview
The browser entry point provides IndexedDB-based key storage for web applications. It includes all universal features plus browser-specific key management capabilities.Installation
Import Paths
Automatic (Recommended)
The package automatically resolves to the browser build when imported in browser environments:Explicit
You can explicitly import the browser version:Browser-Specific Features
IndexedDB Key Service
The browser build includescreateIdbKeyService for secure key storage using the browser’s IndexedDB API.
Creating an IDB Key Service
API Methods
The IDB key service provides the following methods:IndexedDB Structure
The service creates an IndexedDB database with:- Database name: Configurable via
idbName(default:'near-api-ts') - Object store:
'keyPairs' - Key: Public key (string)
- Value: Private key (string)
Security Considerations
- Keys are stored in IndexedDB, which is origin-scoped
- Private keys are accessible only to scripts from the same origin
- File permissions are set to
0o600on the server side equivalent - Consider using additional encryption for sensitive applications
Complete Browser Example
Browser Compatibility
The browser build requires:- Modern browser with ES2020+ support
- IndexedDB API support (all modern browsers)
- WebCrypto API support
Available Exports
The browser entry point exports:Browser-Specific
createIdbKeyService- Create IndexedDB key service (throwable)safeCreateIdbKeyService- Create IndexedDB key service (safe)
Universal Features
All exports from the universal module:- Client creation functions
- Memory key service
- Memory signer
- Action creators
- Token and gas helpers
- Key pair utilities
- Error handling
- Type definitions
Migration from Near-API-JS
If you’re migrating fromnear-api-js:
- Uses IndexedDB instead of localStorage for better performance
- Async API for all operations
- Result/Error pattern for better error handling
- TypeScript-first design
See Also
- Node.js Platform - File-based key storage for Node.js
- Universal Platform - Cross-platform features
- Key Services - Key service concepts and patterns