Skip to main content

Getting Started with the SDK

Install and configure the 7N7D SDK for your application.

Coming Soon

The SDK is currently in development. This documentation describes the planned API.

Installation​

npm​

npm install @7n7d/sdk

yarn​

yarn add @7n7d/sdk

pnpm​

pnpm add @7n7d/sdk

Dependencies​

The SDK requires:

  • Node.js 18+ (for server-side)
  • ethers.js v6 (included as peer dependency)

Basic Setup​

Initialize the Client​

import { SevenNSevenD } from '@7n7d/sdk';

const client = new SevenNSevenD({
// Required: Arbitrum RPC URL
rpcUrl: 'https://arb1.arbitrum.io/rpc',

// Required for transactions: Private key or signer
privateKey: process.env.PRIVATE_KEY,
});

Configuration Options​

interface SevenNSevenDConfig {
// Arbitrum RPC endpoint
rpcUrl: string;

// Authentication (choose one)
privateKey?: string; // Raw private key
signer?: ethers.Signer; // ethers.js signer

// Optional settings
network?: 'mainnet' | 'testnet'; // Default: 'mainnet'
timeout?: number; // Request timeout in ms
retries?: number; // Number of retry attempts
}

Authentication Methods​

Method 1: Private Key​

Simplest for backend services:

const client = new SevenNSevenD({
rpcUrl: process.env.RPC_URL,
privateKey: process.env.PRIVATE_KEY,
});
Security

Never hardcode private keys. Always use environment variables.

Method 2: External Signer​

For wallets and custom signers:

import { ethers } from 'ethers';

// From browser wallet
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();

const client = new SevenNSevenD({
rpcUrl: process.env.RPC_URL,
signer: signer,
});

Method 3: Hardware Wallet​

With Ledger or Trezor:

import { LedgerSigner } from '@ethersproject/hardware-wallets';

const signer = new LedgerSigner(provider, "hid", "m/44'/60'/0'/0/0");

const client = new SevenNSevenD({
rpcUrl: process.env.RPC_URL,
signer: signer,
});

Method 4: Read-Only​

For queries without transactions:

const client = new SevenNSevenD({
rpcUrl: process.env.RPC_URL,
// No privateKey or signer = read-only
});

// Can read data
const tvl = await client.vault.getTVL();

// Cannot send transactions
await client.vault.deposit('1000'); // Error: No signer configured

Environment Setup​

Create .env File​

# .env
RPC_URL=https://arb1.arbitrum.io/rpc
PRIVATE_KEY=your_private_key_here

Load Environment Variables​

import 'dotenv/config';
import { SevenNSevenD } from '@7n7d/sdk';

const client = new SevenNSevenD({
rpcUrl: process.env.RPC_URL!,
privateKey: process.env.PRIVATE_KEY!,
});

Network Configuration​

Mainnet (Production)​

const client = new SevenNSevenD({
rpcUrl: 'https://arb1.arbitrum.io/rpc',
privateKey: process.env.PRIVATE_KEY,
network: 'mainnet', // Default
});

Testnet (Development)​

const client = new SevenNSevenD({
rpcUrl: 'https://sepolia-rollup.arbitrum.io/rpc',
privateKey: process.env.TESTNET_PRIVATE_KEY,
network: 'testnet',
});

Verify Connection​

Check Connection​

async function verifySetup() {
const client = new SevenNSevenD({
rpcUrl: process.env.RPC_URL!,
privateKey: process.env.PRIVATE_KEY!,
});

// Check connected address
const address = await client.getAddress();
console.log(`Connected as: ${address}`);

// Check USDC balance
const usdcBalance = await client.getUSDCBalance();
console.log(`USDC Balance: ${usdcBalance}`);

// Check vault share balance
const vaultBalance = await client.vault.getBalance();
console.log(`Vault Shares: ${vaultBalance.shares}`);
console.log(`Vault Value: $${vaultBalance.usdcValue}`);

return true;
}

verifySetup().catch(console.error);

Expected Output​

Connected as: 0x1234...abcd
USDC Balance: 5000.00
Vault Shares: 4761.90
Vault Value: $5000.00

TypeScript Support​

The SDK is written in TypeScript with full type definitions:

import { 
SevenNSevenD,
VaultBalance,
DepositResult,
WithdrawResult
} from '@7n7d/sdk';

const client = new SevenNSevenD({ ... });

// Types are inferred
const balance: VaultBalance = await client.vault.getBalance();
const deposit: DepositResult = await client.vault.deposit('1000');

React Integration​

For React applications:

// providers/SevenNSevenDProvider.tsx
import { SevenNSevenDProvider } from '@7n7d/sdk/react';

export function Providers({ children }) {
return (
<SevenNSevenDProvider
config={{
rpcUrl: process.env.NEXT_PUBLIC_RPC_URL!,
}}
>
{children}
</SevenNSevenDProvider>
);
}
// components/VaultBalance.tsx
import { useVaultBalance } from '@7n7d/sdk/react';

export function VaultBalance() {
const { balance, isLoading, error } = useVaultBalance();

if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;

return (
<div>
<p>Shares: {balance.shares}</p>
<p>Value: ${balance.usdcValue}</p>
</div>
);
}

Error Handling​

import { SevenNSevenD, SDKError } from '@7n7d/sdk';

try {
const result = await client.vault.deposit('1000');
} catch (error) {
if (error instanceof SDKError) {
switch (error.code) {
case 'INSUFFICIENT_BALANCE':
console.log('Not enough USDC');
break;
case 'INSUFFICIENT_ALLOWANCE':
console.log('Need to approve USDC first');
break;
case 'TRANSACTION_FAILED':
console.log('Transaction reverted:', error.message);
break;
default:
console.log('Unknown error:', error);
}
}
}

Next Steps​

Now that you're set up:

  1. Deposit USDC - Add funds to the vault
  2. Withdraw - Remove funds
  3. Check Balances - Monitor your position
  4. API Reference - Full function documentation

Next: Learn how to Deposit USDC.