Skip to content

Repository files navigation

Yield.xyz SDK

A TypeScript SDK for the most complete API for integrating non-custodial, on-chain yield — including staking, restaking, liquid staking, DeFi lending, RWA yields, vaults, and more across 70+ blockchain networks.

Originally developed as the backbone of Omni (one of the most advanced staking wallets in Web3), Yield.xyz now powers platforms like Ledger, Zerion, and Tangem, serving 4M+ users and supporting hundreds of millions in monthly volume.

Why Yield.xyz?

  • 🔗 Unified Interface — Every protocol and opportunity is abstracted into a consistent, schema-based format: one format for metadata, one for actions, one for balances
  • ⚡ Instant Integration — No need to write custom logic for Cosmos staking vs. Aave lending — integrate once, support everything
  • 🔐 Self-Custodial by Design — Transactions are returned fully constructed but never executed — you sign and broadcast using any infrastructure: wallets, smart contracts, or custody platforms
  • 🏗️ Battle-Tested Infrastructure — Built on the stack that powers millions of real-world transactions and billions in TVL
  • 🔄 Composable — Chain together multiple yields to build cross-chain workflows (e.g. bridge + stake + restake) in a single declarative call
  • 🌐 Chain-Agnostic — Works across EVM and non-EVM chains, including Ethereum, Cosmos, Tron, Solana, and more
  • 💰 Monetizable — Configure deposit, performance, and management fees or earn validator rebates directly in your integration
  • 🎯 TypeScript First — Full type safety with auto-generated types from OpenAPI spec
  • 🧪 Testing Support — Built-in MSW (Mock Service Worker) support for testing

What You Can Build

  • 💳 Wallets — Add staking, DeFi flows with full control over UX, signing, and monetization
  • 🏦 Custodians & Fintechs — Offer on-chain yield on crypto or stablecoin balances with full transparency and fee control
  • 🤖 AI Agents — Query all available yield actions and execute optimal strategies using standard schemas
  • 🔗 Aggregators & Infra — Compose multi-step flows using a unified transaction model — no chain-specific code required

Core Concepts

Yields

Each yield represents an opportunity: staking, restaking, lending, vaults, or RWA strategies — with standardized metadata, reward mechanics, and execution logic across 70+ networks.

Actions

Each yield supports consistent actions like enter, exit, and manage, using schema-based inputs. No matter if it's Ethereum staking or Cosmos delegation — the interface is the same.

Balances

Retrieve unified views of user positions across all lifecycle stages: active, pending, cooldown, claimable, and more — all in a consistent format regardless of the underlying protocol.

Protocols

Yields can be grouped under known brands or ecosystems (e.g. Aave, Cosmos, EigenLayer) for easy discovery and filtering.

Installation

npm install @yieldxyz/sdk
# or
yarn add @yieldxyz/sdk
# or
pnpm add @yieldxyz/sdk

Quick Start

Configuration

