What is Zyfai SDK?
The Zyfai SDK is a powerful TypeScript library that simplifies interaction with Zyfai’s yield optimization infrastructure.Two Ways to Earn Yield
The SDK offers two distinct approaches for earning yield:- Smart Wallet: On first deposit, a personal pre-deployed Safe (with session key) is assigned for automated yield optimization across Base, Arbitrum, and Mainnet
- Vault: Deposit into a shared vault on Base and receive shares representing your stake
Features
The SDK provides:- Pre-deployed Smart Wallets: First
depositFundsassigns an ERC-4337 / ERC-7579 Safe with a signed session key - Flexible Authentication: Support for private keys and modern wallet providers with automatic SIWE authentication
- Multi-Chain Support: Base (8453), Arbitrum (42161), and Ethereum Mainnet (1)
- Multi-Asset Support: USDC, WETH, and EURC (EURC on Mainnet and Base)
- Yield Optimization: Access multiple DeFi protocols and strategies
- Position Tracking: Monitor and manage your DeFi positions across chains
- Analytics & Earnings: Track earnings, APY history, and portfolio performance
- SDK Key Analytics: Access wallet lists and TVL data without requiring wallet connection
Prerequisites
Before you begin, ensure your environment meets these requirements:- Node.js: Version 18.0.0 or higher
- API Key: Obtain your SDK API Key from the Zyfai Dashboard
- CORS Whitelist: Your application domain must be whitelisted on the Zyfai backend to allow API calls from the browser. Contact the Zyfai team with your domain (e.g.
https://app.yourproject.com) to get it added. Without this, browser-side SDK calls will be blocked by CORS policy.
Installation
Install the SDK along withviem as a peer dependency.
Latest version: 0.2.50
Architecture
The SDK bridges your application with two core backend systems:Quick Start
Follow these steps to integrate Zyfai into your application.1. Initialize the SDK
Create a new instance of the Zyfai SDK with your configuration:2. Connect an Account
The SDK handles SIWE (Sign-In with Ethereum) authentication automatically.Option A: Backend/Node.js (Private Key)
Option B: Browser/Frontend (Wallet Provider)
connectAccount() performs the full SIWE handshake. No additional authentication logic is required in your application.3. Fund Management (onboarding via deposit)
Zyfai uses Safe smart accounts to manage user funds. There is no separate deploy or session-key step.Deposit
Transfer tokens from the EOA to the Safe smart wallet:"conservative"(default): Optimized for low-risk, stable yield."aggressive": Optimized for higher yield with higher risk profile.
"USDC", "WETH", "EURC" (EURC on Mainnet and Base only).
Minimums apply to total Safe balance after deposit. Smaller top-ups are allowed if the Safe already meets the threshold.
Withdrawal
Initiate a withdrawal from the Safe back to an EOA:4. Monitor Performance
Full Workflow Example
Here is a complete integration script:Advanced Configuration
Environment Variables
Store sensitive credentials securely:Custom RPC Setup
Key Features Deep Dive
Pre-deployed Wallets
On first deposit, the backend assigns a pre-deployed Safe (with signed session key) to the EOA. The same Safe is available immediately on Base, Arbitrum, and Ethereum Mainnet.Session Key Security
Session keys ship with the pre-deployed Safe. They cannot withdraw funds to arbitrary addresses; they are strictly limited to rebalancing assets within the Zyfai ecosystem.Comprehensive Analytics
- Platform-wide: TVL, volume, and active user metrics.
- User-specific: Historical APY (7D/14D/30D), detailed earnings breakdown, and transaction logs.
Target Audience
- dApp Developers: Build DeFi apps with abstraction and yield optimization.
- DeFi Services: Manage Safe wallets and positions at scale.
- Wallet Providers: Embed yield optimization directly into your wallet UI.
Troubleshooting
- “No account connected”: Ensure
sdk.connectAccount()is called and resolved before executing transactions. - “Unsupported chain”: Verify the chain ID is supported (1, 8453, 42161).
- CORS Errors: In browsers, ensure your domain is whitelisted in the Zyfai Dashboard.
Next Steps
Check out the API Reference for a detailed list of all available methods.Support
- GitHub: ondefy/zyfai-sdk
- Community: Join our Telegram.
- Website: zyf.ai