Initializing the Library
This guide shows how to initialize the Nevermined Payments Library in your application. The library supports both server-side (Node.js) and browser environments with different initialization methods.Get Your NVM API Key
Before initializing the library, you need a Nevermined API key:- Visit nevermined.app
- Sign in or create a free account
- Navigate to your profile settings
- Generate an API key
- Builder Key: For AI builders who register agents and payment plans
- Subscriber Key: For users who purchase access and query agents
Server-Side Initialization
For Node.js applications, use thegetInstance method:
Configuration Options
ThegetInstance method accepts a PaymentOptions object:
Complete Server-Side Example
Browser Initialization
For browser-based applications, use thegetBrowserInstance method:
Browser Authentication Flow
The browser instance supports OAuth-style authentication:Environments
The Nevermined protocol supports multiple environments:Production Environments
| Environment | Description | Usage |
|---|---|---|
sandbox | Production testing environment | Development and testing with real blockchain |
live | Production environment | Live agents and real payments |
Choosing an Environment
Environment Configuration Details
Each environment has specific API endpoints:Verify Connection
After initialization, verify the connection is working:Best Practices
- Environment Variables: Always store API keys in environment variables, never hardcode them
- Singleton Pattern: Create one Payments instance per application
- Environment Consistency: Use the same environment for all operations in a session
- Error Handling: Wrap initialization in try-catch blocks for production apps
Related Documentation
Source References:
src/payments.ts(getInstance, getBrowserInstance methods)src/environments.ts(environment configurations)tests/e2e/fixtures.ts(createPaymentsBuilder, createPaymentsSubscriber)