Skip to main content

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
});
OptionRequiredDefaultNotes
apiKeyYesSent as the X-API-Key header. The client throws ConfigError without it
networkNo'testnet'testnet is Arbitrum Sepolia (421614), the app's network. mainnet (Arbitrum One, 42161) has no addresses yet
apiUrlNotestnet: https://api-testnet.7n7d.comREST base URL
rpcUrlNotestnet: https://arbitrum-sepolia-rpc.publicnode.comMust be an RPC for the client's chain. Wins over chain.rpcUrl
chainNofollows network{ id, name?, rpcUrl?, explorerUrl? }. Builds the provider for another chain ID, such as a local fork
privateKeyNoNeeded for every write: deposit, the withdrawal calls, stake, unstake, exit, claim, approve and the governance writes
contractsNothe network's built-in addressesOverride 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:

ClasscodeWhen
ApiErrorAPI_ERRORNon-2xx REST response. Has status
ContractErrorCONTRACT_ERRORA contract call or transaction failed
ConfigErrorCONFIG_ERRORMissing 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.