Practical code examples demonstrating how to interact with Yield.xyz APIs for DeFi operations.
Yield.xyz provides unified APIs for decentralized finance:
- Yields API - Engage with yield opportunities across multiple networks and protocols
- Perps API - Trade perpetual futures with leverage across multiple providers
These recipes demonstrate:
- Discovering and entering yield opportunities
- Trading perpetual futures with full position management
- Managing active positions and executing pending actions
- Signing and submitting transactions with ethers.js
- Building schema-driven interactive CLI applications
- Node.js (v16+) and pnpm installed
- Wallet mnemonic phrase
- Yield.xyz API key (obtain from Yield.xyz dashboard)
- Clone this repository
- Create a
.envfile by copying the example:
cp .env.example .env- Fill in your
.envfile with:MNEMONIC: Your wallet's seed phrase (12 or 24 words)YIELDS_API_KEY: Your Yield.xyz API key (for yields/staking)PERPS_API_KEY: Your Yield.xyz API key (for perpetuals trading)
- Install dependencies:
pnpm installEngage with yield opportunities across multiple networks and protocols:
pnpm yieldsFeatures:
- Browse 2000+ yield opportunities across all networks
- Search and filter by APY, network, token, and protocol
- Enter positions with dynamic argument collection (validators, LP ranges, etc.)
- View balances by type (active, claimable, withdrawable, etc.)
- Execute pending actions (claim rewards, unstake, withdraw, etc.)
- Fetch validator metadata for staking protocols (APY, status, voting power)
- Support for concentrated and classic liquidity pools
- Transaction status polling with explorer links
Supported:
- 80+ networks (Ethereum, Cosmos, Polkadot, Solana, Tron, and more)
- All yield types: staking, restaking, lending, vaults, liquidity pools
- Schema-driven UI that automatically adapts to each protocol
Trade perpetual futures with leverage:
pnpm perpsFeatures:
- View account balances and margin utilization
- Browse markets with real-time prices and funding rates
- Execute leveraged trades (long/short positions)
- Manage existing positions (close, adjust leverage, set TP/SL)
- View and cancel orders
- Deposit and withdraw collateral
- Schema-driven UI that adapts to each provider
Supported Providers:
- Hyperliquid
- More providers coming soon
All recipes follow an interactive, schema-driven approach:
- Connect - API key and wallet authentication
- Discover - Browse available markets, providers, or opportunities
- Execute - Perform actions with real-time argument collection
- Sign - Sign transactions locally with your wallet
- Submit - Submit to the blockchain or provider
The recipes automatically adapt to API changes using schema-driven UI generation.
For complete API documentation and integration guides:
- Perps API: docs.yield.xyz - Perpetual futures trading
- Yields API: docs.yield.xyz - Staking and yield opportunities
# Build TypeScript
pnpm build
# Format code
pnpm format
# Clean build artifacts
pnpm clean- Keep your
.envfile private - Never share your mnemonic phrase
- Protect your API keys
Use .env.example as a template only.