Integration12 min read
TypeScript SDK
Complete guide to the NEXO TypeScript SDK
Installation
bash
npm install @nexo/sdk @solana/web3.jsInitialization
typescript
import { NexoClient } from '@nexo/sdk';
import { Connection, Keypair } from '@solana/web3.js';
const client = new NexoClient({
apiKey: process.env.NEXO_API_KEY,
network: 'mainnet-beta',
connection: new Connection('https://api.mainnet-beta.solana.com')
});Core Methods
swap()
typescript
const result = await client.swap({
inputMint: 'So11111111111111111111111111111111111111112', // SOL
outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
amount: 1_000_000_000, // 1 SOL in lamports
slippage: 0.5,
wallet: walletAdapter
});execute()
typescript
const result = await client.execute({
transaction: serializedTransaction,
protection: 'maximum',
simulate: true
});scan()
typescript
const report = await client.scan({
address: 'contract_address',
includeHistory: true
});Error Handling
typescript
try {
const result = await client.swap(params);
} catch (error) {
if (error instanceof NexoError) {
console.log('Code:', error.code);
console.log('Message:', error.message);
}
}