Skip to main content
This guide will help you set up and initialize the Nevermined Payment Libraries to start monetizing your AI services.

Prerequisites

Before you begin, make sure you have:
1

Development Environment

  • Node.js 16+ and npm/yarn (for TypeScript)
  • Python 3.8+ (for Python)
  • A code editor (VS Code recommended)
2

Blockchain Wallet

  • MetaMask or compatible wallet
  • Some test tokens for the testing environment
3

Nevermined API Key

Get your API key from the Nevermined App

Installation

npm install @nevermined-io/payments
# or
yarn add @nevermined-io/payments

Getting Your API Key

  1. Go to the Nevermined App
  2. Log in with your wallet
  3. Navigate to the Settings section in the user menu
  4. Click on the API Keys tab
  5. Generate a new key, give it a descriptive name, and copy it
  6. Store this key securely as an environment variable (e.g., NVM_API_KEY)
Never expose your API key in client-side code or commit it to version control. Always use environment variables.

Initialize the SDK

import { Payments } from '@nevermined-io/payments'

const payments = Payments.getInstance({
  nvmApiKey: process.env.NVM_API_KEY,
  environment: 'testing' // or 'production'
})

Environment Configuration

Choose the appropriate environment for your use case:
  • Network: Base Sepolia testnet
  • Use case: Development and testing
  • Tokens: Test tokens (free)
  • Environment: 'testing'
  • Network: Base Mainnet
  • Use case: Live applications
  • Tokens: Real tokens (paid)
  • Environment: 'production'

Basic Configuration Example

Here’s a complete example of setting up the Payments client:
import { Payments } from '@nevermined-io/payments'
import dotenv from 'dotenv'

// Load environment variables
dotenv.config()

// Initialize the Payments client
const payments = Payments.getInstance({
  nvmApiKey: process.env.NVM_API_KEY!,
  environment: 'testing', // Start with testing
  // Optional: specify custom RPC endpoints
  // web3ProviderUri: 'https://your-custom-rpc-endpoint.com'
})

// Verify the connection
console.log('Payments client initialized successfully')

Environment Variables Setup

Create a .env file in your project root:
# Required
NVM_API_KEY=your_api_key_here

# Optional - for custom configurations
WEB3_PROVIDER_URI=https://your-custom-rpc-endpoint.com
BUILDER_ADDRESS=your_wallet_address_here

Verification

Test your setup with a simple verification:
async function verifySetup() {
  try {
    // Test the connection by checking if the client is properly initialized
    const config = await payments.getConfig()
    console.log('Setup verified! Environment:', config.environment)
    return true
  } catch (error) {
    console.error('Setup verification failed:', error)
    return false
  }
}

verifySetup()

Next Steps

Now that you have the Nevermined Payment Libraries set up, you can:

Common Issues

Make sure your API key is correctly set in your environment variables and has the proper permissions.
Check that you’re using the correct environment (‘testing’ or ‘production’) and that your network connection is stable.
Ensure your wallet has some test tokens for the testing environment or real tokens for production.
If you encounter any issues, check our Troubleshooting Guide or reach out to our community on Discord.