What This Does
When a user wants to earn yield on their crypto, their firstdepositFunds call associates their EOA with a pre-deployed Smart Account (Safe) that already has a signed session key. Funds deposited into this subaccount are automatically optimized across DeFi protocols. The user stays in full control and can withdraw anytime. Their EOA is unchanged.
- The subaccount is owned by the user’s EOA — only they can withdraw
- Session keys allow automated rebalancing but cannot withdraw to other addresses
- First deposit assigns the Safe live on Base, Arbitrum, and Mainnet at once
- No separate deploy or session-key step —
depositFundsis the onboarding call
The Flow
Prerequisites
- API Key — Get one programmatically (see below) or manually at sma.zyf.ai
- Wallet Connection — Either a wallet provider (browser) or secure key management (server)
- Node.js 18+
0.2.45
Programmatic API Key Creation (Agent-Native)
Agents can create their own API key without human intervention. You need the wallet address (public key) of the agent.
Important: Store the apiKey securely — it cannot be retrieved later. The key is linked to the provided wallet address.
Supported Chains
Important: Always Use EOA Address
When calling SDK methods, always pass the EOA address (the user’s wallet address) asuserAddress — never the subaccount/Safe address. The SDK resolves the assigned Safe address for that EOA.
Wallet Connection Options
The SDK supports multiple ways to connect a wallet. Choose based on your security requirements and deployment context.Option 1: Wallet Provider (Recommended for Browser/dApps)
Use an injected wallet provider like MetaMask. The private key never leaves the user’s wallet.Option 2: Viem WalletClient (Recommended for Server Agents)
Use a pre-configured viem WalletClient. This is the recommended approach for server-side agents as it allows integration with secure key management solutions.- AWS KMS / GCP Cloud KMS — Hardware-backed key storage
- Turnkey / Privy / Dynamic — Wallet-as-a-Service providers
- Hardware wallets — Via WalletConnect or similar
Option 3: Private Key String (Development Only)
Direct private key usage.Security Comparison
Step-by-Step
1. Connect to Zyfai
2. Deposit Funds
"conservative"— Stable yield, lower risk (default)"aggressive"— Higher yield, higher risk
3. Withdraw Funds
4. Disconnect
Complete Example
API Reference
Note: All methods that take
userAddress expect the EOA address, not the subaccount/Safe address.
Data Methods
getPositions
Get all active DeFi positions for a user across protocols. Optionally filter by chain. Parameters:
Example:
getAvailableProtocols
Get available DeFi protocols and pools for a specific chain with APY data.getUserDetails
Get current authenticated user details including smart wallet, chains, protocols, and settings. Requires SIWE authentication.UpdateUserProfileResponse (same as updateUserProfile).
updateUserProfile
Update the authenticated user’s profile settings including strategy, protocols, splitting, and cross-chain options. Requires SIWE authentication.asset: Each asset has its own configuration. Use asset: "WETH" or asset: "EURC" to update that asset separately from USDC.
Returns:
Cross-chain strategies: Only enable cross-chain when the user explicitly requests it. For cross-chain to work, bothcrosschainStrategyandomniAccountmust be set totrue. Never enable cross-chain settings by default.
- Strategy: Can be changed anytime. Subsequent rebalancing uses the new active strategy.
- Protocols: Use
getAvailableProtocols(chainId)to get valid protocol IDs before updating. - Smart Splitting (minSplits = 1): Default mode. To maximize returns, funds are automatically distributed across multiple DeFi pools — but only when beneficial. The system intelligently decides when splitting is advantageous based on current market conditions and opportunities. Funds may not split if no opportunity exists.
- Forced Splitting (minSplits > 1): When
minSplitsis set to 2, 3, or 4, funds are always distributed across at least that many pools for improved risk diversification (up to 4 DeFi pools). This guarantees your funds will be split regardless of market conditions. - Cross-chain: Requires both
crosschainStrategy: trueANDomniAccount: true. Only activate when the user explicitly asks for cross-chain yield optimization. Chains are configured during initial setup and cannot be changed via this method. - Auto-compounding: Enabled by default. When
true, yields are reinvested automatically. - Smart wallet address, chains, and
executorProxycannot be updated via this method.
getAPYPerStrategy
Get global APY by strategy type, time period, chain, and token. Use this to compare expected returns between strategies before deploying. Parameters:
Example:
getOnchainEarnings
Get onchain earnings for a wallet with total earnings by token.registerAgentOnIdentityRegistry (ERC-8004)
Register your Zyfai deployed agent on the Identity Registry following the ERC-8004 standard. This is used for OpenClaw agent registration. The method fetches a tokenUri containing the agent’s metadata stored on IPFS, then registers it on-chain. Supported Chains:
Parameters:
Example:
- Fetches a
tokenUrifrom the Zyfai API (agent metadata stored on IPFS) - Encodes the
register(tokenUri)call for the Identity Registry contract - Sends the transaction from the connected wallet
- Waits for on-chain confirmation
Security
- Non-custodial — User’s EOA owns the subaccount
- Session keys are limited — Can rebalance, cannot withdraw elsewhere
- Deterministic — Same EOA = same subaccount on every chain
- Flexible key management — Use wallet providers, WalletClients, or KMS integrations
Key Management Best Practices
For production autonomous agents, we recommend:- Use a WalletClient with a secure key source (not raw private keys)
- Integrate with KMS (AWS KMS, GCP Cloud KMS) for hardware-backed key storage
- Consider Wallet-as-a-Service providers like Turnkey, Privy, or Dynamic
- Never hardcode private keys in source code
- Rotate keys periodically and implement key revocation procedures
Troubleshooting
Subaccount address mismatch across chains
After first deposit, the assigned Safe address should be identical across Base, Arbitrum, and Mainnet for the same EOA. If you see different addresses:”Safe not available” / deposit failed on first use
The Safe is assigned on the first successfuldepositFunds call. If deposit fails:
- Confirm the EOA is connected via
connectAccount - Confirm the chain and asset are supported (EURC: Mainnet/Base only)
- Retry
depositFunds— do not call any separate deploy or session-key method
”Invalid signature” error
This typically means:- The wallet/signer doesn’t match the EOA you’re passing
- The Safe address on-chain doesn’t match what the SDK expects
Resources
- Get API Key: sma.zyf.ai or programmatically via
POST /api/sdk-api-keys/create - Docs: docs.zyf.ai
- Demo: github.com/ondefy/zyfai-sdk-demo
- MCP Server: mcp.zyf.ai — Use with Claude or other MCP-compatible agents
- Agent Registration: zyf.ai/.well-known/agent-registration.json