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.
0.2.0 is the first version published to npm. The public repository github.com/7n7dai/sdk matches the published release, not the source these pages describe, so building from it gives you 0.2.0's behaviour (see the caution below).
:::caution Published 0.2.0 still targets Arbitrum Sepolia
npm install @7n7d/sdk currently installs 0.2.0. Its testnet default is Arbitrum Sepolia, its staking and governance are the retired Arbitrum Sepolia contracts, and its vault calls target the retired V1 vault. Do not use 0.2.0's vault calls. The Ethereum Sepolia default, the v2 staking and governance contracts and the no-vault behaviour on these pages are in the repository source and ship in the next release (0.3.0).
:::
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 Ethereum Sepolia (11155111), the testnet hub for the token, staking and governance. mainnet (Arbitrum One, 42161) has no addresses yet |
apiUrl | No | testnet: https://api-testnet.7n7d.com | REST base URL |
rpcUrl | No | testnet: https://ethereum-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 the vault on testnet until Vault V2 is deployed) does not stop the client from being created. The first call that needs it throws a ConfigError that names it, for example tradingVault 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.staking.stake('100');
} catch (err) {
if (err instanceof ContractError) console.error(err.message, err.cause);
}
Next: Depositing USDC.