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
sendDepositassigns 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, EURC, USDT, PYUSD, and NVDAc — chains, decimals, and minimums are on Supported Assets
- 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. How to hold it, and when an origin must be whitelisted, is below.
API key and CORS
The dashboard key is a partner credential (X-API-Key on every call). It is not a user session. Keep it on a server you control.
Demo snippets in these docs and in the SDK repo sometimes pass process.env.ZYFAI_API_KEY (or NEXT_PUBLIC_ZYFAI_API_KEY) straight into a React component. A bundler ships that value in the frontend, so the key is public. A native app binary can be unpacked the same way. Those snippets are for demos. For a production web app or a wallet, your backend holds the key and proxies calls to Zyfai. The user still signs SIWE on their device.
Someone who only has the key cannot move funds. Deposits, withdrawals, and deposit registration return 401 without that user’s SIWE session, and an on-chain transfer still needs their signature. What the key alone allows:
- Data API calls, counted against your quota
- Listing the smart wallets created under the key, and their TVL (
getSdkAllowedWallets,getSdkKeyTVL) - Registering extra wallets onto the key (
addWalletToSdk)
api.zyf.ai / defiapi.zyf.ai.
If a web app calls your proxy, and the proxy calls Zyfai from the server, whitelist nothing on our side. CORS is between the browser and your proxy.
Installation
Install the SDK along withviem as a peer dependency.
Latest version:
Architecture
The SDK bridges your application with two core backend systems. Full URLs, Swagger UIs, and which SDK methods hit which backend: API Reference Overview.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
sendDeposit transfers a collateral the wallet already holds. Pass spendToken when the wallet holds a different token: Relay delivers the collateral, then the same registration runs. Optional slippageBps on that swap defaults to 200 basis points (maximum 500) and is fixed when the funding order is created.
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."yieldmaxxing": Adds async vaults. Required for NVDAc.
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–180D), 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: Only a browser calling Zyfai directly needs its page origin whitelisted. Contact the Zyfai team with that origin. A native app or a server-side proxy does not. See API key and CORS.
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