Skip to main content

Use Case Guides

Comprehensive guides for common integration patterns and use cases. These guides provide step-by-step instructions for building real-world applications with NUVA Labs APIs.

Overview

This section covers practical use cases and integration patterns:

  • Wallet Applications: Building digital wallets
  • Trading Platforms: Creating trading interfaces
  • Payment Systems: Implementing payment solutions
  • Asset Management: Managing digital assets
  • Data Analytics: Building analytics dashboards
  • Compliance Tools: Implementing regulatory compliance

Wallet Applications

Building a Digital Wallet

A digital wallet allows users to store, send, and receive digital assets securely.

Key Features

  • Account creation and management
  • Asset storage and tracking
  • Send and receive functionality
  • Transaction history
  • Security features (2FA, biometrics)

Implementation Steps

  1. Set up authentication
import { NUClient } from '@nu/sdk';

const client = new NUClient({
clientId: process.env.NU_CLIENT_ID,
clientSecret: process.env.NU_CLIENT_SECRET,
environment: 'production',
});

await client.authenticate();
  1. Create user account
const account = await client.createAccount({
name: 'John Doe',
email: 'john@example.com',
type: 'user',
});
  1. Get user's assets
const assets = await client.getAssets();
const portfolio = await client.getPortfolio(account.id);
  1. Implement send functionality
const transfer = await client.transferAssets({
from: account.id,
to: recipientAccountId,
assetId: assetId,
amount: amount,
memo: 'Payment',
});
  1. Track transaction status
const status = await client.getTransactionStatus(transfer.id);
if (status.status === 'confirmed') {
console.log('Transfer completed');
}

Complete Example

class DigitalWallet {
constructor(client) {
this.client = client;
}

async createWallet(userData) {
const account = await this.client.createAccount({
name: userData.name,
email: userData.email,
type: 'user',
});

return account;
}

async getBalance(accountId) {
const portfolio = await this.client.getPortfolio(accountId);
return portfolio.positions;
}

async sendAssets(from, to, assetId, amount, memo) {
const transfer = await this.client.transferAssets({
from,
to,
assetId,
amount,
memo,
});

return transfer;
}

async getTransactionHistory(accountId) {
const history = await this.client.getTransactionHistory({
accountId,
limit: 100,
});

return history;
}
}

Trading Platforms

Creating a Trading Interface

A trading platform enables users to buy, sell, and trade digital assets.

Key Features

  • Order placement and management
  • Real-time market data
  • Portfolio tracking
  • Risk management
  • Trading history

Implementation Steps

  1. Set up market data connection
const ws = client.createWebSocket();

ws.on('priceUpdate', (price) => {
console.log('Price update:', price.assetId, price.price);
});
  1. Implement order placement
const order = await client.placeOrder({
type: 'limit',
side: 'buy',
assetId: 'asset_1234567890',
quantity: 100,
price: 10.5,
accountId: account.id,
});
  1. Monitor order status
const orderStatus = await client.getOrder(order.id);
if (orderStatus.status === 'filled') {
console.log('Order executed');
}
  1. Get portfolio performance
const performance = await client.getPerformance(account.id, {
period: '30d',
});

Complete Example

class TradingPlatform {
constructor(client) {
this.client = client;
}

async placeOrder(orderData) {
const order = await this.client.placeOrder({
type: orderData.type,
side: orderData.side,
assetId: orderData.assetId,
quantity: orderData.quantity,
price: orderData.price,
accountId: orderData.accountId,
});

return order;
}

async getMarketData(assetId) {
const marketData = await this.client.getMarketData(assetId);
return marketData;
}

async getPortfolio(accountId) {
const portfolio = await this.client.getPortfolio(accountId);
return portfolio;
}

async getOrderHistory(accountId) {
const orders = await this.client.getOrderHistory({
accountId,
limit: 100,
});

return orders;
}
}

Payment Systems

Implementing Payment Solutions

A payment system enables businesses to accept digital asset payments.

Key Features

  • Payment processing
  • Invoice generation
  • Payment tracking
  • Refund handling
  • Reporting and analytics

Implementation Steps

  1. Create payment request
const payment = await client.createPayment({
amount: 100,
assetId: 'asset_1234567890',
recipient: 'acc_0987654321',
memo: 'Payment for services',
});
  1. Track payment status
const status = await client.getPaymentStatus(payment.id);
if (status.status === 'completed') {
console.log('Payment received');
}
  1. Generate invoice
const invoice = await client.generateInvoice({
amount: 100,
assetId: 'asset_1234567890',
description: 'Service payment',
dueDate: '2024-02-15',
});
  1. Process refund
const refund = await client.processRefund({
paymentId: payment.id,
amount: 50,
reason: 'Partial refund',
});

Complete Example

class PaymentSystem {
constructor(client) {
this.client = client;
}

async processPayment(paymentData) {
const payment = await this.client.createPayment({
amount: paymentData.amount,
assetId: paymentData.assetId,
recipient: paymentData.recipient,
memo: paymentData.memo,
});

return payment;
}

async trackPayment(paymentId) {
const status = await this.client.getPaymentStatus(paymentId);
return status;
}

async generateInvoice(invoiceData) {
const invoice = await this.client.generateInvoice({
amount: invoiceData.amount,
assetId: invoiceData.assetId,
description: invoiceData.description,
dueDate: invoiceData.dueDate,
});

return invoice;
}

async processRefund(refundData) {
const refund = await this.client.processRefund({
paymentId: refundData.paymentId,
amount: refundData.amount,
reason: refundData.reason,
});

return refund;
}
}

Asset Management

Managing Digital Assets

