Introduction
The@gizatech/agent-sdk is a TypeScript SDK for managing Giza DeFi yield optimization agents. It provides a resource-oriented, type-safe interface and handles authentication, request retries, pagination, and error handling.
The SDK wraps the HTTP API in a convenient TypeScript interface with automatic authentication, type safety, and structured error handling.
Installation
Quick Start
SDK Architecture
The SDK follows a resource-oriented design with two primary classes:Giza— the top-level client. Handles configuration, authentication, and chain-level queries (protocols, tokens, stats, optimizer). It also acts as a factory forAgentinstances.Agent— a wallet-scoped handle bound to a single smart-account address. All agent lifecycle, monitoring, withdrawal, rewards, and protocol operations live here. You never pass a wallet address to individual methods because theAgentalready knows it.
- Create a
Gizaclient with your chain and credentials. - Obtain an
Agentviagiza.createAgent(eoa),giza.getAgent(eoa), orgiza.agent(wallet). - Call methods on the
Agentinstance for all wallet-scoped operations.
Configuration
All configuration is passed through theGizaConfig interface. Credentials fall back to environment variables when omitted.
| Parameter | Type | Required | Default | Env Fallback | Description |
|---|---|---|---|---|---|
chain | Chain | Yes | — | — | Target blockchain network |
apiKey | string | No | — | GIZA_API_KEY | Partner API key |
partner | string | No | — | GIZA_PARTNER_NAME | Partner identifier |
apiUrl | string | No | — | GIZA_API_URL | Giza backend URL |
timeout | number | No | 45000 | — | HTTP request timeout in ms |
enableRetry | boolean | No | false | — | Auto-retry on 5xx and network errors |
Supported Chains
Error Handling
The SDK provides a typed error hierarchy so you can handle failures precisely:| Error Class | When It Occurs |
|---|---|
ValidationError | Invalid input parameters (bad address format, missing fields) |
GizaAPIError | API returned an HTTP error (includes statusCode and message) |
TimeoutError | Request exceeded the configured timeout |
NetworkError | Network connectivity failure (DNS, connection refused) |
GizaError class.
SDK vs HTTP API
| Feature | SDK | HTTP API |
|---|---|---|
| Type Safety | Full TypeScript types | Manual typing |
| Authentication | Automatic via config/env | Manual headers |
| Error Handling | Typed error classes | Manual response parsing |
| Retries | Built-in (opt-in) | Manual implementation |
| Pagination | Async-iterable Paginator | Manual page tracking |
| Language | TypeScript / JavaScript | Any HTTP client |
HTTP API Reference
For direct HTTP access or non-JavaScript integrations, see the API Reference.