Getting Started with the SDK
Install
npm install @7n7d/sdk
You need Node.js 18 or later. The SDK depends on ethers v6 and viem v2.
note
0.2.0 is the first version published to npm. If npm install returns a 404, it has not been published yet; build it from github.com/7n7dai/sdk instead.
Create a client
import { SevenNSevenD } from '@7n7d/sdk';
const client = new SevenNSevenD({
apiKey: process.env.SEVEN_N_SEVEN_D_API_KEY!, // required
network: 'testnet', // 'testnet' (default) | 'mainnet'
privateKey: process.env.PRIVATE_KEY, // optional: only for transactions
// apiUrl, rpcUrl, chain and contracts are optional overrides
});
| Option | Required | Default | Notes |
|---|---|---|---|
apiKey | Yes | Sent as the X-API-Key header. The client throws ConfigError without it | |
network | No | 'testnet' | testnet is Arbitrum Sepolia (421614), the app's network. mainnet (Arbitrum One, 42161) has no addresses yet |
apiUrl | No | testnet: https://api-testnet.7n7d.com | REST base URL |
rpcUrl | No | testnet: https://arbitrum-sepolia-rpc.publicnode.com | Must be an RPC for the client's chain. Wins over chain.rpcUrl |
chain | No | follows network | { id, name?, rpcUrl?, explorerUrl? }. Builds the provider for another chain ID, such as a local fork |
privateKey | No | Needed for every write: deposit, the withdrawal calls, stake, unstake, exit, claim, approve and the governance writes | |
contracts | No | the network's built-in addresses | Override tradingVault, usdc, token, profitDistributor or stakedGovernance |
client.chainId tells you which chain the provider was built for.
A contract with no address on the selected network (every mainnet contract today, and StakedGovernance on testnet until it is deployed) does not stop the client from being created. The first call that needs it throws a ConfigError that names it, for example stakedGovernance is not deployed on testnet yet.
Environment variables
SEVEN_N_SEVEN_D_API_KEY=your-api-key
PRIVATE_KEY=0x... # only if you send transactions
Check the connection
const health = await client.api.health(); // { ok, service, version, timestamp }
const status = await client.api.status(); // vault/agent status + trading network
const contracts = await client.api.contracts(); // addresses the API reports
Errors
Every SDK error extends SdkError, which has a code:
| Class | code | When |
|---|---|---|
ApiError | API_ERROR | Non-2xx REST response. Has status |
ContractError | CONTRACT_ERROR | A contract call or transaction failed |
ConfigError | CONFIG_ERROR | Missing apiKey, unknown network, a contract not deployed on the network, or a write without privateKey |
import { ApiError, ContractError } from '@7n7d/sdk';
try {
await client.vault.requestWithdrawal('100');
} catch (err) {
if (err instanceof ContractError) console.error(err.message, err.cause);
}
Next: Depositing USDC.