An asset management system enables organizations to manage their digital asset portfolios.

Key Features

  • Asset creation and registration
  • Ownership tracking
  • Transfer management
  • Compliance reporting
  • Analytics and insights

Implementation Steps

  1. Create digital asset
const asset = await client.createAsset({
name: 'Company Token',
symbol: 'CT',
description: 'Company digital token',
totalSupply: 1000000,
decimals: 18,
});
  1. Track ownership
const ownership = await client.getAssetOwnership(asset.id);
console.log('Total owners:', ownership.totalOwners);
  1. Manage transfers
const transfer = await client.transferAsset({
assetId: asset.id,
from: 'acc_1234567890',
to: 'acc_0987654321',
amount: 1000,
});
  1. Generate compliance report
const report = await client.generateComplianceReport({
assetId: asset.id,
reportType: 'ownership',
format: 'pdf',
});

Complete Example

class AssetManagementSystem {
constructor(client) {
this.client = client;
}

async createAsset(assetData) {
const asset = await this.client.createAsset({
name: assetData.name,
symbol: assetData.symbol,
description: assetData.description,
totalSupply: assetData.totalSupply,
decimals: assetData.decimals,
});

return asset;
}

async trackOwnership(assetId) {
const ownership = await this.client.getAssetOwnership(assetId);
return ownership;
}

async manageTransfer(transferData) {
const transfer = await this.client.transferAsset({
assetId: transferData.assetId,
from: transferData.from,
to: transferData.to,
amount: transferData.amount,
});

return transfer;
}

async generateReport(assetId, reportType) {
const report = await this.client.generateComplianceReport({
assetId,
reportType,
format: 'pdf',
});

return report;
}
}

Data Analytics

Building Analytics Dashboards

An analytics dashboard provides insights into blockchain data and user behavior.

Key Features

  • Real-time data visualization
  • Historical analysis
  • Custom metrics and KPIs
  • Export capabilities
  • Interactive charts and graphs

Implementation Steps

  1. Get real-time data
const status = await client.getBlockchainStatus();
const marketData = await client.getMarketData('asset_1234567890');
  1. Query historical data
const historicalData = await client.getHistoricalData('asset_1234567890', {
startDate: '2024-01-01',
endDate: '2024-01-31',
interval: '1d',
});
  1. Generate analytics
const analytics = await client.getAnalytics('asset_1234567890', {
period: '30d',
metrics: ['price', 'volume', 'transactions'],
});
  1. Export data
const exportResult = await client.exportData({
query: {
table: 'transactions',
filters: {
timestamp: { $gte: '2024-01-01' },
},
},
format: 'csv',
});

Complete Example

class AnalyticsDashboard {
constructor(client) {
this.client = client;
}

async getDashboardData() {
const [status, marketData, analytics] = await Promise.all([
this.client.getBlockchainStatus(),
this.client.getMarketData('asset_1234567890'),
this.client.getAnalytics('asset_1234567890', { period: '7d' }),
]);

return {
blockchainStatus: status,
marketData,
analytics,
};
}

async getHistoricalData(assetId, period) {
const data = await this.client.getHistoricalData(assetId, {
startDate: period.startDate,
endDate: period.endDate,
interval: period.interval,
});

return data;
}

async exportData(query, format) {
const result = await this.client.exportData({
query,
format,
});

return result;
}
}

Compliance Tools

Implementing Regulatory Compliance

Compliance tools help organizations meet regulatory requirements and maintain audit trails.

Key Features

  • Transaction monitoring
  • Compliance reporting
  • Audit trail management
  • Risk assessment
  • Regulatory updates

Implementation Steps

  1. Monitor transactions
const transactions = await client.getTransactionHistory({
accountId: account.id,
startDate: '2024-01-01',
endDate: '2024-01-31',
});
  1. Generate compliance report
const report = await client.generateComplianceReport({
accountId: account.id,
reportType: 'transaction_summary',
period: '30d',
format: 'pdf',
});
  1. Track audit trail
const auditTrail = await client.getAuditTrail({
accountId: account.id,
startDate: '2024-01-01',
endDate: '2024-01-31',
});
  1. Assess risk
const riskAssessment = await client.assessRisk({
accountId: account.id,
criteria: ['transaction_volume', 'geographic_risk'],
});

Complete Example

class ComplianceTool {
constructor(client) {
this.client = client;
}

async monitorTransactions(accountId, period) {
const transactions = await this.client.getTransactionHistory({
accountId,
startDate: period.startDate,
endDate: period.endDate,
});

return transactions;
}

async generateReport(accountId, reportType, period) {
const report = await this.client.generateComplianceReport({
accountId,
reportType,
period,
format: 'pdf',
});

return report;
}

async getAuditTrail(accountId, period) {
const auditTrail = await this.client.getAuditTrail({
accountId,
startDate: period.startDate,
endDate: period.endDate,
});

return auditTrail;
}

async assessRisk(accountId, criteria) {
const riskAssessment = await this.client.assessRisk({
accountId,
criteria,
});

return riskAssessment;
}
}

Best Practices

1. Security

  • Implement proper authentication
  • Use HTTPS for all requests
  • Validate all inputs
  • Monitor for suspicious activity

2. Performance

  • Use pagination for large datasets
  • Implement proper caching
  • Monitor API usage
  • Handle rate limiting

3. Error Handling

  • Implement comprehensive error handling
  • Provide meaningful error messages
  • Log errors for debugging
  • Handle network issues gracefully

4. User Experience

  • Provide clear feedback
  • Implement loading states
  • Handle edge cases
  • Test thoroughly

Next Steps


Ready to start building? Let's explore Integration Patterns for advanced integration techniques!