Skip to main content
If you’re an agent, use this quickstart guide to get started with the Zyfai SDK.
This page is also available as a raw markdown file:docs.zyf.ai/Skill.md
Turn any Ethereum wallet into a yield-generating account.

What This Does

When a user wants to earn yield on their crypto, their first depositFunds 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.
Key points:
  • 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 — depositFunds is the onboarding call

The Flow

On the first deposit, Zyfai assigns a pre-deployed Safe with a signed session key to the EOA. The Safe is available immediately on Base, Arbitrum, and Ethereum Mainnet. This does not impact the EOA itself.

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+
Latest version: 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.
Response:
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) as userAddress — 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. Use an injected wallet provider like MetaMask. The private key never leaves the user’s wallet.
Security: The private key stays in the user’s wallet. The SDK only requests signatures when needed. Use a pre-configured viem WalletClient. This is the recommended approach for server-side agents as it allows integration with secure key management solutions.
Security: The WalletClient abstraction allows you to integrate with secure key management solutions like:
  • 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 Warning: Raw private keys in environment variables are a security risk. For production autonomous agents, use Option 2 with a proper key management solution.

Security Comparison

Step-by-Step

1. Connect to Zyfai

2. Deposit Funds

Funds move from EOA → Subaccount and start earning yield immediately. Strategies (first deposit only):
  • "conservative" — Stable yield, lower risk (default)
  • "aggressive" — Higher yield, higher risk
After deposit you can inspect the assigned Safe:

3. Withdraw Funds

Funds return to the user’s EOA. Withdrawals are processed asynchronously.

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:
Returns:

getAvailableProtocols

Get available DeFi protocols and pools for a specific chain with APY data.
Returns:

getUserDetails

Get current authenticated user details including smart wallet, chains, protocols, and settings. Requires SIWE authentication.
Returns UpdateUserProfileResponse (same as updateUserProfile).

updateUserProfile

Update the authenticated user’s profile settings including strategy, protocols, splitting, and cross-chain options. Requires SIWE authentication.
Parameters:
Note on asset: Each asset has its own configuration. Use asset: "WETH" or asset: "EURC" to update that asset separately from USDC. Returns:
Examples:
Cross-chain strategies: Only enable cross-chain when the user explicitly requests it. For cross-chain to work, both crosschainStrategy and omniAccount must be set to true. Never enable cross-chain settings by default.
Notes:
  • 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 minSplits is 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: true AND omniAccount: 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 executorProxy cannot 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:
Returns:

getOnchainEarnings

Get onchain earnings for a wallet with total earnings by token.
Returns:

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:
Returns:
How It Works:
  1. Fetches a tokenUri from the Zyfai API (agent metadata stored on IPFS)
  2. Encodes the register(tokenUri) call for the Identity Registry contract
  3. Sends the transaction from the connected wallet
  4. 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:
  1. Use a WalletClient with a secure key source (not raw private keys)
  2. Integrate with KMS (AWS KMS, GCP Cloud KMS) for hardware-backed key storage
  3. Consider Wallet-as-a-Service providers like Turnkey, Privy, or Dynamic
  4. Never hardcode private keys in source code
  5. 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:
If addresses don’t match: contact support on Telegram: @paul_zyfai

”Safe not available” / deposit failed on first use

The Safe is assigned on the first successful depositFunds call. If deposit fails:
  1. Confirm the EOA is connected via connectAccount
  2. Confirm the chain and asset are supported (EURC: Mainnet/Base only)
  3. 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
Verify you’re using the correct wallet for the EOA.

Resources