El SDK oficial de Pan para JavaScript/TypeScript simplifica la integracion con Pan API.
Instalacion
Configuracion Basica
import { Pan } from '@pan/sdk';
const pan = new Pan({
apiKey: process.env.PAN_API_KEY
});
Opciones de Configuracion
const pan = new Pan({
// Requerido
apiKey: 'pan_sk_...',
// Opcionales
baseURL: 'https://api.pan.dev/v1', // URL base de la API
timeout: 30000, // Timeout en ms (default: 30000)
debug: false, // Modo debug (default: false)
retries: 3, // Reintentos automaticos (default: 3)
});
| Opcion | Tipo | Default | Descripcion |
|---|
apiKey | string | - | Tu API key de Pan |
baseURL | string | https://api.pan.dev/v1 | URL base |
timeout | number | 30000 | Timeout en milisegundos |
debug | boolean | false | Activa logs de debug |
retries | number | 3 | Reintentos en errores |
Verificar Instalacion
import { Pan } from '@pan/sdk';
const pan = new Pan({ apiKey: process.env.PAN_API_KEY });
// Verificar conexion
try {
const yields = await pan.yields.getAll();
console.log('Conexion exitosa!');
console.log('Mejor APY:', yields.best.apy);
} catch (error) {
console.error('Error de conexion:', error.message);
}
Variables de Entorno
Recomendamos usar variables de entorno para la API key:
# .env
PAN_API_KEY=pan_sk_tu_api_key_aqui
// Cargar con dotenv o similar
import 'dotenv/config';
import { Pan } from '@pan/sdk';
const pan = new Pan({
apiKey: process.env.PAN_API_KEY
});
Nunca commitees tu API key. Agrega .env a tu .gitignore.
TypeScript
El SDK incluye tipos TypeScript completos:
import { Pan, Wallet, Intent, Balances, Yields } from '@pan/sdk';
const pan = new Pan({ apiKey: process.env.PAN_API_KEY! });
// Los tipos se infieren automaticamente
const wallet: Wallet = await pan.wallet.create({
userId: 'user_123'
});
const balances: Balances = await pan.wallet.getBalances(wallet.id);
const intent: Intent = await pan.lend({
walletId: wallet.id,
amount: 1000,
asset: 'USDC'
});
Proximos Pasos