import{sdk}from'@yieldxyz/sdk';sdk.configure({apiKey: 'your-api-key',baseURL: 'https://api.yield.xyz/',// Optional, defaults to this URL});

Basic Usage

import{sdk}from'@yieldxyz/sdk';// Configure the SDK firstsdk.configure({apiKey: 'your-api-key',});// Discover yield opportunities across all networks and protocolsconstyields=awaitsdk.api.getYields({network: 'ethereum',limit: 10});// Get balances for a specific yield and addressconstbalances=awaitsdk.api.getYieldBalances('ethereum-lido-staking',{address: '0x1234567890123456789012345678901234567890',arguments: {}});// Enter a yield position (returns unsigned transactions)constaction=awaitsdk.api.enterYield({yieldId: 'ethereum-lido-staking',address: '0x1234567890123456789012345678901234567890',arguments: {amount: '1000000000000000000'// 1 ETH in wei}});// The transactions are ready to sign and broadcast with your preferred methodconsole.log(action.transactions);// Array of unsigned transactions

API Reference

Yield Discovery

Get All Yields

constyields=awaitsdk.api.getYields({network?: string;// Filter by network (ethereum, polygon, etc.)token?: string;// Filter by token symbol or addressinputToken?: string;// Filter by input tokenprovider?: string;// Filter by providerlimit?: number;// Page sizeoffset?: number;// Pagination offset});

Get Specific Yield

constyieldDetails=awaitsdk.api.getYield('ethereum-lido-staking');

Get Yield Validators (for staking)

constvalidators=awaitsdk.api.getYieldValidators('cosmos-staking',{limit?: 10,offset?: 0});

Balance Management

Get Yield Balances

constbalances=awaitsdk.api.getYieldBalances('ethereum-lido-staking',{address: '0x...',arguments?: object// Protocol-specific parameters});

Get Aggregate Balances (multiple yields)

constaggregateBalances=awaitsdk.api.getAggregateBalances({queries: [{yieldId: 'ethereum-lido-staking',address: '0x...',network: 'ethereum'},{yieldId: 'polygon-staking',address: '0x...',network: 'polygon'}]});

Action Execution

Enter Yield Position

constenterAction=awaitsdk.api.enterYield({yieldId: 'ethereum-lido-staking',address: '0x...',arguments: {amount: '1000000000000000000'}});

Exit Yield Position

constexitAction=awaitsdk.api.exitYield({yieldId: 'ethereum-lido-staking',address: '0x...',arguments: {amount: '1000000000000000000'}});

Manage Yield Position

constmanageAction=awaitsdk.api.manageYield({yieldId: 'ethereum-lido-staking',address: '0x...',action: 'CLAIM_REWARDS',// Available actions from balance.pendingActionspassthrough: 'server-generated-passthrough',// From balance queryarguments: {}});

Get User Actions

constactions=awaitsdk.api.getActions({address: '0x...',status?: 'CREATED'|'PROCESSING'|'SUCCESS'|'FAILED',intent?: 'enter'|'exit'|'manage',yieldId?: 'ethereum-lido-staking',limit?: 10,offset?: 0});

Get Action Details

constaction=awaitsdk.api.getAction('action-id');

Transaction Management

Submit Transaction Hash

consttransaction=awaitsdk.api.submitTransactionHash('transaction-id',{hash: '0x...'// After broadcasting the transaction});

Get Transaction Details

consttransaction=awaitsdk.api.getTransaction('transaction-id');

Network & Provider Discovery

Get Networks

constnetworks=awaitsdk.api.getNetworks();

Get Providers

constproviders=awaitsdk.api.getProviders({limit?: 10,offset?: 0});

Get Provider Details

constprovider=awaitsdk.api.getProvider('lido');

Health Check

Get API Health Status

consthealthStatus=awaitsdk.api.health();

Advanced Configuration

Custom Fetch Instance

You can provide your own fetch implementation for custom request handling:

import{sdk,typeFetchInstance}from'@yieldxyz/sdk';constcustomFetch: FetchInstance=async<T>(url: string,init: RequestInit): Promise<T>=>{// Custom fetch logic (e.g., retry, logging, etc.)constresponse=awaitfetch(url,init);if(!response.ok){thrownewError(`HTTP error! status: ${response.status}`);}returnresponse.json();};sdk.configure({apiKey: 'your-api-key',baseURL: 'https://api.yield.xyz/',fetchInstance: customFetch});

Testing

The SDK includes MSW (Mock Service Worker) support for testing:

import{setupServer}from'msw/node';import{getYieldXyzAPIMock}from'@yieldxyz/sdk/msw';constserver=setupServer(...getYieldXyzAPIMock());beforeAll(()=>server.listen());afterEach(()=>server.resetHandlers());afterAll(()=>server.close());

Type Safety

The SDK provides full TypeScript support with auto-generated types:

import{sdk}from'@yieldxyz/sdk';importtype{YieldDto,ActionDto,BalancesResponseDto,NetworkDto}from'@yieldxyz/sdk';// All API responses are fully typedconsthandleYieldData=(yield: YieldDto)=>{console.log(yield.id,yield.metadata.name);console.log(yield.rewardRate.total);// Fully typed reward informationconsole.log(yield.mechanics.type);// staking | restaking | lending | vault | etc.};

Error Handling

The SDK will throw an error if you try to use the API without configuring it first:

import{sdk}from'@yieldxyz/sdk';try{// This will throw an error if not configuredconstyields=awaitsdk.api.getYields();}catch(error){console.error('SDK not configured:',error.message);}// Configure firstsdk.configure({apiKey: 'your-api-key'});// Now API calls will workconstyields=awaitsdk.api.getYields();

Development

# Install dependencies
pnpm install
# Generate API client from OpenAPI spec
pnpm run generate-api
# Build the SDK
pnpm run build
# Run linting
pnpm run lint
# Format code
pnpm run format

Getting an API Key

To get started with Yield.xyz:

  1. Visit docs.yield.xyz to learn more about the platform
  2. Contact the Yield.xyz team to get your API key and discuss your use case
  3. Review the official documentation for comprehensive guides and examples

License

ISC

Documentation & Support

For comprehensive guides, API reference, and detailed examples, visit the official Yield.xyz documentation.

For support and partnerships:


Welcome to the yield layer of Web3 🌱

About

A TypeScript SDK for the most complete API for integrating non-custodial, on-chain yield — including staking, restaking, liquid staking, DeFi lending, RWA yields, vaults, and more across 70+ blockchain networks.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages